From 8ea8f73b05d0d6ec42c315b21244eedc8c9f4060 Mon Sep 17 00:00:00 2001 From: Nadege Michel Date: Sat, 22 Jul 2023 10:41:38 +0000 Subject: [PATCH] Add one test for post generation hook --- tests/test_using.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_using.py b/tests/test_using.py index 694b1108..76dc406d 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -2521,6 +2521,29 @@ def incr_one(self, _create, _increment): self.assertEqual(3, obj.one) self.assertFalse(hasattr(obj, 'incr_one')) + + def test_post_generation_async(self): + class TestAsyncFactory(FakeAsyncModelFactory): + class Meta: + model = AsyncTestModel + + one = 1 + + @factory.post_generation + def incr_one(self, _create, _increment): + self.one += 1 + + obj = TestAsyncFactory.create() + self.assertEqual(create_marker, obj.id) + self.assertEqual(2, obj.one) + self.assertFalse(hasattr(obj, 'incr_one')) + + obj = TestAsyncFactory.create(one=2) + self.assertEqual(create_marker, obj.id) + self.assertEqual(3, obj.one) + self.assertFalse(hasattr(obj, 'incr_one')) + + def test_post_generation_hook(self): class TestObjectFactory(factory.Factory): class Meta: