From 37c9318748896a1bb7e33a05a7db2c5de268ff22 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Tue, 14 Aug 2012 20:12:38 +0200 Subject: [PATCH] [py3] Fixed sitemaps tests. --- django/contrib/sitemaps/tests/generic.py | 5 ++-- django/contrib/sitemaps/tests/http.py | 36 +++++++++++++++--------- django/contrib/sitemaps/tests/https.py | 20 +++++++------ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/django/contrib/sitemaps/tests/generic.py b/django/contrib/sitemaps/tests/generic.py index f63c5bf6e7..e0b0a827a6 100644 --- a/django/contrib/sitemaps/tests/generic.py +++ b/django/contrib/sitemaps/tests/generic.py @@ -14,8 +14,9 @@ class GenericViewsSitemapTests(SitemapTestsBase): expected = '' for username in User.objects.values_list("username", flat=True): expected += "%s/users/%s/" % (self.base_url, username) - self.assertEqual(response.content, b""" + expected_content = """ %s -""" % expected) +""" % expected + self.assertEqual(response.content, expected_content.encode('utf-8')) diff --git a/django/contrib/sitemaps/tests/http.py b/django/contrib/sitemaps/tests/http.py index 5cff67c238..8da971876f 100644 --- a/django/contrib/sitemaps/tests/http.py +++ b/django/contrib/sitemaps/tests/http.py @@ -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""" + expected_content = """ %s/simple/sitemap-simple.xml -""" % 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 @@ class HTTPSitemapTests(SitemapTestsBase): 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""" + expected_content = """ %s/simple/sitemap-simple.xml -""" % 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""" + expected_content = """ %s/location/%snever0.5 -""" % (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""" + expected_content = """ %s/location/%snever0.5 -""" % (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 @@ class HTTPSitemapTests(SitemapTestsBase): 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""" + expected_content = """ %s/location/%snever0.5 -""" % (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 @@ class HTTPSitemapTests(SitemapTestsBase): # installed doesn't raise an exception Site._meta.installed = False response = self.client.get('/simple/sitemap.xml') - self.assertEqual(response.content, b""" + expected_content = """ http://testserver/location/%snever0.5 -""" % 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 @@ class HTTPSitemapTests(SitemapTestsBase): Check that a cached sitemap index can be rendered (#2713). """ response = self.client.get('/cached/index.xml') - self.assertEqual(response.content, b""" + expected_content = """ %s/cached/sitemap-simple.xml -""" % self.base_url) +""" % self.base_url + self.assertEqual(response.content, expected_content.encode('utf-8')) diff --git a/django/contrib/sitemaps/tests/https.py b/django/contrib/sitemaps/tests/https.py index 34d992fc78..26241eb30b 100644 --- a/django/contrib/sitemaps/tests/https.py +++ b/django/contrib/sitemaps/tests/https.py @@ -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""" + expected_content = """ %s/secure/sitemap-simple.xml -""" % 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""" + expected_content = """ %s/location/%snever0.5 -""" % (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""" + expected_content = """ %s/simple/sitemap-simple.xml -""" % 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""" + expected_content = """ %s/location/%snever0.5 -""" % (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'))