summaryrefslogtreecommitdiff
path: root/django/test/utils.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-23 00:10:53 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-23 20:15:08 +0100
commit5891990b6e6f6e90a873ceb199b321177a90c9eb (patch)
tree437f9c221dd28d888913e1d55dabc66a2a9d68a5 /django/test/utils.py
parent8cff95e937a3a10e577082bfbcd75ed82ec0223b (diff)
downloaddjango-5891990b6e6f6e90a873ceb199b321177a90c9eb.tar.gz
Refactored INSTALLED_APPS overrides.
* Introduced [un]set_installed_apps to handle changes to the INSTALLED_APPS setting. * Refactored [un]set_available_apps to share its implementation with [un]set_installed_apps. * Implemented a receiver to clear some app-related caches. * Removed test_missing_app as it is basically impossible to reproduce this situation with public methods of the new app cache.
Diffstat (limited to 'django/test/utils.py')
-rw-r--r--django/test/utils.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index 550d7642b9..ce7536bd6d 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -9,6 +9,7 @@ import warnings
from functools import wraps
from xml.dom.minidom import parseString, Node
+from django.apps import app_cache
from django.conf import settings, UserSettingsHolder
from django.core import mail
from django.core.signals import request_started
@@ -190,6 +191,8 @@ class override_settings(object):
"""
def __init__(self, **kwargs):
self.options = kwargs
+ # Special case that requires updating the app cache, a core feature.
+ self.installed_apps = self.options.get('INSTALLED_APPS')
def __enter__(self):
self.enable()
@@ -223,6 +226,8 @@ class override_settings(object):
setattr(override, key, new_value)
self.wrapped = settings._wrapped
settings._wrapped = override
+ if self.installed_apps is not None:
+ app_cache.set_installed_apps(self.installed_apps)
for key, new_value in self.options.items():
setting_changed.send(sender=settings._wrapped.__class__,
setting=key, value=new_value, enter=True)
@@ -230,6 +235,8 @@ class override_settings(object):
def disable(self):
settings._wrapped = self.wrapped
del self.wrapped
+ if self.installed_apps is not None:
+ app_cache.unset_installed_apps()
for key in self.options:
new_value = getattr(settings, key, None)
setting_changed.send(sender=settings._wrapped.__class__,