# Path: farmsList/public/forms.py
# class LoginForm(Form):
#     username = TextField('Username', validators=[DataRequired()])
#     password = PasswordField('Password', validators=[DataRequired()])
# 
#     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.query.filter_by(username=self.username.data).first()
#         if not self.user:
#             self.username.errors.append('Unknown username')
#             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.username.errors.append('User not activated')
#             return False
#         return True
# 
# Path: tests/factories.py
# class UserFactory(BaseFactory):
#     username = Sequence(lambda n: "user{0}".format(n))
#     email = Sequence(lambda n: "user{0}@example.com".format(n))
#     password = PostGenerationMethodCall('set_password', 'example')
#     active = True
# 
#     class Meta:
#         model = User


import pytest
from farmsList.public.forms import LoginForm
from farmsList.user.forms import RegisterForm
from .factories import UserFactory
# -*- coding: utf-8 -*-


class TestRegisterForm:

    def test_validate_user_already_registered(self, user):
        # Enters username that is already registered
        form = RegisterForm(username=user.username, email='foo@bar.com',

# Path: farmsList/public/forms.py
# class LoginForm(Form):
#     username = TextField('Username', validators=[DataRequired()])
#     password = PasswordField('Password', validators=[DataRequired()])
# 
#     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.query.filter_by(username=self.username.data).first()
#         if not self.user:
#             self.username.errors.append('Unknown username')
#             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.username.errors.append('User not activated')
#             return False
#         return True
# 
# Path: tests/factories.py
# class UserFactory(BaseFactory):
#     username = Sequence(lambda n: "user{0}".format(n))
#     email = Sequence(lambda n: "user{0}@example.com".format(n))
#     password = PostGenerationMethodCall('set_password', 'example')
#     active = True
# 
#     class Meta:
#         model = User


# Path: tests/test_forms.py
import pytest
from farmsList.public.forms import LoginForm
from farmsList.user.forms import RegisterForm
from .factories import UserFactory

# -*- coding: utf-8 -*-


class TestRegisterForm:

    def test_validate_user_already_registered(self, user):
        # Enters username that is already registered
        form = RegisterForm(username=user.username, email='foo@bar.com',

            password='example', confirm='example')