diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-05 23:12:10 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-05 23:12:10 +0100 |
commit | 114ac649e448e97a210cf8dccc6ba50278645ce6 (patch) | |
tree | 705da01544a66d5602624d4d3813ac7ffef45382 /tests | |
parent | d01f5e6c041395bc579f58e12e7034a08afe3f14 (diff) | |
download | factory-boy-114ac649e448e97a210cf8dccc6ba50278645ce6.tar factory-boy-114ac649e448e97a210cf8dccc6ba50278645ce6.tar.gz |
Stop calling Foo.objects.create() when it doesn't break (Closes #23).
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 <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_using.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 |