diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-06-21 13:32:04 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-06-21 13:32:04 +0200 |
commit | d9b49c72395a82d356fc2704c9a66047f20fe983 (patch) | |
tree | bf5fdeccb1ce89008ea692d70cc01037d4b06c3b | |
parent | ad056787937844809b48dd36311dac0f8bd4c0ab (diff) | |
download | factory-boy-d9b49c72395a82d356fc2704c9a66047f20fe983.tar factory-boy-d9b49c72395a82d356fc2704c9a66047f20fe983.tar.gz |
Provide readable errors when Meta.model isn't set (Closes #137).
-rw-r--r-- | factory/__init__.py | 2 | ||||
-rw-r--r-- | factory/django.py | 3 | ||||
-rw-r--r-- | tests/test_django.py | 9 |
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() |