From 114ac649e448e97a210cf8dccc6ba50278645ce6 Mon Sep 17 00:00:00 2001 From: Raphaël Barrois Date: Tue, 5 Mar 2013 23:12:10 +0100 Subject: Stop calling Foo.objects.create() when it doesn't break (Closes #23). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be properly fixed in v2.0.0; the current heuristic is: - If the user defined a custom _create method, use it - If he didn't, but the associated class has a objects attribute, use TheClass.objects.create(*args, **kwargs) - Otherwise, simply call TheClass(*args, **kwargs). Signed-off-by: Raphaël Barrois --- tests/test_using.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/test_using.py b/tests/test_using.py index 9bc466e..8f43813 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -314,6 +314,21 @@ class UsingFactoryTestCase(unittest.TestCase): self.assertEqual(1, obj.id) self.assertTrue(obj.properly_created) + def test_non_django_create(self): + class NonDjango(object): + def __init__(self, x, y=2): + self.x = x + self.y = y + + class NonDjangoFactory(factory.Factory): + FACTORY_FOR = NonDjango + + x = 3 + + obj = NonDjangoFactory.create() + self.assertEqual(3, obj.x) + self.assertEqual(2, obj.y) + def test_sequence_batch(self): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject -- cgit v1.2.3