Commit 9cdf1f6d authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Stop testing for inclusion in INSTALLED_APPS.

Removed some exception masking in the comments app that was harmful and
couldn't be preserved easily.
parent 70c9654d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
from django.conf import settings
from django.core.apps import app_cache
from django.template import Library

register = Library()

if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
if app_cache.has_app('django.contrib.staticfiles'):
    from django.contrib.staticfiles.templatetags.staticfiles import static
else:
    from django.templatetags.static import static
+6 −13
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ from importlib import import_module
import warnings
from django.conf import settings
from django.core import urlresolvers
from django.core.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django.contrib.comments.models import Comment
from django.contrib.comments.forms import CommentForm
@@ -14,20 +15,12 @@ def get_comment_app():
    """
    Get the comment app (i.e. "django.contrib.comments") as defined in the settings
    """
    # Make sure the app's in INSTALLED_APPS
    comments_app = get_comment_app_name()
    if comments_app not in settings.INSTALLED_APPS:
        raise ImproperlyConfigured("The COMMENTS_APP (%r) "\
                                   "must be in INSTALLED_APPS" % settings.COMMENTS_APP)

    # Try to import the package
    try:
        package = import_module(comments_app)
    except ImportError as e:
        raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
                                   "a non-existing package. (%s)" % e)

    return package
        app_config = app_cache.get_app_config(get_comment_app_name().rpartition(".")[2])
    except LookupError:
        raise ImproperlyConfigured("The COMMENTS_APP (%r) "
                                   "must be in INSTALLED_APPS" % settings.COMMENTS_APP)
    return app_config.app_module

def get_comment_app_name():
    """
+26 −27
Original line number Diff line number Diff line
from unittest import skipIf
from unittest import skipUnless

from django import http
from django.conf import settings, global_settings
@@ -7,14 +7,15 @@ from django.contrib.messages.api import MessageFailure
from django.contrib.messages.constants import DEFAULT_LEVELS
from django.contrib.messages.storage import default_storage, base
from django.contrib.messages.storage.base import Message
from django.core.apps import app_cache
from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from django.utils.translation import ugettext_lazy


def skipUnlessAuthIsInstalled(func):
    return skipIf(
        'django.contrib.auth' not in settings.INSTALLED_APPS,
    return skipUnless(
        app_cache.has_app('django.contrib.auth'),
        "django.contrib.auth isn't installed")(func)


@@ -219,8 +220,6 @@ class BaseTests(object):
            self.assertContains(response, msg)

    @override_settings(
        INSTALLED_APPS=filter(
            lambda app: app != 'django.contrib.messages', settings.INSTALLED_APPS),
        MIDDLEWARE_CLASSES=filter(
            lambda m: 'MessageMiddleware' not in m, settings.MIDDLEWARE_CLASSES),
        TEMPLATE_CONTEXT_PROCESSORS=filter(
@@ -233,6 +232,7 @@ class BaseTests(object):
        Tests that, when the middleware is disabled, an exception is raised
        when one attempts to store a message.
        """
        with app_cache._without_app('django.contrib.messages'):
            data = {
                'messages': ['Test message %d' % x for x in range(5)],
            }
@@ -244,8 +244,6 @@ class BaseTests(object):
                                  data, follow=True)

    @override_settings(
        INSTALLED_APPS=filter(
            lambda app: app != 'django.contrib.messages', settings.INSTALLED_APPS),
        MIDDLEWARE_CLASSES=filter(
            lambda m: 'MessageMiddleware' not in m, settings.MIDDLEWARE_CLASSES),
        TEMPLATE_CONTEXT_PROCESSORS=filter(
@@ -258,6 +256,7 @@ class BaseTests(object):
        Tests that, when the middleware is disabled, an exception is not
        raised if 'fail_silently' = True
        """
        with app_cache._without_app('django.contrib.messages'):
            data = {
                'messages': ['Test message %d' % x for x in range(5)],
                'fail_silently': True,
+2 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.conf import settings
from django.contrib.redirects.models import Redirect
from django.contrib.sites.models import get_current_site
from django.core.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django import http

@@ -14,7 +15,7 @@ class RedirectFallbackMiddleware(object):
    response_redirect_class = http.HttpResponsePermanentRedirect

    def __init__(self):
        if 'django.contrib.sites' not in settings.INSTALLED_APPS:
        if not app_cache.has_app('django.contrib.sites'):
            raise ImproperlyConfigured(
                "You cannot use RedirectFallbackMiddleware when "
                "django.contrib.sites is not installed."
+4 −5
Original line number Diff line number Diff line
from django import http
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.utils import override_settings
@@ -56,10 +57,8 @@ class RedirectTests(TestCase):
        response = self.client.get('/initial')
        self.assertEqual(response.status_code, 410)

    @override_settings(
        INSTALLED_APPS=[app for app in settings.INSTALLED_APPS
                        if app != 'django.contrib.sites'])
    def test_sites_not_installed(self):
        with app_cache._without_app('django.contrib.sites'):
            with self.assertRaises(ImproperlyConfigured):
                RedirectFallbackMiddleware()

Loading