<commit_before>import time
from apps.webdriver_testing.pages import Page


class UnisubsPage(Page):
    """
     Unisubs page contains common web elements found across
     all Universal Subtitles pages. Every new page class is derived from
     UnisubsPage so that every child class can have access to common web
     elements and methods that pertain to those elements.
    """

    _LOGIN = "a[href*='/auth/login']"
    _USER_MENU = "li#me_menu"
    _CREATE_NAV = "li#nav_submit a"
    _FEEDBACK_BUTTON = ".feedback_tab"

    _CURRENT_USER = "li#me_menu div#user_menu div#menu_name a"

    _USER_TEAMS = "li#me_menu  div#user_menu div#menu ul#dropdown li[id^=team] a"
    _SITE_LOGIN_USER_ID = "input#id_username"
    _SITE_LOGIN_USER_PW = "<PASSWORD>"
    _SITE_LOGIN_SUBMIT = "form button[value=login]"

    _ERROR_MESSAGE = "div#messages h2.error"
    _SUCCESS_MESSAGE = "div#messages h2.success"

    _MODAL_DIALOG = "div.modal"
    _MODAL_CLOSE = "div a.close"
    _SEARCHING_INDICATOR = "img.placeholder"

    def error_message_present(self, message):
        self.logger.info('Check if error message is present')
        if self.is_text_present(self._ERROR_MESSAGE, message):
            return True

    def success_message_present(self, message):
        self.logger.info('Check if success message present')
        if self.is_text_present(self._SUCCESS_MESSAGE, message):
            return True

    def open_amara(self):
        self.logger.info('Open amara home page')
        self.browser.get(self.base_url)

    def _current_user(self):
        self.logger.info('Get the username of currently logged in user')

        if self.is_element_present(self._CURRENT_USER):
            return self.get_text_by_css(self._CURRENT_USER)
    
    def logged_in(self):
        self.logger.info('Check if user logged in')

        if self.is_element_visible(self._CURRENT_USER):
            return True

    def log_out(self):
        self.logger.info('Log out of site')
        self.open_page('logout/?next=/videos/create')

    def log_in(self, username, passw):
        """Log in with the specified account type - default as a no-priv user.

        """
        self.open_page('auth/login/?next=/videos/create/')
        #self.click_by_css(self._LOGIN)
        #self.wait_for_element_present(self._SITE_LOGIN_USER_ID)
        self.type_by_css(self._SITE_LOGIN_USER_ID, username)
        self.type_by_css(self._SITE_LOGIN_USER_PW, passw)
        self.click_by_css(self._SITE_LOGIN_SUBMIT)
        self.wait_for_element_present(self._USER_MENU)

    def current_teams(self):
        """Returns the href value of any teams that use logged in user is 
           currently a memeber.

        """
        self.logger.info('Get a list of teams for the current user')<commit_msg>Faster login for selenium tests<commit_after>import time

from django.conf import settings
from django.utils.importlib import import_module
from django.contrib.auth import authenticate

from apps.webdriver_testing.pages import Page

class UnisubsPage(Page):
    """
     Unisubs page contains common web elements found across
     all Universal Subtitles pages. Every new page class is derived from
     UnisubsPage so that every child class can have access to common web
     elements and methods that pertain to those elements.
    """

    _LOGIN = "a[href*='/auth/login']"
    _USER_MENU = "li#me_menu"
    _CREATE_NAV = "li#nav_submit a"
    _FEEDBACK_BUTTON = ".feedback_tab"

    _CURRENT_USER = "li#me_menu div#user_menu div#menu_name a"

    _USER_TEAMS = "li#me_menu  div#user_menu div#menu ul#dropdown li[id^=team] a"
    _SITE_LOGIN_USER_ID = "input#id_username"
    _SITE_LOGIN_USER_PW = "<PASSWORD>"
    _SITE_LOGIN_SUBMIT = "form button[value=login]"

    _ERROR_MESSAGE = "div#messages h2.error"
    _SUCCESS_MESSAGE = "div#messages h2.success"

    _MODAL_DIALOG = "div.modal"
    _MODAL_CLOSE = "div a.close"
    _SEARCHING_INDICATOR = "img.placeholder"

    def error_message_present(self, message):
        self.logger.info('Check if error message is present')
        if self.is_text_present(self._ERROR_MESSAGE, message):
            return True

    def success_message_present(self, message):
        self.logger.info('Check if success message present')
        if self.is_text_present(self._SUCCESS_MESSAGE, message):
            return True

    def open_amara(self):
        self.logger.info('Open amara home page')
        self.browser.get(self.base_url)

    def _current_user(self):
        self.logger.info('Get the username of currently logged in user')

        if self.is_element_present(self._CURRENT_USER):
            return self.get_text_by_css(self._CURRENT_USER)
    
    def logged_in(self):
        self.logger.info('Check if user logged in')

        if self.is_element_visible(self._CURRENT_USER):
            return True

    def log_out(self):
        self.logger.info('Log out of site')
        self.open_page('logout/?next=/videos/create')

    def log_in(self, username, password):
        """Log in with the specified account type - default as a no-priv user.

        """
        self.logger.info("LOG IN")
        engine = import_module(settings.SESSION_ENGINE)
        session = engine.SessionStore(self._get_session_id())
        user = authenticate(username=username, password=password)
        if user is None:
            raise ValueError("Invalid auth credentials: %r/%r" %
                             (username, password))
        session['_auth_user_id'] = unicode(user.pk)
        session['_auth_user_backend'] = u'auth.backends.CustomUserBackend'
        session.save()
        self.logger.info("session saved: %s", session.session_key)
        self.browser.add_cookie({ u'domain': u'unisubs.example.com',
                                 u'name': u'sessionid',
                                  u'value': session.session_key,
                                  u'path': u'/',
                                 })
        self.logger.info("cookie saved")
        self.logger.info("cookies: %s", self.browser.get_cookies())

    def _get_session_id(self):
        for cookie in self.browser.get_cookies():
            if (cookie['domain'] == 'unisubs.example.com' and 
                cookie['name'] == 'sessionid'):
                return cookie['value']
        return None

    def current_teams(self):
        """Returns the href value of any teams that use logged in user is 
           currently a memeber.

        """
        self.logger.info('Get a list of teams for the current user')
{'fraction_non_alphanumeric': 0.0971690895179801, 'fraction_numerical': 0.000612088752869166, 'mean_word_length': 2.7649769585253456, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '249501', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1976, 'n_words': 477}