summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference.rst9
-rw-r--r--factory/base.py3
-rw-r--r--tests/test_using.py15
3 files changed, 26 insertions, 1 deletions
diff --git a/docs/reference.rst b/docs/reference.rst
index 6d01e5d..03023fc 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -235,6 +235,15 @@ factory_boy supports two main strategies for generating instances, plus stubs.
.. OHAI_VIM*
+ .. warning:: For backward compatibility reasons, the default behaviour of
+ factory_boy is to call ``MyClass.objects.create(*args, **kwargs)``
+ when using the ``create`` strategy.
+
+ That policy will be used if the
+ :attr:`associated class <Factory.FACTORY_FOR>` has an ``objects``
+ attribute *and* the :meth:`~Factory._create` classmethod of the
+ :class:`Factory` wasn't overridden.
+
.. function:: use_strategy(strategy)
diff --git a/factory/base.py b/factory/base.py
index 3ebc746..44d58a7 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -527,7 +527,8 @@ class Factory(BaseFactory):
creation_function = getattr(cls, '_creation_function', ())
if creation_function and creation_function[0]:
return creation_function[0]
- elif cls._create.__func__ == Factory._create.__func__:
+ elif cls._create.__func__ == Factory._create.__func__ and \
+ hasattr(cls._associated_class, 'objects'):
# Backwards compatibility.
# Default creation_function and default _create() behavior.
# The best "Vanilla" _create detection algorithm I found is relying
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