Update tests for factory-boy>=2.4.0

[fixes #23]
master
sloria 11 years ago
parent d9fdece9e6
commit 4179245939
  1. 4
      {{cookiecutter.app_name}}/tests/conftest.py
  2. 18
      {{cookiecutter.app_name}}/tests/factories.py
  3. 7
      {{cookiecutter.app_name}}/tests/test_functional.py
  4. 3
      {{cookiecutter.app_name}}/tests/test_models.py

@ -39,4 +39,6 @@ def db(app):
@pytest.fixture
def user(db):
return UserFactory()
user = UserFactory(password='myprecious')
db.session.commit()
return user

@ -7,20 +7,14 @@ from {{cookiecutter.app_name}}.database import db
class BaseFactory(SQLAlchemyModelFactory):
FACTORY_SESSION = db.session
class Meta:
sqlalchemy_session = db.session
@classmethod
def _create(cls, target_class, *args, **kwargs):
"""Create an instance of the model, and save it to the database."""
session = cls.FACTORY_SESSION
obj = target_class(*args, **kwargs)
session.add(obj)
session.commit()
return obj
class UserFactory(BaseFactory):
FACTORY_FOR = User
class UserFactory(SQLAlchemyModelFactory):
class Meta:
model = User
sqlalchemy_session = db.session
username = Sequence(lambda n: "user{0}".format(n))
email = Sequence(lambda n: "user{0}@example.com".format(n))

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
'''Functional tests using WebTest.
"""Functional tests using WebTest.
See: http://webtest.readthedocs.org/
'''
"""
import pytest
from flask import url_for
@ -10,9 +10,6 @@ from flask import url_for
from {{cookiecutter.app_name}}.user.models import User
from .factories import UserFactory
@pytest.fixture
def user(db):
return UserFactory(password='myprecious')
class TestLoggingIn:

@ -28,8 +28,9 @@ class TestUser:
user.save()
assert user.password is None
def test_factory(self):
def test_factory(self, db):
user = UserFactory(password="myprecious")
db.session.commit()
assert bool(user.username)
assert bool(user.email)
assert bool(user.created_at)

Loading…
Cancel
Save