1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Deprecated load_app().

Adjusted several tests that used it to add apps to the app cache and
then attempted to remove them by manipulating attributes directly.

Also renamed invalid_models to invalid_models_tests to avoid clashing
application labels between the outer and the inner invalid_models
applications.
This commit is contained in:
Aymeric Augustin
2013-12-18 17:56:11 +01:00
parent 439b364e1e
commit f25fa9d859
10 changed files with 47 additions and 64 deletions

View File

@@ -8,6 +8,7 @@ from django.core.apps import app_cache
from django.core.apps.cache import AppCache
from django.test.utils import override_settings
from django.utils._os import upath
from django.utils import six
class EggLoadingTest(TestCase):
@@ -31,45 +32,41 @@ class EggLoadingTest(TestCase):
"""Models module can be loaded from an app in an egg"""
egg_name = '%s/modelapp.egg' % self.egg_dir
sys.path.append(egg_name)
models = app_cache.load_app('app_with_models')
self.assertFalse(models is None)
with app_cache._with_app('app_with_models'):
models_module = app_cache.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
def test_egg2(self):
"""Loading an app from an egg that has no models returns no models (and no error)"""
egg_name = '%s/nomodelapp.egg' % self.egg_dir
sys.path.append(egg_name)
models = app_cache.load_app('app_no_models')
self.assertTrue(models is None)
with app_cache._with_app('app_no_models'):
models_module = app_cache.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
def test_egg3(self):
"""Models module can be loaded from an app located under an egg's top-level package"""
egg_name = '%s/omelet.egg' % self.egg_dir
sys.path.append(egg_name)
models = app_cache.load_app('omelet.app_with_models')
self.assertFalse(models is None)
with app_cache._with_app('omelet.app_with_models'):
models_module = app_cache.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
def test_egg4(self):
"""Loading an app with no models from under the top-level egg package generates no error"""
egg_name = '%s/omelet.egg' % self.egg_dir
sys.path.append(egg_name)
models = app_cache.load_app('omelet.app_no_models')
self.assertTrue(models is None)
with app_cache._with_app('omelet.app_no_models'):
models_module = app_cache.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
def test_egg5(self):
"""Loading an app from an egg that has an import error in its models module raises that error"""
egg_name = '%s/brokenapp.egg' % self.egg_dir
sys.path.append(egg_name)
self.assertRaises(ImportError, app_cache.load_app, 'broken_app')
raised = None
try:
app_cache.load_app('broken_app')
except ImportError as e:
raised = e
# Make sure the message is indicating the actual
# problem in the broken app.
self.assertTrue(raised is not None)
self.assertTrue("modelz" in raised.args[0])
with six.assertRaisesRegex(self, ImportError, 'modelz'):
with app_cache._with_app('broken_app'):
app_cache.get_app_config('omelet.app_no_models').models_module
def test_missing_app(self):
"""