diff options
-rw-r--r-- | factory/declarations.py | 6 | ||||
-rw-r--r-- | tests/test_using.py | 29 |
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 |