"""User wants to register and login"""
from pytest import fixture

from adhocracy_core.testing import god_email
from adhocracy_core.testing import god_login
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


class TestUserLogin:

    def test_register(self, browser):
        register(browser, 'user2', 'email2@example.com', 'password2',
                 expect_success=False)
        assert is_not_yet_activated(browser)

    def test_register_error_wrong_password_repeat(self, browser):

        register(browser, 'user4', 'email4@example.com', 'password4',
                 'wrong_repeated_password', expect_success=False)
        assert browser.browser.is_element_present_by_css(
            '.register [type="submit"]:disabled')

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

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

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

    def test_login_persistence(self, 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.is_element_present_by_css('.register-success')

@@ -1152,32 +1152,565 @@
 ed_in(browser)%0A%0A
+    def login_name_with_wrong_password(self, browser):%0A        login(browser, god_login, 'wrong', expect_success=False, visit_root=False)%0A        assert browser.is_element_present_by_css(%0A            '.login .form-error:not(.ng-hide)', wait_time=2)%0A        assert not is_logged_in(browser)%0A%0A    def login_name_with_password_length_lower_6(self, browser):%0A        login(browser, god_login, 'short', expect_success=False, visit_root=False)%0A        browser.is_text_present('password to short')%0A        assert not is_logged_in(browser)%0A%0A
     def test_log

add more user login tests