summaryrefslogtreecommitdiff
path: root/tests/test_base.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-16 20:28:21 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-16 22:38:42 +0200
commit6efa57cf38f945c55214a94e0e7c12cc7eff474f (patch)
tree2f43cb1fe7af4d0a4ee40ba54a4603ec74da215c /tests/test_base.py
parentdf0b1124cbb9f244dc40f435410ec16462a8fc9b (diff)
downloadfactory-boy-6efa57cf38f945c55214a94e0e7c12cc7eff474f.tar
factory-boy-6efa57cf38f945c55214a94e0e7c12cc7eff474f.tar.gz
Refactor building_function/creation_function handling.
Rely on inheritance instead of handwritten set_creation_function and such. Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests/test_base.py')
-rw-r--r--tests/test_base.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/test_base.py b/tests/test_base.py
index 5cbb31b..7ec3d0e 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.iteritems():
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
@@ -114,7 +120,7 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
def testCreateStrategy(self):
# Default default_strategy
- class TestModelFactory(base.Factory):
+ class TestModelFactory(FakeModelFactory):
FACTORY_FOR = TestModel
one = 'one'
@@ -215,7 +221,7 @@ class FactoryCreationTestCase(unittest.TestCase):
self.assertEqual(TestFactory.default_strategy, base.STUB_STRATEGY)
def testCustomCreation(self):
- class TestModelFactory(base.Factory):
+ class TestModelFactory(FakeModelFactory):
FACTORY_FOR = TestModel
@classmethod