# Path: flask_editablesite/user/models.py
# class User(UserMixin, SurrogatePK, TimeStamped, Confirmable, Model):
#     __tablename__ = 'users'
# 
#     email = Column(db.String(255), unique=True, nullable=False)
#     password = Column(db.String(255), nullable=True)
#     first_name = Column(db.String(255), nullable=True)
#     last_name = Column(db.String(255), nullable=True)
# 
#     def __init__(self, email, password=None, **kwargs):
#         db.Model.__init__(self, email=email, **kwargs)
#         if password:
#             self.set_password(password)
#         else:
#             self.password = None
# 
#     def set_password(self, password):
#         self.password = bcrypt.generate_password_hash(password)
# 
#     def check_password(self, value):
#         return bcrypt.check_password_hash(self.password, value)
# 
#     @property
#     def full_name(self):
#         if self.first_name and self.last_name:
#             return "{0} {1}".format(self.first_name, self.last_name)
# 
#         return ""
# 
#     @property
#     def full_name_or_email(self):
#         return self.full_name or self.email
# 
#     def __repr__(self):
#         return '{0} <{1}>'.format(self.full_name, self.email)
# 
#     @classmethod
#     def sessionstore_user(cls):
#         """
#         A dummy user object to represent the logged-in user when
#         we're set to 'sessionstore' instead of 'db'.
#         """
# 
#         return cls(
#             email=app.config['SESSIONSTORE_USER_EMAIL'],
#             first_name=app.config['SESSIONSTORE_USER_FIRST_NAME'],
#             last_name=app.config['SESSIONSTORE_USER_LAST_NAME'],
#             active=True)
# 
# Path: tests/factories.py
# class UserFactory(BaseFactory):
#     email = Sequence(lambda n: "user{0}@example.com".format(n))
#     password = PostGenerationMethodCall('set_password', 'example')
#     active = True
# 
#     class Meta:
#         model = User


import datetime as dt
from flask_editablesite.user.models import User
from .factories import UserFactory
    user.delete()


def test_user_password_is_nullable():
    user = User(email='foo@bar.com')
    user.save()
    assert user.password is None

    user.delete()


def test_user_factory(db):
    user = UserFactory(password="myprecious")
    db.session.commit()
    assert bool(user.email)
    assert bool(user.created_at)
    assert user.active is True
    assert user.check_password('myprecious')


def test_user_check_password():
    user = User.create(email="foo@bar.com",
                       password="foobarbaz123")
    assert user.check_password('foobarbaz123') is True
    assert user.check_password("barfoobaz") is False

    user.delete()


def test_user_full_name():

# Path: flask_editablesite/user/models.py
# class User(UserMixin, SurrogatePK, TimeStamped, Confirmable, Model):
#     __tablename__ = 'users'
# 
#     email = Column(db.String(255), unique=True, nullable=False)
#     password = Column(db.String(255), nullable=True)
#     first_name = Column(db.String(255), nullable=True)
#     last_name = Column(db.String(255), nullable=True)
# 
#     def __init__(self, email, password=None, **kwargs):
#         db.Model.__init__(self, email=email, **kwargs)
#         if password:
#             self.set_password(password)
#         else:
#             self.password = None
# 
#     def set_password(self, password):
#         self.password = bcrypt.generate_password_hash(password)
# 
#     def check_password(self, value):
#         return bcrypt.check_password_hash(self.password, value)
# 
#     @property
#     def full_name(self):
#         if self.first_name and self.last_name:
#             return "{0} {1}".format(self.first_name, self.last_name)
# 
#         return ""
# 
#     @property
#     def full_name_or_email(self):
#         return self.full_name or self.email
# 
#     def __repr__(self):
#         return '{0} <{1}>'.format(self.full_name, self.email)
# 
#     @classmethod
#     def sessionstore_user(cls):
#         """
#         A dummy user object to represent the logged-in user when
#         we're set to 'sessionstore' instead of 'db'.
#         """
# 
#         return cls(
#             email=app.config['SESSIONSTORE_USER_EMAIL'],
#             first_name=app.config['SESSIONSTORE_USER_FIRST_NAME'],
#             last_name=app.config['SESSIONSTORE_USER_LAST_NAME'],
#             active=True)
# 
# Path: tests/factories.py
# class UserFactory(BaseFactory):
#     email = Sequence(lambda n: "user{0}@example.com".format(n))
#     password = PostGenerationMethodCall('set_password', 'example')
#     active = True
# 
#     class Meta:
#         model = User


# Path: tests/test_user_models.py
import datetime as dt
from flask_editablesite.user.models import User
from .factories import UserFactory

    user.delete()


def test_user_password_is_nullable():
    user = User(email='foo@bar.com')
    user.save()
    assert user.password is None

    user.delete()


def test_user_factory(db):
    user = UserFactory(password="myprecious")
    db.session.commit()
    assert bool(user.email)
    assert bool(user.created_at)
    assert user.active is True
    assert user.check_password('myprecious')


def test_user_check_password():
    user = User.create(email="foo@bar.com",
                       password="foobarbaz123")
    assert user.check_password('foobarbaz123') is True
    assert user.check_password("barfoobaz") is False

    user.delete()


def test_user_full_name():

    user = UserFactory(first_name="Foo", last_name="Bar")