diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-03-26 23:04:41 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-03-26 23:04:41 +0100 |
commit | a456a9e3f440e5f61497e97d75dd0a15efe71a8d (patch) | |
tree | 43817d30fb81b64bc4fa26a331bda72e48b3d608 /tests | |
parent | 636ca46951d710a4b9d9fd61ec1da02294806d3d (diff) | |
download | factory-boy-a456a9e3f440e5f61497e97d75dd0a15efe71a8d.tar factory-boy-a456a9e3f440e5f61497e97d75dd0a15efe71a8d.tar.gz |
Remove limitations of factory.StubFactory (Closes #131).
``StubFactory.build()`` is now supported, and maps to
``StubFactory.stub()``.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_base.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/test_base.py b/tests/test_base.py index d1df58e..12031b9 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -403,7 +403,7 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): self.assertRaises(base.Factory.UnknownStrategy, TestModelFactory) - def test_stub_with_non_stub_strategy(self): + def test_stub_with_create_strategy(self): class TestModelFactory(base.StubFactory): class Meta: model = TestModel @@ -414,8 +414,18 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): self.assertRaises(base.StubFactory.UnsupportedStrategy, TestModelFactory) + def test_stub_with_build_strategy(self): + class TestModelFactory(base.StubFactory): + class Meta: + model = TestModel + + one = 'one' + TestModelFactory._meta.strategy = base.BUILD_STRATEGY - self.assertRaises(base.StubFactory.UnsupportedStrategy, TestModelFactory) + obj = TestModelFactory() + + # For stubs, build() is an alias of stub(). + self.assertFalse(isinstance(obj, TestModel)) def test_change_strategy(self): @base.use_strategy(base.CREATE_STRATEGY) @@ -454,6 +464,23 @@ class FactoryCreationTestCase(unittest.TestCase): self.assertEqual(TestFactory._meta.strategy, base.STUB_STRATEGY) + def test_stub_and_subfactory(self): + class StubA(base.StubFactory): + class Meta: + model = TestObject + + one = 'blah' + + class StubB(base.StubFactory): + class Meta: + model = TestObject + + stubbed = declarations.SubFactory(StubA, two='two') + + b = StubB() + self.assertEqual('blah', b.stubbed.one) + self.assertEqual('two', b.stubbed.two) + def test_custom_creation(self): class TestModelFactory(FakeModelFactory): class Meta: |