aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2015-05-20 23:24:45 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2015-05-20 23:24:45 +0200
commitfa6d60d17ddb7b70c6bc2337d901ef8cc924e67b (patch)
tree83fb2851ab7dd64a54732159d3099488193aac02 /tests
parent536ac1b0fe7c4a04ad144022d6394b994feccdfd (diff)
downloadfactory-boy-fa6d60d17ddb7b70c6bc2337d901ef8cc924e67b.tar
factory-boy-fa6d60d17ddb7b70c6bc2337d901ef8cc924e67b.tar.gz
Add Meta.rename to handle name conflicts (See #206).
Define ``Meta.rename = {'attrs': 'attributes'}`` if your model expects a ``attributes`` kwarg but you can't define it since it's already reserved by the ``Factory`` class.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_using.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index b7fea81..6d75531 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -1076,6 +1076,21 @@ class KwargAdjustTestCase(unittest.TestCase):
self.assertEqual({'x': 1, 'y': 2, 'z': 3, 'foo': 3}, obj.kwargs)
self.assertEqual((), obj.args)
+ def test_rename(self):
+ class TestObject(object):
+ def __init__(self, attributes=None):
+ self.attributes = attributes
+
+ class TestObjectFactory(factory.Factory):
+ class Meta:
+ model = TestObject
+ rename = {'attributes_': 'attributes'}
+
+ attributes_ = 42
+
+ obj = TestObjectFactory.build()
+ self.assertEqual(42, obj.attributes)
+
class SubFactoryTestCase(unittest.TestCase):
def test_sub_factory(self):