Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Fixed sitemaps tests.

  • Loading branch information...
commit 37c9318748896a1bb7e33a05a7db2c5de268ff22 1 parent f2fe7a3
Aymeric Augustin aaugustin authored
5 django/contrib/sitemaps/tests/generic.py
View
@@ -14,8 +14,9 @@ def test_generic_sitemap(self):
expected = ''
for username in User.objects.values_list("username", flat=True):
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">
%s
</urlset>
-""" % expected)
+""" % expected
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
36 django/contrib/sitemaps/tests/http.py
View
@@ -21,11 +21,12 @@ class HTTPSitemapTests(SitemapTestsBase):
def test_simple_sitemap_index(self):
"A simple sitemap index can be rendered"
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">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
</sitemapindex>
-""" % self.base_url)
+""" % self.base_url
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
@override_settings(
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
@@ -33,30 +34,34 @@ def test_simple_sitemap_index(self):
def test_simple_sitemap_custom_index(self):
"A simple sitemap index can be rendered with a custom template"
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 -->
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
</sitemapindex>
-""" % self.base_url)
+""" % self.base_url
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
+
def test_simple_sitemap_section(self):
"A simple sitemap section can be rendered"
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">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</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):
"A simple sitemap can be rendered"
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">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
-""" % (self.base_url, date.today()))
+""" % (self.base_url, date.today())
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
@override_settings(
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
@@ -64,12 +69,13 @@ def test_simple_sitemap(self):
def test_simple_custom_sitemap(self):
"A simple sitemap can be rendered with a custom template"
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 -->
<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()))
+""" % (self.base_url, date.today())
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
@skipUnless(settings.USE_I18N, "Internationalization is not enabled")
@override_settings(USE_L10N=True)
@@ -90,11 +96,12 @@ def test_requestsite_sitemap(self):
# installed doesn't raise an exception
Site._meta.installed = False
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">
<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
-""" % date.today())
+""" % date.today()
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
@skipUnless("django.contrib.sites" in settings.INSTALLED_APPS,
"django.contrib.sites app not installed.")
@@ -131,8 +138,9 @@ def test_cached_sitemap_index(self):
Check that a cached sitemap index can be rendered (#2713).
"""
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">
<sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
</sitemapindex>
-""" % self.base_url)
+""" % self.base_url
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
20 django/contrib/sitemaps/tests/https.py
View
@@ -13,20 +13,22 @@ class HTTPSSitemapTests(SitemapTestsBase):
def test_secure_sitemap_index(self):
"A secure sitemap index can be rendered"
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">
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
</sitemapindex>
-""" % self.base_url)
+""" % self.base_url
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
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, 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">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</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)
@@ -36,17 +38,19 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
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, 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">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
</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):
"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, 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">
<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()))
+""" % (self.base_url.replace('http://', 'https://'), date.today())
+ self.assertEqual(response.content, expected_content.encode('utf-8'))
Please sign in to comment.
Something went wrong with that request. Please try again.