summaryrefslogtreecommitdiff
path: root/tests/test_django.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2014-05-18 12:34:19 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2014-05-18 14:18:49 +0200
commit395744736691b3412dbedaffa8735e248a70c3c1 (patch)
tree4e4e67f8a907edcad3984a843707cf9b5dcad375 /tests/test_django.py
parent47b34e933f94e71e7aabd81cd1e065a807a55276 (diff)
downloadfactory-boy-395744736691b3412dbedaffa8735e248a70c3c1.tar
factory-boy-395744736691b3412dbedaffa8735e248a70c3c1.tar.gz
Switch tests to class Meta.
Diffstat (limited to 'tests/test_django.py')
-rw-r--r--tests/test_django.py58
1 files changed, 38 insertions, 20 deletions
diff --git a/tests/test_django.py b/tests/test_django.py
index 37bf7a5..2bc5fe2 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -99,61 +99,71 @@ def tearDownModule():
class StandardFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.StandardModel
+ class Meta:
+ target = models.StandardModel
foo = factory.Sequence(lambda n: "foo%d" % n)
class StandardFactoryWithPKField(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.StandardModel
- FACTORY_DJANGO_GET_OR_CREATE = ('pk',)
+ class Meta:
+ target = models.StandardModel
+ django_get_or_create = ('pk',)
foo = factory.Sequence(lambda n: "foo%d" % n)
pk = None
class NonIntegerPkFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.NonIntegerPk
+ class Meta:
+ target = models.NonIntegerPk
foo = factory.Sequence(lambda n: "foo%d" % n)
bar = ''
class AbstractBaseFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.AbstractBase
- ABSTRACT_FACTORY = True
+ class Meta:
+ target = models.AbstractBase
+ abstract = True
foo = factory.Sequence(lambda n: "foo%d" % n)
class ConcreteSonFactory(AbstractBaseFactory):
- FACTORY_FOR = models.ConcreteSon
+ class Meta:
+ target = models.ConcreteSon
class AbstractSonFactory(AbstractBaseFactory):
- FACTORY_FOR = models.AbstractSon
+ class Meta:
+ target = models.AbstractSon
class ConcreteGrandSonFactory(AbstractBaseFactory):
- FACTORY_FOR = models.ConcreteGrandSon
+ class Meta:
+ target = models.ConcreteGrandSon
class WithFileFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.WithFile
+ class Meta:
+ target = models.WithFile
if django is not None:
afile = factory.django.FileField()
class WithImageFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.WithImage
+ class Meta:
+ target = models.WithImage
if django is not None:
animage = factory.django.ImageField()
class WithSignalsFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.WithSignals
+ class Meta:
+ target = models.WithSignals
@unittest.skipIf(django is None, "Django not installed.")
@@ -220,17 +230,20 @@ class DjangoPkForceTestCase(django_test.TestCase):
@unittest.skipIf(django is None, "Django not installed.")
class DjangoModelLoadingTestCase(django_test.TestCase):
- """Tests FACTORY_FOR = 'app.Model' pattern."""
+ """Tests class Meta:
+ target = 'app.Model' pattern."""
def test_loading(self):
class ExampleFactory(factory.DjangoModelFactory):
- FACTORY_FOR = 'djapp.StandardModel'
+ class Meta:
+ target = 'djapp.StandardModel'
self.assertEqual(models.StandardModel, ExampleFactory._get_target_class())
def test_building(self):
class ExampleFactory(factory.DjangoModelFactory):
- FACTORY_FOR = 'djapp.StandardModel'
+ class Meta:
+ target = 'djapp.StandardModel'
e = ExampleFactory.build()
self.assertEqual(models.StandardModel, e.__class__)
@@ -241,7 +254,8 @@ class DjangoModelLoadingTestCase(django_test.TestCase):
See https://github.com/rbarrois/factory_boy/issues/109.
"""
class ExampleFactory(factory.DjangoModelFactory):
- FACTORY_FOR = 'djapp.StandardModel'
+ class Meta:
+ target = 'djapp.StandardModel'
class Example2Factory(ExampleFactory):
pass
@@ -255,12 +269,14 @@ class DjangoModelLoadingTestCase(django_test.TestCase):
See https://github.com/rbarrois/factory_boy/issues/109.
"""
class ExampleFactory(factory.DjangoModelFactory):
- FACTORY_FOR = 'djapp.StandardModel'
+ class Meta:
+ target = 'djapp.StandardModel'
foo = factory.Sequence(lambda n: n)
class Example2Factory(ExampleFactory):
- FACTORY_FOR = 'djapp.StandardSon'
+ class Meta:
+ target = 'djapp.StandardSon'
self.assertEqual(models.StandardSon, Example2Factory._get_target_class())
@@ -563,7 +579,8 @@ class PreventSignalsTestCase(unittest.TestCase):
def test_class_decorator(self):
@factory.django.mute_signals(signals.pre_save, signals.post_save)
class WithSignalsDecoratedFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.WithSignals
+ class Meta:
+ target = models.WithSignals
WithSignalsDecoratedFactory()
@@ -576,7 +593,8 @@ class PreventSignalsTestCase(unittest.TestCase):
def test_class_decorator_build(self):
@factory.django.mute_signals(signals.pre_save, signals.post_save)
class WithSignalsDecoratedFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = models.WithSignals
+ class Meta:
+ target = models.WithSignals
WithSignalsDecoratedFactory.build()