|
|
@ -1,5 +1,5 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
import unittest |
|
|
|
"""Model unit tests.""" |
|
|
|
import datetime as dt |
|
|
|
import datetime as dt |
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
import pytest |
|
|
@ -9,44 +9,42 @@ from {{ cookiecutter.app_name }}.user.models import User, Role |
|
|
|
from .base import DbTestCase |
|
|
|
from .base import DbTestCase |
|
|
|
from .factories import UserFactory |
|
|
|
from .factories import UserFactory |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestUser: |
|
|
|
def test_created_at_defaults_to_datetime(session): |
|
|
|
|
|
|
|
user = User(username='foo', email='foo@bar.com') |
|
|
|
def test_created_at_defaults_to_datetime(self, session): |
|
|
|
user.save() |
|
|
|
user = User(username='foo', email='foo@bar.com') |
|
|
|
assert bool(user.created_at) |
|
|
|
user.save() |
|
|
|
assert isinstance(user.created_at, dt.datetime) is True |
|
|
|
assert bool(user.created_at) |
|
|
|
|
|
|
|
assert isinstance(user.created_at, dt.datetime) is True |
|
|
|
def test_password_is_nullable(session): |
|
|
|
|
|
|
|
user = User(username='foo', email='foo@bar.com') |
|
|
|
def test_password_is_nullable(self, session): |
|
|
|
user.save() |
|
|
|
user = User(username='foo', email='foo@bar.com') |
|
|
|
assert user.password is None |
|
|
|
user.save() |
|
|
|
|
|
|
|
assert user.password is None |
|
|
|
def test_factory(session): |
|
|
|
|
|
|
|
user = UserFactory(password="myprecious") |
|
|
|
def test_factory(self, session): |
|
|
|
assert bool(user.username) |
|
|
|
user = UserFactory(password="myprecious") |
|
|
|
assert bool(user.email) |
|
|
|
assert bool(user.username) |
|
|
|
assert bool(user.created_at) |
|
|
|
assert bool(user.email) |
|
|
|
assert user.is_admin is False |
|
|
|
assert bool(user.created_at) |
|
|
|
assert user.active is True |
|
|
|
assert user.is_admin is False |
|
|
|
assert user.password == "myprecious" |
|
|
|
assert user.active is True |
|
|
|
|
|
|
|
assert user.password == "myprecious" |
|
|
|
def test_check_password_with_equality_operators(session): |
|
|
|
|
|
|
|
user = User.create(username="foo", email="foo@bar.com", |
|
|
|
def test_check_password_with_equality_operators(self, session): |
|
|
|
password="foobarbaz123") |
|
|
|
user = User.create(username="foo", email="foo@bar.com", |
|
|
|
assert user.password == 'foobarbaz123' |
|
|
|
password="foobarbaz123") |
|
|
|
assert user.password != "barfoobaz" |
|
|
|
assert user.password == 'foobarbaz123' |
|
|
|
|
|
|
|
assert user.password != "barfoobaz" |
|
|
|
def test_full_name(session): |
|
|
|
|
|
|
|
user = UserFactory(first_name="Foo", last_name="Bar") |
|
|
|
def test_full_name(self, session): |
|
|
|
assert user.full_name == "Foo Bar" |
|
|
|
user = UserFactory(first_name="Foo", last_name="Bar") |
|
|
|
|
|
|
|
assert user.full_name == "Foo Bar" |
|
|
|
def test_roles(session): |
|
|
|
|
|
|
|
role = Role(name='admin') |
|
|
|
def test_roles(self, session): |
|
|
|
role.save() |
|
|
|
role = Role(name='admin') |
|
|
|
u = UserFactory() |
|
|
|
role.save() |
|
|
|
u.roles.append(role) |
|
|
|
u = UserFactory() |
|
|
|
u.save() |
|
|
|
u.roles.append(role) |
|
|
|
assert role in u.roles |
|
|
|
u.save() |
|
|
|
|
|
|
|
assert role in u.roles |
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
|
|
unittest.main() |
|
|
|
|
|
|
|