1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

[1.8.x] Fixed #24287 -- Added friendly error if a model is in a models.py outside an installed app.

This commit is contained in:
jMyles
2015-02-05 16:50:31 -05:00
committed by Tim Graham
parent 64a9540829
commit ac576e9f45
2 changed files with 50 additions and 11 deletions

View File

@@ -1,8 +1,11 @@
from __future__ import unicode_literals
import os
import sys
from django.apps import apps
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.test import TestCase
from django.test.utils import extend_sys_path
from django.utils._os import upath
@@ -75,3 +78,26 @@ class GetModelsTest(TestCase):
self.assertNotIn(
"NotInstalledModel",
[m.__name__ for m in apps.get_models()])
def test_exception_raised_if_model_declared_outside_app(self):
class FakeModule(models.Model):
__name__ = str("models_that_do_not_live_in_an_app")
sys.modules['models_not_in_app'] = FakeModule
def declare_model_outside_app():
models.base.ModelBase.__new__(
models.base.ModelBase,
str('Outsider'),
(models.Model,),
{'__module__': 'models_not_in_app'})
msg = (
'Unable to detect the app label for model "Outsider." '
'Ensure that its module, "models_that_do_not_live_in_an_app", '
'is located inside an installed app.'
)
with self.assertRaisesMessage(ImproperlyConfigured, msg):
declare_model_outside_app()