summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2012-06-01 13:35:46 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2012-06-01 13:35:46 +0200
commit18393e00d21276ba7f8b6d83b51510470781ec69 (patch)
tree43b3774535a60ca1c92dbe677f5e80b368fa3f5c
parentf60ae420b8505100b9079a6c695074ef12c5e7c7 (diff)
downloadfactory-boy-18393e00d21276ba7f8b6d83b51510470781ec69.tar
factory-boy-18393e00d21276ba7f8b6d83b51510470781ec69.tar.gz
Fix sequence count for SubFactory (Closes #16).
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
-rw-r--r--factory/declarations.py6
-rw-r--r--tests/test_using.py29
2 files changed, 30 insertions, 5 deletions
diff --git a/factory/declarations.py b/factory/declarations.py
index 828d8a7..6b53c88 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -244,12 +244,10 @@ class SubFactory(OrderedDeclaration):
defaults.update(extra)
defaults['__containers'] = containers
- attrs = self.factory.attributes(create, defaults)
-
if create:
- return self.factory.create(**attrs)
+ return self.factory.create(**defaults)
else:
- return self.factory.build(**attrs)
+ return self.factory.build(**defaults)
class PostGenerationDeclaration(object):
diff --git a/tests/test_using.py b/tests/test_using.py
index 3bb0959..b5687b5 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -616,7 +616,7 @@ class SubFactoryTestCase(unittest.TestCase):
self.assertEqual('x0x', test_model.two.one)
self.assertEqual('x0xx0x', test_model.two.two)
- def testSubFactoryOverriding(self):
+ def testSubFactoryAndSequence(self):
class TestObject(object):
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
@@ -625,9 +625,36 @@ class SubFactoryTestCase(unittest.TestCase):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
+ one = factory.Sequence(lambda n: int(n))
+
class WrappingTestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
+ wrapped = factory.SubFactory(TestObjectFactory)
+
+ wrapping = WrappingTestObjectFactory.build()
+ self.assertEqual(0, wrapping.wrapped.one)
+ wrapping = WrappingTestObjectFactory.build()
+ self.assertEqual(1, wrapping.wrapped.one)
+
+ def testSubFactoryOverriding(self):
+ class TestObject(object):
+ def __init__(self, **kwargs):
+ for k, v in kwargs.iteritems():
+ setattr(self, k, v)
+
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
+
+ class OtherTestObject(object):
+ def __init__(self, **kwargs):
+ for k, v in kwargs.iteritems():
+ setattr(self, k, v)
+
+ class WrappingTestObjectFactory(factory.Factory):
+ FACTORY_FOR = OtherTestObject
+
wrapped = factory.SubFactory(TestObjectFactory, two=2, four=4)
wrapped__two = 4
wrapped__three = 3