summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-13 16:06:13 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-13 16:06:13 +0200
commit64a059101d0119e18c1cb0b15b0e9e15795ccba1 (patch)
tree7f15e7e83dbc6fe9095aac937c211f7b5c1fbaad /tests.py
parentf57a0c213ffe12325e20e69e5cc03ff27633d06c (diff)
downloadfactory-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.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index 89a9363..bc534a6 100644
--- a/tests.py
+++ b/tests.py
@@ -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):