Dropped AppCache._empty, _with_app and _without_app.

It's now easier to achieve the same effect with modify_settings or
override_settings.
This commit is contained in:
Aymeric Augustin 2013-12-23 10:37:34 +01:00
parent 5241763c81
commit da16bb30ff
21 changed files with 121 additions and 228 deletions

View file

@ -2,9 +2,9 @@ from __future__ import unicode_literals
import os
import sys
from unittest import TestCase
from django.apps import app_cache
from django.test import TestCase
from django.utils._os import upath
from django.utils import six
@ -17,10 +17,9 @@ class EggLoadingTest(TestCase):
# The models need to be removed after the test in order to prevent bad
# interactions with the flush operation in other tests.
self._old_models = app_cache.app_configs['app_loading'].models.copy()
self._old_models = app_cache.all_models['app_loading'].copy()
def tearDown(self):
app_cache.app_configs['app_loading'].models = self._old_models
app_cache.all_models['app_loading'] = self._old_models
app_cache._get_models_cache = {}
@ -30,7 +29,7 @@ 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)
with app_cache._with_app('app_with_models'):
with self.settings(INSTALLED_APPS=['app_with_models']):
models_module = app_cache.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
@ -38,7 +37,7 @@ class EggLoadingTest(TestCase):
"""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)
with app_cache._with_app('app_no_models'):
with self.settings(INSTALLED_APPS=['app_no_models']):
models_module = app_cache.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
@ -46,7 +45,7 @@ class EggLoadingTest(TestCase):
"""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)
with app_cache._with_app('omelet.app_with_models'):
with self.settings(INSTALLED_APPS=['omelet.app_with_models']):
models_module = app_cache.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
@ -54,7 +53,7 @@ class EggLoadingTest(TestCase):
"""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)
with app_cache._with_app('omelet.app_no_models'):
with self.settings(INSTALLED_APPS=['omelet.app_no_models']):
models_module = app_cache.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
@ -63,8 +62,8 @@ class EggLoadingTest(TestCase):
egg_name = '%s/brokenapp.egg' % self.egg_dir
sys.path.append(egg_name)
with six.assertRaisesRegex(self, ImportError, 'modelz'):
with app_cache._with_app('broken_app'):
app_cache.get_app_config('omelet.app_no_models').models_module
with self.settings(INSTALLED_APPS=['broken_app']):
pass
class GetModelsTest(TestCase):