1
0
mirror of https://github.com/django/django.git synced 2025-04-12 03:22:21 +00:00
django/tests/empty/tests.py
Aymeric Augustin a4cb140004 Added get_app_config() to look up app configs by label.
Refactored get_app() to rely on that method.

get_app() starts by calling _populate(), which goes through
INSTALLED_APPS and, for each app, imports the app module and attempts to
import the models module. At this point, no further imports are
necessary to return the models module for a  given app. Therefore, the
implementation of get_app() can be simplified and the safeguards for
race conditions can be removed.

Besides, the emptyOK parameter isn't used anywhere in Django. It was
introduced in d6c95e93 but not actually used nor documented, and it has
just been carried around since then. Since it's an obscure private API,
it's acceptable to stop supporting it without a deprecation path. This
branch aims at providing first-class support for applications without a
models module eventually.

For backwards-compatibility, get_app() still raises ImproperlyConfigured
when an app isn't found, even though LookupError is technically more
correct. I haven't gone as far as to preserve the exact error messages.
I've adjusted a few tests instead.
2013-12-17 10:17:44 +01:00

37 lines
1.1 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,
"No app with label 'no_models'."):
app_cache.get_app('no_models')