From f25fa9d8590c7759c1ec7ffecf1d67be81237674 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Wed, 18 Dec 2013 17:56:11 +0100 Subject: 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. --- tests/app_loading/tests.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'tests/app_loading') diff --git a/tests/app_loading/tests.py b/tests/app_loading/tests.py index 45f6cd6c31..bb71ad84a2 100644 --- a/tests/app_loading/tests.py +++ b/tests/app_loading/tests.py @@ -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): """ -- cgit v1.3