diff options
author | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2012-04-13 19:42:19 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2012-04-15 10:06:39 +0200 |
commit | 0e7fed312bf2de6d628a61b116bd91e04bf0a9ff (patch) | |
tree | 103408b5bee8339eee6e510300a374b0bcea748f /tests | |
parent | b590e5014351a79d66d2f4816b1a6aa83908f395 (diff) | |
download | factory-boy-0e7fed312bf2de6d628a61b116bd91e04bf0a9ff.tar factory-boy-0e7fed312bf2de6d628a61b116bd91e04bf0a9ff.tar.gz |
Handle the PostGeneration declarations.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_using.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py index a3cf89c..54106a9 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -835,6 +835,39 @@ class IteratorTestCase(unittest.TestCase): self.assertEqual(i % 5, obj.one) +class PostDeclarationHookTestCase(unittest.TestCase): + def test_post_declaration(self): + class TestObjectFactory(factory.Factory): + one = 1 + + @factory.post_declaration() + def incr_one(self, _create, _increment): + self.one += 1 + + obj = TestObjectFactory.build() + self.assertEqual(2, obj.one) + self.assertFalse(hasattr(obj, 'incr_one')) + + obj = TestObjectFactory.build(one=2) + self.assertEqual(3, obj.one) + self.assertFalse(hasattr(obj, 'incr_one')) + + def test_post_declaration_extraction(self): + class TestObjectFactory(factory.Factory): + one = 1 + + @factory.post_declaration() + def incr_one(self, _create, increment=1): + self.one += increment + + obj = TestObjectFactory.build(incr_one=2) + self.assertEqual(3, obj.one) + self.assertFalse(hasattr(obj, 'incr_one')) + + obj = TestObjectFactory.build(one=2, incr_one=2) + self.assertEqual(4, obj.one) + self.assertFalse(hasattr(obj, 'incr_one')) + if __name__ == '__main__': unittest.main() |