diff options
author | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2013-04-16 11:20:18 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2013-04-16 11:20:18 +0200 |
commit | 68b5872e8cbd33f5f59ea8d859e326eb0ff0c6eb (patch) | |
tree | dd78a618459ce74ef076d4179e2b8a6b8955520f /tests | |
parent | 9e17f7ef95f7951d7373d9f0f197dd21ac077725 (diff) | |
download | factory-boy-68b5872e8cbd33f5f59ea8d859e326eb0ff0c6eb.tar factory-boy-68b5872e8cbd33f5f59ea8d859e326eb0ff0c6eb.tar.gz |
Release v2.0.1v2.0.1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_using.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/test_using.py b/tests/test_using.py index 9e9e6aa..d366c8c 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -50,9 +50,11 @@ class FakeModel(object): class FakeModelManager(object): def get_or_create(self, **kwargs): - kwargs.update(kwargs.pop('defaults', {})) + defaults = kwargs.pop('defaults', {}) + kwargs.update(defaults) instance = FakeModel.create(**kwargs) instance.id = 2 + instance._defaults = defaults return instance, True def values_list(self, *args, **kwargs): @@ -1778,6 +1780,35 @@ class DjangoModelFactoryTestCase(unittest.TestCase): self.assertEqual('foo_4', o3.a) self.assertEqual('foo_5', o4.a) + def test_no_get_or_create(self): + class TestModelFactory(factory.DjangoModelFactory): + FACTORY_FOR = TestModel + + a = factory.Sequence(lambda n: 'foo_%s' % n) + + o = TestModelFactory() + self.assertEqual({}, o._defaults) + self.assertEqual('foo_2', o.a) + self.assertEqual(2, o.id) + + def test_get_or_create(self): + class TestModelFactory(factory.DjangoModelFactory): + FACTORY_FOR = TestModel + FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b') + + a = factory.Sequence(lambda n: 'foo_%s' % n) + b = 2 + c = 3 + d = 4 + + o = TestModelFactory() + self.assertEqual({'c': 3, 'd': 4}, o._defaults) + self.assertEqual('foo_2', o.a) + self.assertEqual(2, o.b) + self.assertEqual(3, o.c) + self.assertEqual(4, o.d) + self.assertEqual(2, o.id) + if __name__ == '__main__': unittest.main() |