Follow one test class per model convention

master
Steven Loria 11 years ago
parent ce85de1b20
commit 9851fa2974
  1. 2
      {{cookiecutter.app_name}}/manage.py
  2. 18
      {{cookiecutter.app_name}}/tests/test_models.py

@ -17,7 +17,7 @@ else:
app = create_app(DevConfig) app = create_app(DevConfig)
manager = Manager(app) manager = Manager(app)
TEST_CMD = "py.test" TEST_CMD = "py.test tests"
def _make_context(): def _make_context():
'''Return context dict for a shell session so you can access '''Return context dict for a shell session so you can access

@ -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,19 +9,20 @@ 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): def test_created_at_defaults_to_datetime(self, session):
user = User(username='foo', email='foo@bar.com') user = User(username='foo', email='foo@bar.com')
user.save() user.save()
assert bool(user.created_at) assert bool(user.created_at)
assert isinstance(user.created_at, dt.datetime) is True assert isinstance(user.created_at, dt.datetime) is True
def test_password_is_nullable(session): def test_password_is_nullable(self, session):
user = User(username='foo', email='foo@bar.com') user = User(username='foo', email='foo@bar.com')
user.save() user.save()
assert user.password is None assert user.password is None
def test_factory(session): def test_factory(self, session):
user = UserFactory(password="myprecious") user = UserFactory(password="myprecious")
assert bool(user.username) assert bool(user.username)
assert bool(user.email) assert bool(user.email)
@ -30,23 +31,20 @@ def test_factory(session):
assert user.active is True assert user.active is True
assert user.password == "myprecious" assert user.password == "myprecious"
def test_check_password_with_equality_operators(session): def test_check_password_with_equality_operators(self, session):
user = User.create(username="foo", email="foo@bar.com", user = User.create(username="foo", email="foo@bar.com",
password="foobarbaz123") password="foobarbaz123")
assert user.password == 'foobarbaz123' assert user.password == 'foobarbaz123'
assert user.password != "barfoobaz" assert user.password != "barfoobaz"
def test_full_name(session): def test_full_name(self, session):
user = UserFactory(first_name="Foo", last_name="Bar") user = UserFactory(first_name="Foo", last_name="Bar")
assert user.full_name == "Foo Bar" assert user.full_name == "Foo Bar"
def test_roles(session): def test_roles(self, session):
role = Role(name='admin') role = Role(name='admin')
role.save() role.save()
u = UserFactory() u = UserFactory()
u.roles.append(role) u.roles.append(role)
u.save() u.save()
assert role in u.roles assert role in u.roles
if __name__ == '__main__':
unittest.main()

Loading…
Cancel
Save