Ticket #7835: 7835.test_extra_apps.diff
File 7835.test_extra_apps.diff, 3.0 KB (added by , 16 years ago) |
---|
-
django/django/test/testcases.py
8 8 from django.core.management import call_command 9 9 from django.core.urlresolvers import clear_url_caches 10 10 from django.db import transaction 11 from django.db.models.loading import load_app 11 12 from django.http import QueryDict 12 13 from django.test import _doctest as doctest 13 14 from django.test.client import Client … … 173 174 def _pre_setup(self): 174 175 """Performs any pre-test setup. This includes: 175 176 177 * If the Test Case class has a 'installed_apps' member, replace the 178 INSTALLED_APPS with it. 179 * If the Test Case class has a 'extra_apps' member, append it to 180 INSTALLED_APPS. 176 181 * Flushing the database. 177 182 * If the Test Case class has a 'fixtures' member, installing the 178 183 named fixtures. … … 180 185 ROOT_URLCONF with it. 181 186 * Clearing the mail test outbox. 182 187 """ 188 if hasattr(self, 'installed_apps'): 189 self._old_installed_apps = settings.INSTALLED_APPS 190 settings.INSTALLED_APPS = list(self.installed_apps) 191 if hasattr(self, 'extra_apps'): 192 if hasattr(self, '_old_installed_apps'): 193 # extra_apps and installed_apps can coexist 194 settings.INSTALLED_APPS += list(self.extra_apps) 195 else: 196 self._old_installed_apps = settings.INSTALLED_APPS 197 settings.INSTALLED_APPS += list(self.extra_apps) 198 if hasattr(self, '_old_installed_apps'): 199 for app_label in settings.INSTALLED_APPS: 200 load_app(app_label) 201 # Create the new tables in db 202 call_command('syncdb', verbosity=0, interactive=False) 183 203 call_command('flush', verbosity=0, interactive=False) 184 204 if hasattr(self, 'fixtures'): 185 205 # We have to use this slightly awkward syntax due to the fact … … 220 240 """ Performs any post-test things. This includes: 221 241 222 242 * Putting back the original ROOT_URLCONF if it was changed. 243 * Putting back the original INSTALLED_APPS if it was changed. 223 244 """ 224 245 if hasattr(self, '_old_root_urlconf'): 225 246 settings.ROOT_URLCONF = self._old_root_urlconf … … 224 245 if hasattr(self, '_old_root_urlconf'): 225 246 settings.ROOT_URLCONF = self._old_root_urlconf 226 247 clear_url_caches() 248 if hasattr(self, '_old_installed_apps'): 249 settings.INSTALLED_APPS = self._old_installed_apps 250 #TODO: test apps should be unloaded from the app cache, and the extra tables destroyed. 227 251 228 252 def assertRedirects(self, response, expected_url, status_code=302, 229 253 target_status_code=200, host=None):