|
|
|
@ -5,42 +5,42 @@ import datetime as dt |
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
from {{ cookiecutter.app_name }}.user.models import User, Role |
|
|
|
|
from .base import DbTestCase |
|
|
|
|
from .factories import UserFactory |
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('db') |
|
|
|
|
class TestUser: |
|
|
|
|
|
|
|
|
|
def test_created_at_defaults_to_datetime(self, db): |
|
|
|
|
def test_created_at_defaults_to_datetime(self): |
|
|
|
|
user = User(username='foo', email='foo@bar.com') |
|
|
|
|
user.save() |
|
|
|
|
assert bool(user.created_at) |
|
|
|
|
assert isinstance(user.created_at, dt.datetime) is True |
|
|
|
|
assert isinstance(user.created_at, dt.datetime) |
|
|
|
|
|
|
|
|
|
def test_password_is_nullable(self, db): |
|
|
|
|
def test_password_is_nullable(self): |
|
|
|
|
user = User(username='foo', email='foo@bar.com') |
|
|
|
|
user.save() |
|
|
|
|
assert user.password is None |
|
|
|
|
|
|
|
|
|
def test_factory(self, db): |
|
|
|
|
def test_factory(self): |
|
|
|
|
user = UserFactory(password="myprecious") |
|
|
|
|
assert bool(user.username) |
|
|
|
|
assert bool(user.email) |
|
|
|
|
assert bool(user.created_at) |
|
|
|
|
assert user.is_admin is False |
|
|
|
|
assert user.active is True |
|
|
|
|
assert user.password == "myprecious" |
|
|
|
|
assert user.check_password('myprecious') |
|
|
|
|
|
|
|
|
|
def test_check_password_with_equality_operators(self, db): |
|
|
|
|
def test_check_password(self): |
|
|
|
|
user = User.create(username="foo", email="foo@bar.com", |
|
|
|
|
password="foobarbaz123") |
|
|
|
|
assert user.password == 'foobarbaz123' |
|
|
|
|
assert user.password != "barfoobaz" |
|
|
|
|
assert user.check_password('foobarbaz123') is True |
|
|
|
|
assert user.check_password("barfoobaz") is False |
|
|
|
|
|
|
|
|
|
def test_full_name(self, db): |
|
|
|
|
def test_full_name(self): |
|
|
|
|
user = UserFactory(first_name="Foo", last_name="Bar") |
|
|
|
|
assert user.full_name == "Foo Bar" |
|
|
|
|
|
|
|
|
|
def test_roles(self, db): |
|
|
|
|
def test_roles(self): |
|
|
|
|
role = Role(name='admin') |
|
|
|
|
role.save() |
|
|
|
|
u = UserFactory() |
|
|
|
|