Add abstract base factory

master
sloria 10 years ago
parent 8412376285
commit e589ec1d92
  1. 10
      {{cookiecutter.app_name}}/tests/factories.py

@ -5,13 +5,19 @@ from factory.alchemy import SQLAlchemyModelFactory
from {{cookiecutter.app_name}}.user.models import User from {{cookiecutter.app_name}}.user.models import User
from {{cookiecutter.app_name}}.database import db from {{cookiecutter.app_name}}.database import db
class BaseFactory(SQLAlchemyModelFactory):
class UserFactory(SQLAlchemyModelFactory):
class Meta: class Meta:
model = User abstract = True
sqlalchemy_session = db.session sqlalchemy_session = db.session
class UserFactory(BaseFactory):
username = Sequence(lambda n: "user{0}".format(n)) username = Sequence(lambda n: "user{0}".format(n))
email = Sequence(lambda n: "user{0}@example.com".format(n)) email = Sequence(lambda n: "user{0}@example.com".format(n))
password = PostGenerationMethodCall('set_password', 'example') password = PostGenerationMethodCall('set_password', 'example')
active = True active = True
class Meta:
model = User

Loading…
Cancel
Save