diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-18 17:56:11 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-22 11:39:17 +0100 |
| commit | f25fa9d8590c7759c1ec7ffecf1d67be81237674 (patch) | |
| tree | c0a4a40a5371ad8e0d1c1af8c04295e874170041 /tests/app_loading | |
| parent | 439b364e1e81371bd87488beed35ce051be8aaaa (diff) | |
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.
Diffstat (limited to 'tests/app_loading')
| -rw-r--r-- | tests/app_loading/tests.py | 35 |
1 files changed, 16 insertions, 19 deletions
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): """ |
