diff options
author | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2012-06-01 13:35:46 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2012-06-01 13:35:46 +0200 |
commit | 18393e00d21276ba7f8b6d83b51510470781ec69 (patch) | |
tree | 43b3774535a60ca1c92dbe677f5e80b368fa3f5c /tests | |
parent | f60ae420b8505100b9079a6c695074ef12c5e7c7 (diff) | |
download | factory-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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_using.py | 29 |
1 files changed, 28 insertions, 1 deletions
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 |