summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-08-13 12:06:52 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-08-13 12:11:09 +0200
commit2796de70d5bed4cfff5749085ce4e6f16eba1b1e (patch)
tree71fbfd55fdebfce3faf44426731d7dd7bbf78efd /tests
parent5730d4ac18f8684c37168033ef32d1ee31f5e4a1 (diff)
downloadfactory-boy-2796de70d5bed4cfff5749085ce4e6f16eba1b1e.tar
factory-boy-2796de70d5bed4cfff5749085ce4e6f16eba1b1e.tar.gz
Make ABSTRACT_FACTORY optional (Closes #74)
It will be automatically set to True if neither the Factory subclass nor its parents define a FACTORY_FOR argument. It can also be set on a Factory subclass to prevent it from being called.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_base.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/tests/test_base.py b/tests/test_base.py
index 8ac2f44..8cea6fc 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -73,6 +73,20 @@ class AbstractFactoryTestCase(unittest.TestCase):
# Passed
+ def test_factory_for_and_abstract_factory_optional(self):
+ """Ensure that ABSTRACT_FACTORY is optional."""
+ class TestObjectFactory(base.Factory):
+ pass
+
+ # passed
+
+ def test_abstract_factory_cannot_be_called(self):
+ class TestObjectFactory(base.Factory):
+ pass
+
+ self.assertRaises(base.FactoryError, TestObjectFactory.build)
+ self.assertRaises(base.FactoryError, TestObjectFactory.create)
+
class FactoryTestCase(unittest.TestCase):
def test_factory_for(self):
@@ -318,12 +332,10 @@ class FactoryCreationTestCase(unittest.TestCase):
# Errors
def test_no_associated_class(self):
- try:
- class Test(base.Factory):
- pass
- self.fail() # pragma: no cover
- except base.Factory.AssociatedClassError as e:
- self.assertTrue('autodiscovery' not in str(e))
+ class Test(base.Factory):
+ pass
+
+ self.assertTrue(Test._abstract_factory)
class PostGenerationParsingTestCase(unittest.TestCase):