2012-08-14 17:57:18 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2012-01-30 03:24:32 +08:00
|
|
|
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')
|
2012-08-15 02:12:38 +08:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-30 03:24:32 +08:00
|
|
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
|
|
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
|
|
|
|
</sitemapindex>
|
2012-08-15 02:12:38 +08:00
|
|
|
""" % self.base_url
|
|
|
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
2012-01-30 03:24:32 +08:00
|
|
|
|
|
|
|
def test_secure_sitemap_section(self):
|
|
|
|
"A secure sitemap section can be rendered"
|
|
|
|
response = self.client.get('/secure/sitemap-simple.xml')
|
2012-08-15 02:12:38 +08:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-30 03:24:32 +08: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-15 02:12:38 +08:00
|
|
|
""" % (self.base_url, date.today())
|
|
|
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
2012-01-30 03:24:32 +08:00
|
|
|
|
2012-03-30 17:08:29 +08:00
|
|
|
|
|
|
|
@override_settings(SECURE_PROXY_SSL_HEADER=False)
|
2012-01-30 03:24:32 +08:00
|
|
|
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)
|
2012-08-15 02:12:38 +08:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-30 03:24:32 +08:00
|
|
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
|
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
|
|
|
</sitemapindex>
|
2012-08-15 02:12:38 +08:00
|
|
|
""" % self.base_url.replace('http://', 'https://')
|
|
|
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
2012-01-30 03:24:32 +08: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-15 02:12:38 +08:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-30 03:24:32 +08: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-15 02:12:38 +08:00
|
|
|
""" % (self.base_url.replace('http://', 'https://'), date.today())
|
|
|
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|