summaryrefslogtreecommitdiff
path: root/django/contrib/sitemaps/tests/https.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-01-29 19:24:32 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-01-29 19:24:32 +0000
commita4b472dd809c8a696d1488a54dcaf3870ec9e661 (patch)
tree1338453f7de1c9802a571cabf353af364559370f /django/contrib/sitemaps/tests/https.py
parent123f567093eb3bd2f9cb295f4553eb62433c2962 (diff)
Fixed #8995 -- Added support for HTTPS in sitemaps.
Modularized tests and did a bit of cleanup while I was in the area. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17409 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/sitemaps/tests/https.py')
-rw-r--r--django/contrib/sitemaps/tests/https.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/django/contrib/sitemaps/tests/https.py b/django/contrib/sitemaps/tests/https.py
new file mode 100644
index 0000000000..b590bf2215
--- /dev/null
+++ b/django/contrib/sitemaps/tests/https.py
@@ -0,0 +1,51 @@
+from datetime import date
+
+from django.test.utils import override_settings
+
+from .base import SitemapTestsBase
+
+class HTTPSSitemapTests(SitemapTestsBase):
+ protocol = 'https'
+ urls = 'django.contrib.sitemaps.tests.urls.https'
+
+ def test_secure_sitemap_index(self):
+ "A secure sitemap index can be rendered"
+ response = self.client.get('/secure/index.xml')
+ self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
+<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
+</sitemapindex>
+""" % self.base_url)
+
+ def test_secure_sitemap_section(self):
+ "A secure sitemap section can be rendered"
+ response = self.client.get('/secure/sitemap-simple.xml')
+ self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
+</urlset>
+""" % (self.base_url, date.today()))
+
+#@override_settings(SECURE_PROXY_SSL_HEADER=False)
+class HTTPSDetectionSitemapTests(SitemapTestsBase):
+ extra = {'wsgi.url_scheme': 'https'}
+
+ def test_sitemap_index_with_https_request(self):
+ "A sitemap index requested in HTTPS is rendered with HTTPS links"
+ response = self.client.get('/simple/index.xml', **self.extra)
+ self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
+<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
+</sitemapindex>
+""" % self.base_url.replace('http://', 'https://'))
+
+ def test_sitemap_section_with_https_request(self):
+ "A sitemap section requested in HTTPS is rendered with HTTPS links"
+ response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
+ self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
+</urlset>
+""" % (self.base_url.replace('http://', 'https://'), date.today()))
+
+HTTPSDetectionSitemapTests = override_settings(SECURE_PROXY_SSL_HEADER=False)(HTTPSDetectionSitemapTests)