diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-05-17 18:47:04 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-05-18 14:17:05 +0200 |
commit | 69894fce7977ea55f8cc3ad141840bab49330859 (patch) | |
tree | 07eb056883112ef58b7be037cde76c5f805c8ba2 /tests | |
parent | 1fdba9d9417e8f69b39784ee19129a6c43128620 (diff) | |
download | factory-boy-69894fce7977ea55f8cc3ad141840bab49330859.tar factory-boy-69894fce7977ea55f8cc3ad141840bab49330859.tar.gz |
Switch FACTORY_FOR and related to 'class Meta'.
This is easier to declare, avoids cluttering the namespace, and provides
entry points for ORM-specific customization.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alter_time.py | 2 | ||||
-rw-r--r-- | tests/test_base.py | 30 |
2 files changed, 16 insertions, 16 deletions
diff --git a/tests/alter_time.py b/tests/alter_time.py index db0a611..aa2db3b 100644 --- a/tests/alter_time.py +++ b/tests/alter_time.py @@ -7,7 +7,7 @@ from __future__ import print_function import datetime -import mock +from .compat import mock real_datetime_class = datetime.datetime diff --git a/tests/test_base.py b/tests/test_base.py index ba69164..2edf829 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -107,7 +107,7 @@ class FactoryTestCase(unittest.TestCase): class TestObjectFactory(base.Factory): FACTORY_FOR = TestObject - self.assertEqual(TestObject, TestObjectFactory.FACTORY_FOR) + self.assertEqual(TestObject, TestObjectFactory._meta.target) obj = TestObjectFactory.build() self.assertFalse(hasattr(obj, 'FACTORY_FOR')) @@ -226,13 +226,13 @@ class FactorySequenceTestCase(unittest.TestCase): class FactoryDefaultStrategyTestCase(unittest.TestCase): def setUp(self): - self.default_strategy = base.Factory.FACTORY_STRATEGY + self.default_strategy = base.Factory._meta.strategy def tearDown(self): - base.Factory.FACTORY_STRATEGY = self.default_strategy + base.Factory._meta.strategy = self.default_strategy def test_build_strategy(self): - base.Factory.FACTORY_STRATEGY = base.BUILD_STRATEGY + base.Factory._meta.strategy = base.BUILD_STRATEGY class TestModelFactory(base.Factory): FACTORY_FOR = TestModel @@ -256,7 +256,7 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): self.assertTrue(test_model.id) def test_stub_strategy(self): - base.Factory.FACTORY_STRATEGY = base.STUB_STRATEGY + base.Factory._meta.strategy = base.STUB_STRATEGY class TestModelFactory(base.Factory): FACTORY_FOR = TestModel @@ -268,7 +268,7 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): self.assertFalse(hasattr(test_model, 'id')) # We should have a plain old object def test_unknown_strategy(self): - base.Factory.FACTORY_STRATEGY = 'unknown' + base.Factory._meta.strategy = 'unknown' class TestModelFactory(base.Factory): FACTORY_FOR = TestModel @@ -283,11 +283,11 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): one = 'one' - TestModelFactory.FACTORY_STRATEGY = base.CREATE_STRATEGY + TestModelFactory._meta.strategy = base.CREATE_STRATEGY self.assertRaises(base.StubFactory.UnsupportedStrategy, TestModelFactory) - TestModelFactory.FACTORY_STRATEGY = base.BUILD_STRATEGY + TestModelFactory._meta.strategy = base.BUILD_STRATEGY self.assertRaises(base.StubFactory.UnsupportedStrategy, TestModelFactory) def test_change_strategy(self): @@ -297,7 +297,7 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): one = 'one' - self.assertEqual(base.CREATE_STRATEGY, TestModelFactory.FACTORY_STRATEGY) + self.assertEqual(base.CREATE_STRATEGY, TestModelFactory._meta.strategy) class FactoryCreationTestCase(unittest.TestCase): @@ -311,7 +311,7 @@ class FactoryCreationTestCase(unittest.TestCase): class TestFactory(base.StubFactory): pass - self.assertEqual(TestFactory.FACTORY_STRATEGY, base.STUB_STRATEGY) + self.assertEqual(TestFactory._meta.strategy, base.STUB_STRATEGY) def test_inheritance_with_stub(self): class TestObjectFactory(base.StubFactory): @@ -322,7 +322,7 @@ class FactoryCreationTestCase(unittest.TestCase): class TestFactory(TestObjectFactory): pass - self.assertEqual(TestFactory.FACTORY_STRATEGY, base.STUB_STRATEGY) + self.assertEqual(TestFactory._meta.strategy, base.STUB_STRATEGY) def test_custom_creation(self): class TestModelFactory(FakeModelFactory): @@ -349,7 +349,7 @@ class FactoryCreationTestCase(unittest.TestCase): class Test(base.Factory): pass - self.assertTrue(Test._abstract_factory) + self.assertTrue(Test._meta.abstract) class PostGenerationParsingTestCase(unittest.TestCase): @@ -360,7 +360,7 @@ class PostGenerationParsingTestCase(unittest.TestCase): foo = declarations.PostGenerationDeclaration() - self.assertIn('foo', TestObjectFactory._postgen_declarations) + self.assertIn('foo', TestObjectFactory._meta.postgen_declarations) def test_classlevel_extraction(self): class TestObjectFactory(base.Factory): @@ -369,8 +369,8 @@ class PostGenerationParsingTestCase(unittest.TestCase): foo = declarations.PostGenerationDeclaration() foo__bar = 42 - self.assertIn('foo', TestObjectFactory._postgen_declarations) - self.assertIn('foo__bar', TestObjectFactory._declarations) + self.assertIn('foo', TestObjectFactory._meta.postgen_declarations) + self.assertIn('foo__bar', TestObjectFactory._meta.declarations) |