From 0b5270eab393fad20faa7a6a9720af18c97b1773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 31 May 2015 10:47:28 +0100 Subject: Properly handle custom Django managers (Closes #201). The actual behavior of Django with custom managers and inherited abstract models is rather complex, so this had to be adapted to the actual Django source code. --- tests/djapp/models.py | 11 +++++++++++ tests/test_django.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/djapp/models.py b/tests/djapp/models.py index 68b9709..cadefbc 100644 --- a/tests/djapp/models.py +++ b/tests/djapp/models.py @@ -110,3 +110,14 @@ class WithCustomManager(models.Model): foo = models.CharField(max_length=20) objects = CustomManager() + + +class AbstractWithCustomManager(models.Model): + custom_objects = CustomManager() + + class Meta: + abstract = True + + +class FromAbstractWithCustomManager(AbstractWithCustomManager): + pass diff --git a/tests/test_django.py b/tests/test_django.py index bde8efe..b8e7ccb 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -755,10 +755,21 @@ class PreventSignalsTestCase(unittest.TestCase): self.assertSignalsReactivated() -class DjangoCustomManagerTestCase(django_test.TestCase): +@unittest.skipIf(django is None, "Django not installed.") +class DjangoCustomManagerTestCase(unittest.TestCase): def test_extra_args(self): + # Our CustomManager will remove the 'arg=' argument. model = WithCustomManagerFactory(arg='foo') + def test_with_manager_on_abstract(self): + class ObjFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.FromAbstractWithCustomManager + + # Our CustomManager will remove the 'arg=' argument, + # invalid for the actual model. + ObjFactory.create(arg='invalid') + if __name__ == '__main__': # pragma: no cover unittest.main() -- cgit v1.2.3