<commit_before>"""User wants to register and login"""
from pytest import fixture

from adhocracy_core.testing import god_email
from adhocracy_core.testing import god_name
from adhocracy_core.testing import god_password

from .shared import fill_input
from .shared import click_button
from .shared import login
from .shared import logout
from .shared import is_logged_in


@fixture
def browser(browser):
    logout(browser)
    return browser


class TestUserLogin:

    def test_register(self, browser):
        register(browser, 'user2', '<EMAIL>', '<PASSWORD>')
        assert is_logged_in(browser)

    def test_login_email(self, browser):
        login(browser, god_email, god_password)
        assert is_logged_in(browser)

    def test_login_name(self, browser):
        logout(browser)
        login(browser, god_name, god_password)
        assert is_logged_in(browser)

    def test_login_error(self, browser):
        login(browser, 'wrong', 'wrong', expect_success=False, visit_root=False)
        assert browser.is_element_present_by_css(
            '.login .form-error:not(.ng-hide)', wait_time=2)
        assert not is_logged_in(browser)

    def test_register_error_wrong_password_repeat(self, browser):
        register(browser, 'user4', '<EMAIL>', '<PASSWORD>',
                 '<PASSWORD>', expect_success=False)
        assert browser.browser.is_element_present_by_css(
            '.register [type="submit"]:disabled', wait_time=1)

    def test_login_persistence(self, browser):
        register(browser, 'user5', '<EMAIL>', '<PASSWORD>')
        logout(browser)
        login(browser, 'user5', '<PASSWORD>')
        browser.reload()
        assert is_logged_in(browser)


def register(browser, name, email, password, repeated_password=None,
             expect_success=True):
    register_url = browser.app_url + 'register'
    browser.visit(register_url)
    fill_input(browser, '.register [name="username"]', name)
    fill_input(browser, '.register [name="email"]', email)
    fill_input(browser, '.register [name="password"]', password)
    fill_input(browser, '.register [name="password_repeat"]',
               repeated_password or password)
    click_button(browser, '.register [type="submit"]')
    if expect_success:
        browser.wait_for_condition(is_logged_in, 2)<commit_msg>Fix user_login tests to work with login email verification<commit_after>"""User wants to register and login"""
from pytest import fixture

from adhocracy_core.testing import god_email
from adhocracy_core.testing import god_name
from adhocracy_core.testing import god_password

from .shared import fill_input
from .shared import click_button
from .shared import login
from .shared import logout
from .shared import login_god
from .shared import is_logged_in


@fixture
def browser(browser):
    logout(browser)
    return browser


class TestUserLogin:

    def test_register(self, browser):
        register(browser, 'user2', '<EMAIL>', '<PASSWORD>',
                 expect_success=False)
        assert is_not_yet_activated(browser)

    def test_login_email(self, browser):
        login(browser, god_email, god_password)
        assert is_logged_in(browser)

    def test_login_name(self, browser):
        logout(browser)
        login(browser, god_name, god_password)
        assert is_logged_in(browser)

    def test_login_error(self, browser):
        login(browser, 'wrong', 'wrong', expect_success=False, visit_root=False)
        assert browser.is_element_present_by_css(
            '.login .form-error:not(.ng-hide)', wait_time=2)
        assert not is_logged_in(browser)

    def test_register_error_wrong_password_repeat(self, browser):
        register(browser, 'user4', '<EMAIL>', '<PASSWORD>',
                 '<PASSWORD>', expect_success=False)
        assert browser.browser.is_element_present_by_css(
            '.register [type="submit"]:disabled', wait_time=1)

    def test_login_persistence(self, browser):
        login_god(browser)
        browser.reload()
        assert is_logged_in(browser)


def register(browser, name, email, password, repeated_password=None,
             expect_success=True):
    register_url = browser.app_url + 'register'
    browser.visit(register_url)
    fill_input(browser, '.register [name="username"]', name)
    fill_input(browser, '.register [name="email"]', email)
    fill_input(browser, '.register [name="password"]', password)
    fill_input(browser, '.register [name="password_repeat"]',
               repeated_password or password)
    click_button(browser, '.register [type="submit"]')
    if expect_success:
        browser.wait_for_condition(is_logged_in, 2)


def is_not_yet_activated(browser):
    return browser.browser.is_text_present("User account not yet activated")
{'fraction_non_alphanumeric': 0.10611472998529103, 'fraction_numerical': 0.002521538138264341, 'mean_word_length': 3.8920863309352516, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348438', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1392, 'n_words': 325}