aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_django.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_django.py b/tests/test_django.py
index 7cebf8d..94101e9 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -101,6 +101,14 @@ class StandardFactory(factory.django.DjangoModelFactory):
foo = factory.Sequence(lambda n: "foo%d" % n)
+class StandardFactoryWithPKField(factory.django.DjangoModelFactory):
+ FACTORY_FOR = models.StandardModel
+ FACTORY_DJANGO_GET_OR_CREATE = ('pk',)
+
+ foo = factory.Sequence(lambda n: "foo%d" % n)
+ pk = None
+
+
class NonIntegerPkFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.NonIntegerPk
@@ -171,6 +179,31 @@ class DjangoPkSequenceTestCase(django_test.TestCase):
@unittest.skipIf(django is None, "Django not installed.")
+class DjangoPkForceTestCase(django_test.TestCase):
+ def setUp(self):
+ super(DjangoPkForceTestCase, self).setUp()
+ StandardFactoryWithPKField.reset_sequence()
+
+ def test_no_pk(self):
+ std = StandardFactoryWithPKField()
+ self.assertIsNotNone(std.pk)
+ self.assertEqual('foo1', std.foo)
+
+ def test_force_pk(self):
+ std = StandardFactoryWithPKField(pk=42)
+ self.assertIsNotNone(std.pk)
+ self.assertEqual('foo1', std.foo)
+
+ def test_reuse_pk(self):
+ std1 = StandardFactoryWithPKField(foo='bar')
+ self.assertIsNotNone(std1.pk)
+
+ std2 = StandardFactoryWithPKField(pk=std1.pk, foo='blah')
+ self.assertEqual(std1.pk, std2.pk)
+ self.assertEqual('bar', std2.foo)
+
+
+@unittest.skipIf(django is None, "Django not installed.")
class DjangoModelLoadingTestCase(django_test.TestCase):
"""Tests FACTORY_FOR = 'app.Model' pattern."""