From 2e5046bda818771f474a1514465f71bd62be9dcd Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Wed, 25 Sep 2013 10:58:12 +0200 Subject: Fix Django sequences with abstract base models. --- tests/djapp/models.py | 11 +++++++++++ tests/test_django.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/djapp/models.py b/tests/djapp/models.py index cc34643..3f25fbb 100644 --- a/tests/djapp/models.py +++ b/tests/djapp/models.py @@ -44,6 +44,17 @@ class NonIntegerPk(models.Model): bar = models.CharField(max_length=20, blank=True) +class AbstractBase(models.Model): + foo = models.CharField(max_length=20) + + class Meta: + abstract = True + + +class ConcreteSon(AbstractBase): + pass + + WITHFILE_UPLOAD_TO = 'django' WITHFILE_UPLOAD_DIR = os.path.join(settings.MEDIA_ROOT, WITHFILE_UPLOAD_TO) diff --git a/tests/test_django.py b/tests/test_django.py index b27562c..7cebf8d 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -64,6 +64,8 @@ else: # pragma: no cover models = Fake() models.StandardModel = Fake + models.AbstractBase = Fake + models.ConcreteSon = Fake models.NonIntegerPk = Fake models.WithFile = Fake models.WithImage = Fake @@ -106,6 +108,17 @@ class NonIntegerPkFactory(factory.django.DjangoModelFactory): bar = '' +class AbstractBaseFactory(factory.django.DjangoModelFactory): + FACTORY_FOR = models.AbstractBase + ABSTRACT_FACTORY = True + + foo = factory.Sequence(lambda n: "foo%d" % n) + + +class ConcreteSonFactory(AbstractBaseFactory): + FACTORY_FOR = models.ConcreteSon + + class WithFileFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.WithFile @@ -223,6 +236,14 @@ class DjangoNonIntegerPkTestCase(django_test.TestCase): self.assertEqual('foo1', nonint2.pk) +@unittest.skipIf(django is None, "Django not installed.") +class DjangoAbstractBaseSequenceTestCase(django_test.TestCase): + def test_auto_sequence(self): + with factory.debug(): + obj = ConcreteSonFactory() + self.assertEqual(1, obj.pk) + + @unittest.skipIf(django is None, "Django not installed.") class DjangoFileFieldTestCase(unittest.TestCase): -- cgit v1.2.3