aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-04-02 23:07:03 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-04-02 23:07:03 +0200
commit69e7a86875f97dc12e941302fabe417122f2cb7e (patch)
tree096d558041ad5ff0794a159580aab09b8f7bb9a5 /tests
parent54a915fa25a66d3b7732a096eba7c2dd4a7b5a8e (diff)
downloadfactory-boy-69e7a86875f97dc12e941302fabe417122f2cb7e.tar
factory-boy-69e7a86875f97dc12e941302fabe417122f2cb7e.tar.gz
Add Factory.FACTORY_HIDDEN_ARGS.
Fields listed in this class attributes will be removed from the kwargs dict passed to the associated class for building/creation.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_using.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index 2e07621..41b666f 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -762,6 +762,65 @@ class UsingFactoryTestCase(unittest.TestCase):
self.assertEqual(TestObjectFactory.alt_create(foo=1), {"foo": 1})
+ def test_arg_parameters(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 = ('x', 'y')
+
+ x = 1
+ y = 2
+ z = 3
+ t = 4
+
+ obj = TestObjectFactory.build(x=42, z=5)
+ self.assertEqual((42, 2), obj.args)
+ self.assertEqual({'z': 5, 't': 4}, obj.kwargs)
+
+ def test_hidden_args(self):
+ class TestObject(object):
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+ FACTORY_HIDDEN_ARGS = ('x', 'z')
+
+ x = 1
+ y = 2
+ z = 3
+ t = 4
+
+ obj = TestObjectFactory.build(x=42, z=5)
+ self.assertEqual((), obj.args)
+ self.assertEqual({'y': 2, 't': 4}, obj.kwargs)
+
+ def test_hidden_args_and_arg_parameters(self):
+ class TestObject(object):
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+ FACTORY_HIDDEN_ARGS = ('x', 'z')
+ FACTORY_ARG_PARAMETERS = ('y',)
+
+ x = 1
+ y = 2
+ z = 3
+ t = 4
+
+ obj = TestObjectFactory.build(x=42, z=5)
+ self.assertEqual((2,), obj.args)
+ self.assertEqual({'t': 4}, obj.kwargs)
+
+
class NonKwargParametersTestCase(unittest.TestCase):
def test_build(self):