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

Removed the app_config.installed flag.

Since applications that aren't installed no longer have an application
configuration, it is now always True in practice.

Provided an abstraction to temporarily add or remove applications as
several tests messed with app_config.installed to achieve this effect.
For now this API is _-prefixed because it looks dangerous.
parent 972babc3
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
from __future__ import unicode_literals

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.views import shortcut
from django.contrib.sites.models import Site, get_current_site
from django.contrib.sites.models import get_current_site
from django.core.apps import app_cache
from django.db import models
from django.http import HttpRequest, Http404
from django.test import TestCase
from django.test.utils import override_settings
@@ -54,11 +55,9 @@ class FooWithBrokenAbsoluteUrl(FooWithoutUrl):
class ContentTypesTests(TestCase):

    def setUp(self):
        self._old_installed = Site._meta.app_config.installed
        ContentType.objects.clear_cache()

    def tearDown(self):
        Site._meta.app_config.installed = self._old_installed
        ContentType.objects.clear_cache()

    def test_lookup_cache(self):
@@ -223,12 +222,12 @@ class ContentTypesTests(TestCase):
        user_ct = ContentType.objects.get_for_model(FooWithUrl)
        obj = FooWithUrl.objects.create(name="john")

        Site._meta.app_config.installed = True
        with app_cache._with_app('django.contrib.sites'):
            response = shortcut(request, user_ct.id, obj.id)
            self.assertEqual("http://%s/users/john/" % get_current_site(request).domain,
                             response._headers.get("location")[1])

        Site._meta.app_config.installed = False
        with app_cache._without_app('django.contrib.sites'):
            response = shortcut(request, user_ct.id, obj.id)
            self.assertEqual("http://Example.com/users/john/",
                             response._headers.get("location")[1])
+3 −3
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.core.apps import app_cache
from django.test import TestCase

if HAS_GEOS:
@@ -20,11 +21,10 @@ class GeoFeedTest(TestCase):

    def setUp(self):
        Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
        self._old_installed = Site._meta.app_config.installed
        Site._meta.app_config.installed = True
        self._with_sites = app_cache._begin_with_app('django.contrib.sites')

    def tearDown(self):
        Site._meta.app_config.installed = self._old_installed
        app_cache._end_with_app(self._with_sites)

    def assertChildNodes(self, elem, expected):
        "Taken from syndication/tests.py."
+3 −3
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ from django.conf import settings
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.contrib.sites.models import Site
from django.core.apps import app_cache
from django.test import TestCase
from django.test.utils import IgnoreDeprecationWarningsMixin
from django.utils._os import upath
@@ -26,11 +27,10 @@ class GeoSitemapTest(IgnoreDeprecationWarningsMixin, TestCase):
    def setUp(self):
        super(GeoSitemapTest, self).setUp()
        Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
        self._old_installed = Site._meta.app_config.installed
        Site._meta.app_config.installed = True
        self._with_sites = app_cache._begin_with_app('django.contrib.sites')

    def tearDown(self):
        Site._meta.app_config.installed = self._old_installed
        app_cache._end_with_app(self._with_sites)
        super(GeoSitemapTest, self).tearDown()

    def assertChildNodes(self, elem, expected):
+0 −4
Original line number Diff line number Diff line
@@ -25,10 +25,6 @@ class SitemapTestsBase(TestCase):

    def setUp(self):
        self.base_url = '%s://%s' % (self.protocol, self.domain)
        self._old_installed = Site._meta.app_config.installed
        cache.clear()
        # Create an object for sitemap content.
        TestModel.objects.create(name='Test Object')

    def tearDown(self):
        Site._meta.app_config.installed = self._old_installed
+7 −8
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from unittest import skipUnless
from django.conf import settings
from django.contrib.sitemaps import Sitemap, GenericSitemap
from django.contrib.sites.models import Site
from django.core.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django.test.utils import override_settings
from django.utils.formats import localize
@@ -108,8 +109,7 @@ class HTTPSitemapTests(SitemapTestsBase):
    def test_requestsite_sitemap(self):
        # Make sure hitting the flatpages sitemap without the sites framework
        # installed doesn't raise an exception.
        # Reset by SitemapTestsBase.tearDown().
        Site._meta.app_config.installed = False
        with app_cache._without_app('django.contrib.sites'):
            response = self.client.get('/simple/sitemap.xml')
            expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -134,8 +134,7 @@ class HTTPSitemapTests(SitemapTestsBase):
        Sitemap.get_urls if Site objects exists, but the sites framework is not
        actually installed.
        """
        # Reset by SitemapTestsBase.tearDown().
        Site._meta.app_config.installed = False
        with app_cache._without_app('django.contrib.sites'):
            self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)

    def test_sitemap_item(self):
Loading