From 68b5872e8cbd33f5f59ea8d859e326eb0ff0c6eb Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Tue, 16 Apr 2013 11:20:18 +0200 Subject: Release v2.0.1 --- tests/test_using.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'tests') 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() -- cgit v1.2.3