From ae84379f86a0216685ce1886cd36ec6a550ab231 Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Sat, 15 Jun 2013 14:23:08 +0200 Subject: Add tests for RelatedFactory extraction. --- tests/test_using.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/test_using.py b/tests/test_using.py index a3f5322..db65002 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -1580,6 +1580,45 @@ class PostGenerationTestCase(unittest.TestCase): self.assertEqual(4, related.two) +class RelatedFactoryExtractionTestCase(unittest.TestCase): + def setUp(self): + self.relateds = [] + + class TestRelatedObject(object): + def __init__(subself, obj): + self.relateds.append(subself) + subself.obj = obj + obj.related = subself + + class TestRelatedObjectFactory(factory.Factory): + FACTORY_FOR = TestRelatedObject + + class TestObjectFactory(factory.Factory): + FACTORY_FOR = TestObject + one = factory.RelatedFactory(TestRelatedObjectFactory, 'obj') + + self.TestRelatedObject = TestRelatedObject + self.TestRelatedObjectFactory = TestRelatedObjectFactory + self.TestObjectFactory = TestObjectFactory + + def test_no_extraction(self): + o = self.TestObjectFactory() + self.assertEqual(1, len(self.relateds)) + rel = self.relateds[0] + self.assertEqual(o, rel.obj) + self.assertEqual(rel, o.related) + + def test_passed_value(self): + o = self.TestObjectFactory(one=42) + self.assertEqual([], self.relateds) + self.assertFalse(hasattr(o, 'related')) + + def test_passed_none(self): + o = self.TestObjectFactory(one=None) + self.assertEqual([], self.relateds) + self.assertFalse(hasattr(o, 'related')) + + class CircularTestCase(unittest.TestCase): def test_example(self): sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) -- cgit v1.2.3