summaryrefslogtreecommitdiff
path: root/tests/test_using.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2016-04-07 00:09:43 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2016-04-07 00:09:43 +0200
commit872718c1eb7865878ff17c8ce7dbeb004a089e40 (patch)
tree2b00752cbaa7dd7ce457f29354c2e7b728701ae9 /tests/test_using.py
parent94a9b2cf9ddd7be181c984793a5404e2b95a779e (diff)
parent5836329889ac45034978c69b6a6f7de4b0b5b75d (diff)
downloadfactory-boy-872718c1eb7865878ff17c8ce7dbeb004a089e40.tar
factory-boy-872718c1eb7865878ff17c8ce7dbeb004a089e40.tar.gz
Merge pull request #285 from sampaccoud/feature/add-documentation-and-test-about-factory-parent-attribute
Add documentation and test for subfactory using "factory_parent" attribute
Diffstat (limited to 'tests/test_using.py')
-rw-r--r--tests/test_using.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index eaeb8da..0ce29e9 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -1268,6 +1268,26 @@ class SubFactoryTestCase(unittest.TestCase):
self.assertEqual('x0x', test_model.two.one)
self.assertEqual('x0xx0x', test_model.two.two)
+ def test_sub_factory_with_lazy_fields_access_factory_parent(self):
+ class TestModel2(FakeModel):
+ pass
+
+ class TestModelFactory(FakeModelFactory):
+ class Meta:
+ model = TestModel
+ one = 3
+
+ class TestModel2Factory(FakeModelFactory):
+ class Meta:
+ model = TestModel2
+ one = 'parent'
+ child = factory.SubFactory(TestModelFactory,
+ one=factory.LazyAttribute(lambda o: '%s child' % o.factory_parent.one),
+ )
+
+ test_model = TestModel2Factory()
+ self.assertEqual('parent child', test_model.child.one)
+
def test_sub_factory_and_sequence(self):
class TestObject(object):
def __init__(self, **kwargs):