mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
8662654d6d
Since the original ones in django.db.models.loading were kept only for backwards compatibility, there's no need to recreate them. However, many internals of Django still relied on them. They were also imported in django.db.models. They never appear in the documentation, except a quick mention of get_models and get_app in the 1.2 release notes to document an edge case in GIS. I don't think that makes them a public API. This commit doesn't change the overall amount of global state but clarifies that it's tied to the app_cache object instead of hiding it behind half a dozen functions.
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from django.apps import app_cache
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
from django.test import TestCase
|
|
from django.test.utils import override_settings
|
|
from django.utils import six
|
|
|
|
from .models import Empty
|
|
|
|
|
|
class EmptyModelTests(TestCase):
|
|
def test_empty(self):
|
|
m = Empty()
|
|
self.assertEqual(m.id, None)
|
|
m.save()
|
|
Empty.objects.create()
|
|
self.assertEqual(len(Empty.objects.all()), 2)
|
|
self.assertTrue(m.id is not None)
|
|
existing = Empty(m.id)
|
|
existing.save()
|
|
|
|
|
|
class NoModelTests(TestCase):
|
|
"""
|
|
Test for #7198 to ensure that the proper error message is raised
|
|
when attempting to load an app with no models.py file.
|
|
|
|
Because the test runner won't currently load a test module with no
|
|
models.py file, this TestCase instead lives in this module.
|
|
|
|
It seemed like an appropriate home for it.
|
|
"""
|
|
@override_settings(INSTALLED_APPS=("empty.no_models",))
|
|
def test_no_models(self):
|
|
with six.assertRaisesRegex(self, ImproperlyConfigured,
|
|
'App with label no_models is missing a models.py module.'):
|
|
app_cache.get_app('no_models')
|