2012-08-14 11:57:18 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2012-01-29 20:24:32 +01:00
|
|
|
from datetime import date
|
|
|
|
|
2014-12-21 21:19:05 +01:00
|
|
|
from django.test import ignore_warnings, override_settings
|
2015-06-22 19:54:35 +02:00
|
|
|
from django.utils.deprecation import RemovedInDjango110Warning
|
2012-01-29 20:24:32 +01:00
|
|
|
|
|
|
|
from .base import SitemapTestsBase
|
|
|
|
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2015-02-10 14:11:25 +01:00
|
|
|
@override_settings(ROOT_URLCONF='sitemaps_tests.urls.https')
|
2012-01-29 20:24:32 +01:00
|
|
|
class HTTPSSitemapTests(SitemapTestsBase):
|
|
|
|
protocol = 'https'
|
|
|
|
|
2015-06-22 19:54:35 +02:00
|
|
|
@ignore_warnings(category=RemovedInDjango110Warning)
|
2012-01-29 20:24:32 +01:00
|
|
|
def test_secure_sitemap_index(self):
|
|
|
|
"A secure sitemap index can be rendered"
|
2014-12-21 21:19:05 +01:00
|
|
|
# The URL for views.sitemap in tests/urls/https.py has been updated
|
|
|
|
# with a name but since reversing by Python path is tried first
|
|
|
|
# before reversing by name and works since we're giving
|
|
|
|
# name='django.contrib.sitemaps.views.sitemap', we need to silence
|
|
|
|
# the erroneous warning until reversing by dotted path is removed.
|
|
|
|
# The test will work without modification when it's removed.
|
|
|
|
response = self.client.get('/secure/index.xml')
|
2012-08-14 20:12:38 +02:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-29 20:24:32 +01:00
|
|
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
|
|
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
|
|
|
|
</sitemapindex>
|
2012-08-14 20:12:38 +02:00
|
|
|
""" % self.base_url
|
2012-10-15 22:33:16 +02:00
|
|
|
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
|
2012-01-29 20:24:32 +01:00
|
|
|
|
|
|
|
def test_secure_sitemap_section(self):
|
|
|
|
"A secure sitemap section can be rendered"
|
|
|
|
response = self.client.get('/secure/sitemap-simple.xml')
|
2012-08-14 20:12:38 +02:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-29 20:24:32 +01:00
|
|
|
<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>
|
2012-08-14 20:12:38 +02:00
|
|
|
""" % (self.base_url, date.today())
|
2012-10-15 22:33:16 +02:00
|
|
|
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
|
2012-01-29 20:24:32 +01:00
|
|
|
|
2012-03-30 11:08:29 +02:00
|
|
|
|
|
|
|
@override_settings(SECURE_PROXY_SSL_HEADER=False)
|
2012-01-29 20:24:32 +01:00
|
|
|
class HTTPSDetectionSitemapTests(SitemapTestsBase):
|
|
|
|
extra = {'wsgi.url_scheme': 'https'}
|
|
|
|
|
2015-06-22 19:54:35 +02:00
|
|
|
@ignore_warnings(category=RemovedInDjango110Warning)
|
2012-01-29 20:24:32 +01:00
|
|
|
def test_sitemap_index_with_https_request(self):
|
|
|
|
"A sitemap index requested in HTTPS is rendered with HTTPS links"
|
2014-12-21 21:19:05 +01:00
|
|
|
# The URL for views.sitemap in tests/urls/https.py has been updated
|
|
|
|
# with a name but since reversing by Python path is tried first
|
|
|
|
# before reversing by name and works since we're giving
|
|
|
|
# name='django.contrib.sitemaps.views.sitemap', we need to silence
|
|
|
|
# the erroneous warning until reversing by dotted path is removed.
|
|
|
|
# The test will work without modification when it's removed.
|
|
|
|
response = self.client.get('/simple/index.xml', **self.extra)
|
2012-08-14 20:12:38 +02:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-29 20:24:32 +01:00
|
|
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
|
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
|
|
|
</sitemapindex>
|
2012-08-14 20:12:38 +02:00
|
|
|
""" % self.base_url.replace('http://', 'https://')
|
2012-10-15 22:33:16 +02:00
|
|
|
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
|
2012-01-29 20:24:32 +01:00
|
|
|
|
|
|
|
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)
|
2012-08-14 20:12:38 +02:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-29 20:24:32 +01:00
|
|
|
<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>
|
2012-08-14 20:12:38 +02:00
|
|
|
""" % (self.base_url.replace('http://', 'https://'), date.today())
|
2012-10-15 22:33:16 +02:00
|
|
|
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
|