summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-09-24 20:52:26 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-09-24 20:52:26 +0200
commit8e37debdc17c5649b8d6b2cf035fb58c4ad3c077 (patch)
tree439b52a21ad1f11e8b4abc37d20ecb190b2ef3e2 /tests
parent7fe9dcaa8494e73d57613d1288b4f86c4cba5bf0 (diff)
downloadfactory-boy-8e37debdc17c5649b8d6b2cf035fb58c4ad3c077.tar
factory-boy-8e37debdc17c5649b8d6b2cf035fb58c4ad3c077.tar.gz
Lint
Diffstat (limited to 'tests')
-rw-r--r--tests/test_using.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index 01e950f..3979cd0 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -1018,9 +1018,9 @@ class SubFactoryTestCase(unittest.TestCase):
class TestModel2Factory(FakeModelFactory):
FACTORY_FOR = TestModel2
two = factory.SubFactory(TestModelFactory,
- one=factory.Sequence(lambda n: 'x%dx' % n),
- two=factory.LazyAttribute(
- lambda o: '%s%s' % (o.one, o.one)))
+ one=factory.Sequence(lambda n: 'x%dx' % n),
+ two=factory.LazyAttribute(lambda o: '%s%s' % (o.one, o.one)),
+ )
test_model = TestModel2Factory(one=42)
self.assertEqual('x0x', test_model.two.one)
@@ -1128,6 +1128,32 @@ class SubFactoryTestCase(unittest.TestCase):
self.assertEqual(outer.wrap.wrapped.two.four, 4)
self.assertEqual(outer.wrap.friend, 5)
+ def test_nested_subfactory_with_override(self):
+ """Tests replacing a SubFactory field with an actual value."""
+
+ # The test class
+ class TestObject(object):
+ def __init__(self, two='one', wrapped=None):
+ self.two = two
+ self.wrapped = wrapped
+
+ # Innermost factory
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+ two = 'two'
+
+ # Intermediary factory
+ class WrappingTestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
+ wrapped = factory.SubFactory(TestObjectFactory)
+ wrapped__two = 'three'
+
+ obj = TestObject(two='four')
+ outer = WrappingTestObjectFactory(wrapped=obj)
+ self.assertEqual(obj, outer.wrapped)
+ self.assertEqual('four', outer.wrapped.two)
+
def test_sub_factory_and_inheritance(self):
"""Test inheriting from a factory with subfactories, overriding."""
class TestObject(object):