diff options
author | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2011-05-13 16:06:13 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2011-05-13 16:06:13 +0200 |
commit | 64a059101d0119e18c1cb0b15b0e9e15795ccba1 (patch) | |
tree | 7f15e7e83dbc6fe9095aac937c211f7b5c1fbaad /tests.py | |
parent | f57a0c213ffe12325e20e69e5cc03ff27633d06c (diff) | |
download | factory-boy-64a059101d0119e18c1cb0b15b0e9e15795ccba1.tar factory-boy-64a059101d0119e18c1cb0b15b0e9e15795ccba1.tar.gz |
Improve handling of custom build/create functions.
Only public attributes (i.e not starting with _) will be handled properly.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'tests.py')
-rw-r--r-- | tests.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -258,6 +258,23 @@ class FactoryCreationTestCase(unittest.TestCase): self.assertEqual(TestFactory.default_strategy, STUB_STRATEGY) + def testCustomCreation(self): + class TestModelFactory(Factory): + @classmethod + def _prepare(cls, create, **kwargs): + kwargs['four'] = 4 + return super(TestModelFactory, cls)._prepare(create, **kwargs) + + b = TestModelFactory.build(one=1) + self.assertEqual(1, b.one) + self.assertEqual(4, b.four) + self.assertEqual(None, b.id) + + c = TestModelFactory(one=1) + self.assertEqual(1, c.one) + self.assertEqual(4, c.four) + self.assertEqual(1, c.id) + # Errors def testNoAssociatedClassWithAutodiscovery(self): |