summaryrefslogtreecommitdiff
path: root/tests/test_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_base.py')
-rw-r--r--tests/test_base.py46
1 files changed, 38 insertions, 8 deletions
diff --git a/tests/test_base.py b/tests/test_base.py
index 216711a..73e59fa 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -35,19 +35,25 @@ class TestObject(object):
self.four = four
class FakeDjangoModel(object):
- class FakeDjangoManager(object):
- def create(self, **kwargs):
- fake_model = FakeDjangoModel(**kwargs)
- fake_model.id = 1
- return fake_model
-
- objects = FakeDjangoManager()
+ @classmethod
+ def create(cls, **kwargs):
+ instance = cls(**kwargs)
+ instance.id = 1
+ return instance
def __init__(self, **kwargs):
for name, value in kwargs.items():
setattr(self, name, value)
self.id = None
+class FakeModelFactory(base.Factory):
+ ABSTRACT_FACTORY = True
+
+ @classmethod
+ def _create(cls, target_class, *args, **kwargs):
+ return target_class.create(**kwargs)
+
+
class TestModel(FakeDjangoModel):
pass
@@ -84,6 +90,8 @@ class FactoryTestCase(unittest.TestCase):
def test_lazy_attribute_non_existent_param(self):
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
one = declarations.LazyAttribute(lambda a: a.does_not_exist )
self.assertRaises(AttributeError, TestObjectFactory)
@@ -91,9 +99,13 @@ class FactoryTestCase(unittest.TestCase):
def test_inheritance_with_sequence(self):
"""Tests that sequence IDs are shared between parent and son."""
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
one = declarations.Sequence(lambda a: a)
class TestSubFactory(TestObjectFactory):
+ FACTORY_FOR = TestObject
+
pass
parent = TestObjectFactory.build()
@@ -115,6 +127,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
base.Factory.FACTORY_STRATEGY = base.BUILD_STRATEGY
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory()
@@ -124,7 +138,9 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
def test_create_strategy(self):
# Default FACTORY_STRATEGY
- class TestModelFactory(base.Factory):
+ class TestModelFactory(FakeModelFactory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory()
@@ -135,6 +151,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
base.Factory.FACTORY_STRATEGY = base.STUB_STRATEGY
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory()
@@ -145,12 +163,16 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
base.Factory.FACTORY_STRATEGY = 'unknown'
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
self.assertRaises(base.Factory.UnknownStrategy, TestModelFactory)
def test_stub_with_non_stub_strategy(self):
class TestModelFactory(base.StubFactory):
+ FACTORY_FOR = TestModel
+
one = 'one'
TestModelFactory.FACTORY_STRATEGY = base.CREATE_STRATEGY
@@ -163,6 +185,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
def test_change_strategy(self):
@base.use_strategy(base.CREATE_STRATEGY)
class TestModelFactory(base.StubFactory):
+ FACTORY_FOR = TestModel
+
one = 'one'
self.assertEqual(base.CREATE_STRATEGY, TestModelFactory.FACTORY_STRATEGY)
@@ -183,6 +207,8 @@ class FactoryCreationTestCase(unittest.TestCase):
def test_inheritance_with_stub(self):
class TestObjectFactory(base.StubFactory):
+ FACTORY_FOR = TestObject
+
pass
class TestFactory(TestObjectFactory):
@@ -224,12 +250,16 @@ class PostGenerationParsingTestCase(unittest.TestCase):
def test_extraction(self):
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
foo = declarations.PostGenerationDeclaration()
self.assertIn('foo', TestObjectFactory._postgen_declarations)
def test_classlevel_extraction(self):
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
foo = declarations.PostGenerationDeclaration()
foo__bar = 42