Skip to content

Commit

Permalink
Add one test for post generation hook
Browse files Browse the repository at this point in the history
  • Loading branch information
nadege committed Jul 22, 2023
1 parent 97a3c63 commit 8ea8f73
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_using.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8ea8f73

Please sign in to comment.