From 5ec4a50edc67073e54218549d6985f934f94b88f Mon Sep 17 00:00:00 2001 From: Raphaël Barrois Date: Wed, 14 Nov 2012 23:42:46 +0100 Subject: Add an extension point for kwargs mangling. 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/test_using.py b/tests/test_using.py index 38c9e9e..f489f28 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -741,6 +741,28 @@ class NonKwargParametersTestCase(unittest.TestCase): self.assertEqual({'three': 3}, obj.kwargs) +class KwargAdjustTestCase(unittest.TestCase): + """Tests for the _adjust_kwargs method.""" + + 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 + + @classmethod + def _adjust_kwargs(cls, **kwargs): + kwargs['foo'] = len(kwargs) + return kwargs + + obj = TestObjectFactory.build(x=1, y=2, z=3) + self.assertEqual({'x': 1, 'y': 2, 'z': 3, 'foo': 3}, obj.kwargs) + self.assertEqual((), obj.args) + + class SubFactoryTestCase(unittest.TestCase): def testSubFactory(self): class TestModel2(FakeModel): -- cgit v1.2.3