diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2016-02-23 00:53:44 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2016-02-23 00:54:13 +0100 |
commit | fb608987a4fb61ff6198a6497359ec00058b9253 (patch) | |
tree | b49909f6c899c16c09e525499b6b0cb11d8eeaa8 | |
parent | 639b3a3763194374a71d2049a2da7d2e12cb1b1f (diff) | |
download | factory-boy-fb608987a4fb61ff6198a6497359ec00058b9253.tar factory-boy-fb608987a4fb61ff6198a6497359ec00058b9253.tar.gz |
Add test for "build as dict" trick (See #68).
-rw-r--r-- | tests/test_using.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py index 0a893c1..3ef5403 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -292,6 +292,19 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.three, 5) self.assertEqual(obj.four, None) + def test_build_to_dict(self): + # We have a generic factory + class TestObjectFactory(factory.Factory): + class Meta: + model = TestObject + + one = 'one' + two = factory.LazyAttribute(lambda o: o.one * 2) + + # Now, get a dict out of it + obj = factory.build(dict, FACTORY_CLASS=TestObjectFactory) + self.assertEqual({'one': 'one', 'two': 'oneone'}, obj) + class UsingFactoryTestCase(unittest.TestCase): def test_attribute(self): |