summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-06-13 11:27:14 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-06-13 11:27:14 +0200
commite16a7e3d15c7b88bceadbbe1d75363103570e2b3 (patch)
tree0a32fe2d6ac2c9f02de36ad65ee5dbb55bff691d /factory
parentcb66c88859d8de161561ae42c9eccd8af56440c8 (diff)
downloadfactory-boy-e16a7e3d15c7b88bceadbbe1d75363103570e2b3.tar
factory-boy-e16a7e3d15c7b88bceadbbe1d75363103570e2b3.tar.gz
Add tests for nice behaviour of SubFactory.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'factory')
-rw-r--r--factory/test_base.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/factory/test_base.py b/factory/test_base.py
index 3909a69..689b56d 100644
--- a/factory/test_base.py
+++ b/factory/test_base.py
@@ -250,6 +250,24 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
self.assertEqual(1, test_model.id)
self.assertEqual(1, test_model.two.id)
+ def testSubFactoryWithLazyFields(self):
+ class TestModel2(FakeDjangoModel):
+ pass
+
+ class TestModelFactory(Factory):
+ FACTORY_FOR = TestModel
+
+ class TestModel2Factory(Factory):
+ FACTORY_FOR = TestModel2
+ two = declarations.SubFactory(TestModelFactory,
+ one=declarations.Sequence(lambda n: 'x%sx' % n),
+ two=declarations.LazyAttribute(
+ lambda o: '%s%s' % (o.one, o.one)))
+
+ test_model = TestModel2Factory(one=42)
+ self.assertEqual('x0x', test_model.two.one)
+ self.assertEqual('x0xx0x', test_model.two.two)
+
def testStubStrategy(self):
Factory.default_strategy = STUB_STRATEGY