# Path: recruit_app/public/forms.py
# class LoginForm(Form):
#     email = TextField('Email', validators=[DataRequired()])
#     password = PasswordField('Password', validators=[DataRequired()])
#     submit = SubmitField(label='Log In')
# 
#     def __init__(self, *args, **kwargs):
#         super(LoginForm, self).__init__(*args, **kwargs)
#         self.user = None
# 
#     def validate(self):
#         initial_validation = super(LoginForm, self).validate()
#         if not initial_validation:
#             return False
# 
#         self.user = user_datastore.get_user(self.email.data)
#         if not self.user:
#             self.email.errors.append('Unknown email address')
#             return False
# 
#         if not self.user.check_password(self.password.data):
#             self.password.errors.append('Invalid password')
#             return False
# 
#         if not self.user.active:
#             self.email.errors.append('User not activated')
#             return False
#         return True


from recruit_app.public.forms import LoginForm
from flask_security.forms import ConfirmRegisterForm
        """Enter email that is already registered."""
        form = ConfirmRegisterForm(email=user.email,
                                   password='example',
                                   password_confirm='example')

        assert form.validate() is False
        assert '{0} is already associated with an account.'\
            .format(user.email) in form.email.errors

    def test_validate_success(self, db):
        """Register with success."""
        form = ConfirmRegisterForm(email='new@test.test',
                                   password='example',
                                   password_confirm='example')
        assert form.validate() is True


class TestLoginForm:
    """Login form."""

    def test_validate_success(self, user):
        """Login successful."""
        user.set_password('example')
        user.save()
        form = LoginForm(email=user.email, password='example')
        assert form.validate() is True
        assert form.user == user

    def test_validate_unknown_email(self, db):
        """Unknown email."""

# Path: recruit_app/public/forms.py
# class LoginForm(Form):
#     email = TextField('Email', validators=[DataRequired()])
#     password = PasswordField('Password', validators=[DataRequired()])
#     submit = SubmitField(label='Log In')
# 
#     def __init__(self, *args, **kwargs):
#         super(LoginForm, self).__init__(*args, **kwargs)
#         self.user = None
# 
#     def validate(self):
#         initial_validation = super(LoginForm, self).validate()
#         if not initial_validation:
#             return False
# 
#         self.user = user_datastore.get_user(self.email.data)
#         if not self.user:
#             self.email.errors.append('Unknown email address')
#             return False
# 
#         if not self.user.check_password(self.password.data):
#             self.password.errors.append('Invalid password')
#             return False
# 
#         if not self.user.active:
#             self.email.errors.append('User not activated')
#             return False
#         return True


# Path: tests/test_forms.py
from recruit_app.public.forms import LoginForm
from flask_security.forms import ConfirmRegisterForm

        """Enter email that is already registered."""
        form = ConfirmRegisterForm(email=user.email,
                                   password='example',
                                   password_confirm='example')

        assert form.validate() is False
        assert '{0} is already associated with an account.'\
            .format(user.email) in form.email.errors

    def test_validate_success(self, db):
        """Register with success."""
        form = ConfirmRegisterForm(email='new@test.test',
                                   password='example',
                                   password_confirm='example')
        assert form.validate() is True


class TestLoginForm:
    """Login form."""

    def test_validate_success(self, user):
        """Login successful."""
        user.set_password('example')
        user.save()
        form = LoginForm(email=user.email, password='example')
        assert form.validate() is True
        assert form.user == user

    def test_validate_unknown_email(self, db):
        """Unknown email."""

        form = LoginForm(email='unknown@unknown.com', password='example')