diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-01-06 23:43:52 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-01-06 23:43:52 +0100 |
commit | bcc1ad6fdce458ae3b24270789ab60ddd2425c4a (patch) | |
tree | ba73ba9cc16e6bffed9f843500a23c1ddb3013c7 /tests/test_base.py | |
parent | 8563a98022b8b3e855bf036a57aad4fd86319eff (diff) | |
download | factory-boy-bcc1ad6fdce458ae3b24270789ab60ddd2425c4a.tar factory-boy-bcc1ad6fdce458ae3b24270789ab60ddd2425c4a.tar.gz |
Publish the make_factory method, and make sure that complex declarations work with it.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests/test_base.py')
-rw-r--r-- | tests/test_base.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_base.py b/tests/test_base.py index 5855682..b445cb3 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -65,6 +65,13 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.three, None) self.assertEqual(obj.four, None) + def test_complex(self): + obj = base.build(TestObject, two=2, three=declarations.LazyAttribute(lambda o: o.two + 1)) + self.assertEqual(obj.one, None) + self.assertEqual(obj.two, 2) + self.assertEqual(obj.three, 3) + self.assertEqual(obj.four, None) + def test_create(self): obj = base.create(FakeDjangoModel, foo='bar') self.assertEqual(obj.id, 1) @@ -75,6 +82,21 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.three, 3) self.assertFalse(hasattr(obj, 'two')) + def test_make_factory(self): + fact = base.make_factory(TestObject, two=2, three=declarations.LazyAttribute(lambda o: o.two + 1)) + + obj = fact.build() + self.assertEqual(obj.one, None) + self.assertEqual(obj.two, 2) + self.assertEqual(obj.three, 3) + self.assertEqual(obj.four, None) + + obj = fact.build(two=4) + self.assertEqual(obj.one, None) + self.assertEqual(obj.two, 4) + self.assertEqual(obj.three, 5) + self.assertEqual(obj.four, None) + class FactoryTestCase(unittest.TestCase): def testAttribute(self): |