aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-06-15 14:23:08 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-06-15 14:23:08 +0200
commitae84379f86a0216685ce1886cd36ec6a550ab231 (patch)
tree8117852e1dcff7981ed4fbe558c7deaf1b0ca8a4 /tests
parentfda40cb64041aacdb776e0b1f4f4a635bdc9d70b (diff)
downloadfactory-boy-ae84379f86a0216685ce1886cd36ec6a550ab231.tar
factory-boy-ae84379f86a0216685ce1886cd36ec6a550ab231.tar.gz
Add tests for RelatedFactory extraction.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_using.py39
1 files changed, 39 insertions, 0 deletions
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__)))