summaryrefslogtreecommitdiff
path: root/tests/test_using.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-17 01:22:47 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-17 01:22:47 +0200
commit2611973bb62d38ff23471fdc115cdd09e351be50 (patch)
tree113cf3c40090b02d10f210ad20224cc40492f3dd /tests/test_using.py
parent20515351bb0db936873db5dae133ea317050079d (diff)
downloadfactory-boy-2611973bb62d38ff23471fdc115cdd09e351be50.tar
factory-boy-2611973bb62d38ff23471fdc115cdd09e351be50.tar.gz
Add support for passing non-kwarg parameters to factories.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests/test_using.py')
-rw-r--r--tests/test_using.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index 8620127..7e141eb 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -675,6 +675,55 @@ class UsingFactoryTestCase(unittest.TestCase):
self.assertEqual(TestObjectFactory.alt_create(foo=1), {"foo": 1})
+class NonKwargParametersTestCase(unittest.TestCase):
+ def test_build(self):
+ class TestObject(object):
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+ FACTORY_ARG_PARAMETERS = ('one', 'two',)
+
+ one = 1
+ two = 2
+ three = 3
+
+ obj = TestObjectFactory.build()
+ self.assertEqual((1, 2), obj.args)
+ self.assertEqual({'three': 3}, obj.kwargs)
+
+ def test_create(self):
+ class TestObject(object):
+ def __init__(self, *args, **kwargs):
+ self.args = None
+ self.kwargs = None
+
+ @classmethod
+ def create(cls, *args, **kwargs):
+ inst = cls()
+ inst.args = args
+ inst.kwargs = kwargs
+ return inst
+
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+ FACTORY_ARG_PARAMETERS = ('one', 'two')
+
+ one = 1
+ two = 2
+ three = 3
+
+ @classmethod
+ def _create(cls, target_class, *args, **kwargs):
+ return target_class.create(*args, **kwargs)
+
+ obj = TestObjectFactory.create()
+ self.assertEqual((1, 2), obj.args)
+ self.assertEqual({'three': 3}, obj.kwargs)
+
+
class SubFactoryTestCase(unittest.TestCase):
def testSubFactory(self):
class TestModel2(FakeModel):