[py3] Fixed sitemaps tests.
This commit is contained in:
parent
f2fe7a3e36
commit
37c9318748
|
@ -14,8 +14,9 @@ class GenericViewsSitemapTests(SitemapTestsBase):
|
||||||
expected = ''
|
expected = ''
|
||||||
for username in User.objects.values_list("username", flat=True):
|
for username in User.objects.values_list("username", flat=True):
|
||||||
expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
|
expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
%s
|
%s
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % expected)
|
""" % expected
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
|
@ -21,11 +21,12 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_sitemap_index(self):
|
def test_simple_sitemap_index(self):
|
||||||
"A simple sitemap index can be rendered"
|
"A simple sitemap index can be rendered"
|
||||||
response = self.client.get('/simple/index.xml')
|
response = self.client.get('/simple/index.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
""" % self.base_url)
|
""" % self.base_url
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
|
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
|
||||||
|
@ -33,30 +34,34 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_sitemap_custom_index(self):
|
def test_simple_sitemap_custom_index(self):
|
||||||
"A simple sitemap index can be rendered with a custom template"
|
"A simple sitemap index can be rendered with a custom template"
|
||||||
response = self.client.get('/simple/custom-index.xml')
|
response = self.client.get('/simple/custom-index.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- This is a customised template -->
|
<!-- This is a customised template -->
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
""" % self.base_url)
|
""" % self.base_url
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def test_simple_sitemap_section(self):
|
def test_simple_sitemap_section(self):
|
||||||
"A simple sitemap section can be rendered"
|
"A simple sitemap section can be rendered"
|
||||||
response = self.client.get('/simple/sitemap-simple.xml')
|
response = self.client.get('/simple/sitemap-simple.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % (self.base_url, date.today()))
|
""" % (self.base_url, date.today())
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
def test_simple_sitemap(self):
|
def test_simple_sitemap(self):
|
||||||
"A simple sitemap can be rendered"
|
"A simple sitemap can be rendered"
|
||||||
response = self.client.get('/simple/sitemap.xml')
|
response = self.client.get('/simple/sitemap.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % (self.base_url, date.today()))
|
""" % (self.base_url, date.today())
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
|
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
|
||||||
|
@ -64,12 +69,13 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_custom_sitemap(self):
|
def test_simple_custom_sitemap(self):
|
||||||
"A simple sitemap can be rendered with a custom template"
|
"A simple sitemap can be rendered with a custom template"
|
||||||
response = self.client.get('/simple/custom-sitemap.xml')
|
response = self.client.get('/simple/custom-sitemap.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- This is a customised template -->
|
<!-- This is a customised template -->
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % (self.base_url, date.today()))
|
""" % (self.base_url, date.today())
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
@skipUnless(settings.USE_I18N, "Internationalization is not enabled")
|
@skipUnless(settings.USE_I18N, "Internationalization is not enabled")
|
||||||
@override_settings(USE_L10N=True)
|
@override_settings(USE_L10N=True)
|
||||||
|
@ -90,11 +96,12 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
# installed doesn't raise an exception
|
# installed doesn't raise an exception
|
||||||
Site._meta.installed = False
|
Site._meta.installed = False
|
||||||
response = self.client.get('/simple/sitemap.xml')
|
response = self.client.get('/simple/sitemap.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>
|
<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % date.today())
|
""" % date.today()
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
@skipUnless("django.contrib.sites" in settings.INSTALLED_APPS,
|
@skipUnless("django.contrib.sites" in settings.INSTALLED_APPS,
|
||||||
"django.contrib.sites app not installed.")
|
"django.contrib.sites app not installed.")
|
||||||
|
@ -131,8 +138,9 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
Check that a cached sitemap index can be rendered (#2713).
|
Check that a cached sitemap index can be rendered (#2713).
|
||||||
"""
|
"""
|
||||||
response = self.client.get('/cached/index.xml')
|
response = self.client.get('/cached/index.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
""" % self.base_url)
|
""" % self.base_url
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
|
@ -13,20 +13,22 @@ class HTTPSSitemapTests(SitemapTestsBase):
|
||||||
def test_secure_sitemap_index(self):
|
def test_secure_sitemap_index(self):
|
||||||
"A secure sitemap index can be rendered"
|
"A secure sitemap index can be rendered"
|
||||||
response = self.client.get('/secure/index.xml')
|
response = self.client.get('/secure/index.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
""" % self.base_url)
|
""" % self.base_url
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
def test_secure_sitemap_section(self):
|
def test_secure_sitemap_section(self):
|
||||||
"A secure sitemap section can be rendered"
|
"A secure sitemap section can be rendered"
|
||||||
response = self.client.get('/secure/sitemap-simple.xml')
|
response = self.client.get('/secure/sitemap-simple.xml')
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % (self.base_url, date.today()))
|
""" % (self.base_url, date.today())
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
@override_settings(SECURE_PROXY_SSL_HEADER=False)
|
@override_settings(SECURE_PROXY_SSL_HEADER=False)
|
||||||
|
@ -36,17 +38,19 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
|
||||||
def test_sitemap_index_with_https_request(self):
|
def test_sitemap_index_with_https_request(self):
|
||||||
"A sitemap index requested in HTTPS is rendered with HTTPS links"
|
"A sitemap index requested in HTTPS is rendered with HTTPS links"
|
||||||
response = self.client.get('/simple/index.xml', **self.extra)
|
response = self.client.get('/simple/index.xml', **self.extra)
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
""" % self.base_url.replace('http://', 'https://'))
|
""" % self.base_url.replace('http://', 'https://')
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
||||||
def test_sitemap_section_with_https_request(self):
|
def test_sitemap_section_with_https_request(self):
|
||||||
"A sitemap section requested in HTTPS is rendered with HTTPS links"
|
"A sitemap section requested in HTTPS is rendered with HTTPS links"
|
||||||
response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
|
response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
|
||||||
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % (self.base_url.replace('http://', 'https://'), date.today()))
|
""" % (self.base_url.replace('http://', 'https://'), date.today())
|
||||||
|
self.assertEqual(response.content, expected_content.encode('utf-8'))
|
||||||
|
|
Loading…
Reference in New Issue