mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-03 13:19:16 -05:00
refactor Food tests to use factory_boy fixture factories
This commit is contained in:
28
cookbook/tests/factories/__init__.py
Normal file
28
cookbook/tests/factories/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import factory
|
||||
from django_scopes import scopes_disabled
|
||||
from faker import Factory as FakerFactory
|
||||
|
||||
faker = FakerFactory.create()
|
||||
|
||||
|
||||
class SpaceFactory(factory.django.DjangoModelFactory):
|
||||
"""Space factory."""
|
||||
name = factory.LazyAttribute(lambda x: faker.word())
|
||||
|
||||
@classmethod
|
||||
def _create(cls, model_class, **kwargs):
|
||||
with scopes_disabled():
|
||||
return super()._create(model_class, **kwargs)
|
||||
|
||||
class Meta:
|
||||
model = 'cookbook.Space'
|
||||
|
||||
|
||||
class FoodFactory(factory.django.DjangoModelFactory):
|
||||
"""Food factory."""
|
||||
name = factory.LazyAttribute(lambda x: faker.sentence(nb_words=3))
|
||||
description = factory.LazyAttribute(lambda x: faker.sentence(nb_words=10))
|
||||
space = factory.SubFactory(SpaceFactory)
|
||||
|
||||
class Meta:
|
||||
model = 'cookbook.Food'
|
||||
Reference in New Issue
Block a user