From 18393e00d21276ba7f8b6d83b51510470781ec69 Mon Sep 17 00:00:00 2001 From: Raphaël Barrois Date: Fri, 1 Jun 2012 13:35:46 +0200 Subject: Fix sequence count for SubFactory (Closes #16). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- tests/test_using.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tests') 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 -- cgit v1.2.3