summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2015-03-26 22:37:54 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2015-03-26 22:37:54 +0100
commit72fd943513b0e516f06c53b13ff35ca814b0a4a0 (patch)
tree2d0bb5f265860afe363ed95d31191ce5ee40a638 /tests
parent69befae5fde1897cf68c4d44a146db5ba642c814 (diff)
downloadfactory-boy-72fd943513b0e516f06c53b13ff35ca814b0a4a0.tar
factory-boy-72fd943513b0e516f06c53b13ff35ca814b0a4a0.tar.gz
Fix issues between mute_signals() and factory inheritance (Closes #183).
Previously, if a factory was decorated with ``@mute_signals`` and one of its descendant called another one of its descendant, signals weren't unmuted properly.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_django.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_django.py b/tests/test_django.py
index 0cbef19..4653305 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -592,6 +592,27 @@ class PreventSignalsTestCase(unittest.TestCase):
self.assertSignalsReactivated()
+ def test_class_decorator_with_subfactory(self):
+ @factory.django.mute_signals(signals.pre_save, signals.post_save)
+ class WithSignalsDecoratedFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = models.WithSignals
+
+ @factory.post_generation
+ def post(obj, create, extracted, **kwargs):
+ if not extracted:
+ WithSignalsDecoratedFactory.create(post=42)
+
+ # This will disable the signals (twice), create two objects,
+ # and reactivate the signals.
+ WithSignalsDecoratedFactory()
+
+ self.assertEqual(self.handlers.pre_init.call_count, 2)
+ self.assertFalse(self.handlers.pre_save.called)
+ self.assertFalse(self.handlers.post_save.called)
+
+ self.assertSignalsReactivated()
+
def test_class_decorator_build(self):
@factory.django.mute_signals(signals.pre_save, signals.post_save)
class WithSignalsDecoratedFactory(factory.django.DjangoModelFactory):