From 8563a98022b8b3e855bf036a57aad4fd86319eff Mon Sep 17 00:00:00 2001 From: Raphaël Barrois Date: Fri, 6 Jan 2012 23:39:33 +0100 Subject: Add factory.build(), factory.create(), factory.stub() methods. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Those are shortcuts for writing a full Factory class. Signed-off-by: Raphaël Barrois --- tests/test_base.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_base.py') diff --git a/tests/test_base.py b/tests/test_base.py index 01855c3..5855682 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -55,6 +55,27 @@ class SafetyTestCase(unittest.TestCase): self.assertRaises(RuntimeError, base.BaseFactory) +class SimpleBuildTestCase(unittest.TestCase): + """Tests the minimalist 'factory.build/create' functions.""" + + def test_build(self): + obj = base.build(TestObject, two=2) + self.assertEqual(obj.one, None) + self.assertEqual(obj.two, 2) + self.assertEqual(obj.three, None) + self.assertEqual(obj.four, None) + + def test_create(self): + obj = base.create(FakeDjangoModel, foo='bar') + self.assertEqual(obj.id, 1) + self.assertEqual(obj.foo, 'bar') + + def test_stub(self): + obj = base.stub(TestObject, three=3) + self.assertEqual(obj.three, 3) + self.assertFalse(hasattr(obj, 'two')) + + class FactoryTestCase(unittest.TestCase): def testAttribute(self): class TestObjectFactory(base.Factory): -- cgit v1.2.3