2012-01-29 19:24:32 +00:00
|
|
|
from datetime import date
|
|
|
|
|
2015-08-17 17:45:07 +00:00
|
|
|
from django.test import override_settings
|
2012-01-29 19:24:32 +00:00
|
|
|
|
|
|
|
from .base import SitemapTestsBase
|
|
|
|
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.https")
|
2012-01-29 19:24:32 +00:00
|
|
|
class HTTPSSitemapTests(SitemapTestsBase):
|
2022-02-03 19:24:19 +00:00
|
|
|
protocol = "https"
|
2012-01-29 19:24:32 +00:00
|
|
|
|
|
|
|
def test_secure_sitemap_index(self):
|
|
|
|
"A secure sitemap index can be rendered"
|
2022-02-03 19:24:19 +00:00
|
|
|
response = self.client.get("/secure/index.xml")
|
2012-08-14 18:12:38 +00:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-29 19:24:32 +00:00
|
|
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
2020-12-30 16:44:53 +00:00
|
|
|
<sitemap><loc>%s/secure/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
|
2012-01-29 19:24:32 +00:00
|
|
|
</sitemapindex>
|
2022-02-03 19:24:19 +00:00
|
|
|
""" % (
|
|
|
|
self.base_url,
|
|
|
|
date.today(),
|
|
|
|
)
|
2017-02-07 17:05:47 +00:00
|
|
|
self.assertXMLEqual(response.content.decode(), expected_content)
|
2012-01-29 19:24:32 +00:00
|
|
|
|
|
|
|
def test_secure_sitemap_section(self):
|
|
|
|
"A secure sitemap section can be rendered"
|
2022-02-03 19:24:19 +00:00
|
|
|
response = self.client.get("/secure/sitemap-simple.xml")
|
2022-02-04 07:08:27 +00:00
|
|
|
expected_content = (
|
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
|
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" '
|
|
|
|
'xmlns:xhtml="http://www.w3.org/1999/xhtml">\n'
|
|
|
|
"<url><loc>%s/location/</loc><lastmod>%s</lastmod>"
|
|
|
|
"<changefreq>never</changefreq><priority>0.5</priority></url>\n"
|
|
|
|
"</urlset>"
|
|
|
|
) % (
|
2022-02-03 19:24:19 +00:00
|
|
|
self.base_url,
|
|
|
|
date.today(),
|
|
|
|
)
|
2017-02-07 17:05:47 +00:00
|
|
|
self.assertXMLEqual(response.content.decode(), expected_content)
|
2012-01-29 19:24:32 +00:00
|
|
|
|
2012-03-30 09:08:29 +00:00
|
|
|
|
|
|
|
@override_settings(SECURE_PROXY_SSL_HEADER=False)
|
2012-01-29 19:24:32 +00:00
|
|
|
class HTTPSDetectionSitemapTests(SitemapTestsBase):
|
2022-02-03 19:24:19 +00:00
|
|
|
extra = {"wsgi.url_scheme": "https"}
|
2012-01-29 19:24:32 +00:00
|
|
|
|
|
|
|
def test_sitemap_index_with_https_request(self):
|
|
|
|
"A sitemap index requested in HTTPS is rendered with HTTPS links"
|
2022-02-03 19:24:19 +00:00
|
|
|
response = self.client.get("/simple/index.xml", **self.extra)
|
2012-08-14 18:12:38 +00:00
|
|
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
2012-01-29 19:24:32 +00:00
|
|
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
2020-12-30 16:44:53 +00:00
|
|
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
|
2012-01-29 19:24:32 +00:00
|
|
|
</sitemapindex>
|
2022-02-03 19:24:19 +00:00
|
|
|
""" % (
|
|
|
|
self.base_url.replace("http://", "https://"),
|
|
|
|
date.today(),
|
|
|
|
)
|
2017-02-07 17:05:47 +00:00
|
|
|
self.assertXMLEqual(response.content.decode(), expected_content)
|
2012-01-29 19:24:32 +00:00
|
|
|
|
|
|
|
def test_sitemap_section_with_https_request(self):
|
|
|
|
"A sitemap section requested in HTTPS is rendered with HTTPS links"
|
2022-02-03 19:24:19 +00:00
|
|
|
response = self.client.get("/simple/sitemap-simple.xml", **self.extra)
|
2022-02-04 07:08:27 +00:00
|
|
|
expected_content = (
|
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
|
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" '
|
|
|
|
'xmlns:xhtml="http://www.w3.org/1999/xhtml">\n'
|
|
|
|
"<url><loc>%s/location/</loc><lastmod>%s</lastmod>"
|
|
|
|
"<changefreq>never</changefreq><priority>0.5</priority></url>\n"
|
|
|
|
"</urlset>"
|
|
|
|
) % (
|
2022-02-03 19:24:19 +00:00
|
|
|
self.base_url.replace("http://", "https://"),
|
|
|
|
date.today(),
|
|
|
|
)
|
2017-02-07 17:05:47 +00:00
|
|
|
self.assertXMLEqual(response.content.decode(), expected_content)
|