summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-19 22:33:46 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-22 11:39:18 +0100
commit2239081ff16aab1eaafea003433f7139bf13e097 (patch)
tree373ddb3cf271c77d8baf0e4fd22fcc9f0d5f4d92
parent9cdf1f6d547b6dffcee26f0a525429452551bb4a (diff)
Expurged INSTALLED_APPS from code and tests.
Except the app cache code and a few specific tests, of course.
-rw-r--r--django/contrib/admin/sites.py16
-rw-r--r--tests/migrations/test_writer.py15
-rw-r--r--tests/proxy_model_inheritance/tests.py18
-rw-r--r--tests/staticfiles_tests/tests.py6
-rw-r--r--tests/utils_tests/test_autoreload.py13
5 files changed, 33 insertions, 35 deletions
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 7b633bef89..a4caa863eb 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -6,6 +6,7 @@ from django.contrib.auth import logout as auth_logout, REDIRECT_FIELD_NAME
from django.contrib.contenttypes import views as contenttype_views
from django.views.decorators.csrf import csrf_protect
from django.db.models.base import ModelBase
+from django.core.apps import app_cache
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.core.urlresolvers import reverse, NoReverseMatch
from django.template.response import TemplateResponse
@@ -156,20 +157,17 @@ class AdminSite(object):
"""
Check that all things needed to run the admin have been correctly installed.
- The default implementation checks that LogEntry, ContentType and the
- auth context processor are installed.
+ The default implementation checks that admin and contenttypes apps are
+ installed, as well as the auth context processor.
"""
- from django.contrib.admin.models import LogEntry
- from django.contrib.contenttypes.models import ContentType
-
- if not LogEntry._meta.installed:
+ app_cache.populate_apps()
+ if not app_cache.has_app('django.contrib.admin'):
raise ImproperlyConfigured("Put 'django.contrib.admin' in your "
"INSTALLED_APPS setting in order to use the admin application.")
- if not ContentType._meta.installed:
+ if not app_cache.has_app('django.contrib.contenttypes'):
raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in "
"your INSTALLED_APPS setting in order to use the admin application.")
- if not ('django.contrib.auth.context_processors.auth' in settings.TEMPLATE_CONTEXT_PROCESSORS or
- 'django.core.context_processors.auth' in settings.TEMPLATE_CONTEXT_PROCESSORS):
+ if 'django.contrib.auth.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS:
raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' "
"in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.")
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index f921f9f03c..3f46703207 100644
--- a/tests/migrations/test_writer.py
+++ b/tests/migrations/test_writer.py
@@ -9,7 +9,7 @@ from django.core.apps import app_cache
from django.core.validators import RegexValidator, EmailValidator
from django.db import models, migrations
from django.db.migrations.writer import MigrationWriter
-from django.test import TestCase, override_settings
+from django.test import TestCase
from django.utils import six
from django.utils.deconstruct import deconstructible
from django.utils.translation import ugettext_lazy as _
@@ -122,10 +122,9 @@ class WriterTests(TestCase):
base_dir = os.path.dirname(os.path.dirname(__file__))
- with override_settings(INSTALLED_APPS=test_apps):
- for app in test_apps:
- with app_cache._with_app(app):
- migration = migrations.Migration('0001_initial', app.split('.')[-1])
- expected_path = os.path.join(base_dir, *(app.split('.') + ['migrations', '0001_initial.py']))
- writer = MigrationWriter(migration)
- self.assertEqual(writer.path, expected_path)
+ for app in test_apps:
+ with app_cache._with_app(app):
+ migration = migrations.Migration('0001_initial', app.split('.')[-1])
+ expected_path = os.path.join(base_dir, *(app.split('.') + ['migrations', '0001_initial.py']))
+ writer = MigrationWriter(migration)
+ self.assertEqual(writer.path, expected_path)
diff --git a/tests/proxy_model_inheritance/tests.py b/tests/proxy_model_inheritance/tests.py
index 01a2ddfef6..91fcbbcc09 100644
--- a/tests/proxy_model_inheritance/tests.py
+++ b/tests/proxy_model_inheritance/tests.py
@@ -13,7 +13,8 @@ from .models import (ConcreteModel, ConcreteModelSubclass,
ConcreteModelSubclassProxy)
-@override_settings(INSTALLED_APPS=('app1', 'app2'))
+# Required for available_apps.
+@override_settings(INSTALLED_APPS=['app1', 'app2'])
class ProxyModelInheritanceTests(TransactionTestCase):
"""
Proxy model inheritance across apps can result in migrate not creating the table
@@ -25,20 +26,17 @@ class ProxyModelInheritanceTests(TransactionTestCase):
def setUp(self):
self.old_sys_path = sys.path[:]
sys.path.append(os.path.dirname(os.path.abspath(upath(__file__))))
- self._with_app1 = app_cache._begin_with_app('app1')
- self._with_app2 = app_cache._begin_with_app('app2')
def tearDown(self):
- app_cache._end_with_app(self._with_app1)
- app_cache._end_with_app(self._with_app2)
sys.path = self.old_sys_path
def test_table_exists(self):
- call_command('migrate', verbosity=0)
- from .app1.models import ProxyModel
- from .app2.models import NiceModel
- self.assertEqual(NiceModel.objects.all().count(), 0)
- self.assertEqual(ProxyModel.objects.all().count(), 0)
+ with app_cache._with_app('app1'), app_cache._with_app('app2'):
+ call_command('migrate', verbosity=0)
+ from .app1.models import ProxyModel
+ from .app2.models import NiceModel
+ self.assertEqual(NiceModel.objects.all().count(), 0)
+ self.assertEqual(ProxyModel.objects.all().count(), 0)
class MultiTableInheritanceProxyTest(TestCase):
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
index f5d871587c..3ad8249e76 100644
--- a/tests/staticfiles_tests/tests.py
+++ b/tests/staticfiles_tests/tests.py
@@ -298,7 +298,7 @@ class TestCollectionDryRun(CollectionTestCase, TestNoFilesCreated):
class TestCollectionFilesOverride(CollectionTestCase):
"""
Test overriding duplicated files by ``collectstatic`` management command.
- Check for proper handling of apps order in INSTALLED_APPS even if file modification
+ Check for proper handling of apps order in installed apps even if file modification
dates are in different order:
'staticfiles_tests.apps.test',
@@ -314,7 +314,7 @@ class TestCollectionFilesOverride(CollectionTestCase):
# prepare duplicate of file2.txt from no_label app
# this file will have modification time older than no_label/static/file2.txt
# anyway it should be taken to STATIC_ROOT because 'test' app is before
- # 'no_label' app in INSTALLED_APPS
+ # 'no_label' app in installed apps
self.testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt')
with open(self.testfile_path, 'w+') as f:
f.write('duplicate of file2.txt')
@@ -340,7 +340,7 @@ class TestCollectionFilesOverride(CollectionTestCase):
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
# and now change modification time of no_label/static/file2.txt
- # test app is first in INSTALLED_APPS so file2.txt should remain unmodified
+ # test app is first in installed apps so file2.txt should remain unmodified
mtime = os.path.getmtime(self.testfile_path)
atime = os.path.getatime(self.testfile_path)
os.utime(self.orig_path, (mtime + 1, atime + 1))
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index d6e22ad8ee..47c70fae92 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -2,6 +2,7 @@ import os
from django import conf
from django.contrib import admin
+from django.core.apps import app_cache
from django.test import TestCase, override_settings
from django.utils.autoreload import gen_filenames
@@ -27,7 +28,6 @@ class TestFilenameGenerator(TestCase):
self.assertIn(os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
filenames)
- @override_settings(INSTALLED_APPS=())
def test_project_root_locale(self):
"""
Test that gen_filenames also yields from the current directory (project
@@ -36,19 +36,22 @@ class TestFilenameGenerator(TestCase):
old_cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
try:
- filenames = list(gen_filenames())
+ # Remove the current app from the app cache to guarantee that the
+ # files will be found thanks to the current working directory.
+ with app_cache._empty():
+ filenames = list(gen_filenames())
self.assertIn(
os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
filenames)
finally:
os.chdir(old_cwd)
- @override_settings(INSTALLED_APPS=('django.contrib.admin',))
def test_app_locales(self):
"""
- Test that gen_filenames also yields from INSTALLED_APPS locales.
+ Test that gen_filenames also yields from locale dirs in installed apps.
"""
- filenames = list(gen_filenames())
+ with app_cache._empty(), app_cache._with_app('django.contrib.admin'):
+ filenames = list(gen_filenames())
self.assertIn(os.path.join(os.path.dirname(admin.__file__), 'locale',
'nl', 'LC_MESSAGES', 'django.mo'),
filenames)