Exemple #1
0
 def test_sitemap_get_urls_no_site_2(self):
     """
     Check we get ImproperlyConfigured when we don't pass a site object to
     Sitemap.get_urls if Site objects exists, but the sites framework is not
     actually installed.
     """
     with app_cache._without_app('django.contrib.sites'):
         self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
Exemple #2
0
 def test_no_sites_framework(self):
     """
     Without the sites framework, should not access SITE_ID or Site
     objects. Deleting settings is fine here as UserSettingsHolder is used.
     """
     with self.settings(SITE_ID=None), app_cache._without_app("django.contrib.sites"):
         Site.objects.all().delete()
         del settings.SITE_ID
         self.client.get("/admindocs/views/")  # should not raise
Exemple #3
0
    def test_requestsite_sitemap(self):
        # Make sure hitting the flatpages sitemap without the sites framework
        # installed doesn't raise an exception.
        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">
<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % date.today()
            self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
Exemple #4
0
 def test_middleware_disabled(self):
     """
     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)],
         }
         reverse('django.contrib.messages.tests.urls.show')
         for level in ('debug', 'info', 'success', 'warning', 'error'):
             add_url = reverse('django.contrib.messages.tests.urls.add',
                               args=(level,))
             self.assertRaises(MessageFailure, self.client.post, add_url,
                               data, follow=True)
Exemple #5
0
 def test_middleware_disabled_fail_silently(self):
     """
     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,
         }
         show_url = reverse('django.contrib.messages.tests.urls.show')
         for level in ('debug', 'info', 'success', 'warning', 'error'):
             add_url = reverse('django.contrib.messages.tests.urls.add',
                               args=(level,))
             response = self.client.post(add_url, data, follow=True)
             self.assertRedirects(response, show_url)
             self.assertFalse('messages' in response.context)
Exemple #6
0
    def test_get_current_site(self):
        # Test that the correct Site object is returned
        request = HttpRequest()
        request.META = {
            "SERVER_NAME": "example.com",
            "SERVER_PORT": "80",
        }
        site = get_current_site(request)
        self.assertTrue(isinstance(site, Site))
        self.assertEqual(site.id, settings.SITE_ID)

        # Test that an exception is raised if the sites framework is installed
        # but there is no matching Site
        site.delete()
        self.assertRaises(ObjectDoesNotExist, get_current_site, request)

        # A RequestSite is returned if the sites framework is not installed
        with app_cache._without_app('django.contrib.sites'):
            site = get_current_site(request)
            self.assertTrue(isinstance(site, RequestSite))
            self.assertEqual(site.name, "example.com")
Exemple #7
0
    def test_shortcut_view(self):
        """
        Check that the shortcut view (used for the admin "view on site"
        functionality) returns a complete URL regardless of whether the sites
        framework is installed
        """

        request = HttpRequest()
        request.META = {
            "SERVER_NAME": "Example.com",
            "SERVER_PORT": "80",
        }
        user_ct = ContentType.objects.get_for_model(FooWithUrl)
        obj = FooWithUrl.objects.create(name="john")

        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])

        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])
Exemple #8
0
 def test_sites_not_installed(self):
     with app_cache._without_app('django.contrib.sites'):
         with self.assertRaises(ImproperlyConfigured):
             RedirectFallbackMiddleware()