From bcc1ad6fdce458ae3b24270789ab60ddd2425c4a Mon Sep 17 00:00:00 2001 From: Raphaël Barrois Date: Fri, 6 Jan 2012 23:43:52 +0100 Subject: Publish the make_factory method, and make sure that complex declarations work with it. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- tests/test_base.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') 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): -- cgit v1.2.3