summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--factory/__init__.py2
-rw-r--r--factory/django.py3
-rw-r--r--tests/test_django.py9
3 files changed, 14 insertions, 0 deletions
diff --git a/factory/__init__.py b/factory/__init__.py
index aa550e8..ca1571a 100644
--- a/factory/__init__.py
+++ b/factory/__init__.py
@@ -32,6 +32,8 @@ from .base import (
ListFactory,
StubFactory,
+ FactoryError,
+
BUILD_STRATEGY,
CREATE_STRATEGY,
STUB_STRATEGY,
diff --git a/factory/django.py b/factory/django.py
index 6090145..2b6c463 100644
--- a/factory/django.py
+++ b/factory/django.py
@@ -101,6 +101,9 @@ class DjangoModelFactory(base.Factory):
@classmethod
def _get_manager(cls, model_class):
+ if model_class is None:
+ raise base.AssociatedClassError("No model set on %s.%s.Meta"
+ % (cls.__module__, cls.__name__))
try:
return model_class._default_manager # pylint: disable=W0212
except AttributeError:
diff --git a/tests/test_django.py b/tests/test_django.py
index 84b0933..41a26cf 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -167,6 +167,15 @@ class WithSignalsFactory(factory.django.DjangoModelFactory):
@unittest.skipIf(django is None, "Django not installed.")
+class ModelTests(django_test.TestCase):
+ def test_unset_model(self):
+ class UnsetModelFactory(factory.django.DjangoModelFactory):
+ pass
+
+ self.assertRaises(factory.FactoryError, UnsetModelFactory.create)
+
+
+@unittest.skipIf(django is None, "Django not installed.")
class DjangoPkSequenceTestCase(django_test.TestCase):
def setUp(self):
super(DjangoPkSequenceTestCase, self).setUp()