Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Fixed sitemaps tests.

  • Loading branch information...
commit 37c9318748896a1bb7e33a05a7db2c5de268ff22 1 parent f2fe7a3
Aymeric Augustin authored August 14, 2012
5  django/contrib/sitemaps/tests/generic.py
@@ -14,8 +14,9 @@ def test_generic_sitemap(self):
14 14
         expected = ''
15 15
         for username in User.objects.values_list("username", flat=True):
16 16
             expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
17  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  17
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
18 18
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
19 19
 %s
20 20
 </urlset>
21  
-""" % expected)
  21
+""" % expected
  22
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
36  django/contrib/sitemaps/tests/http.py
@@ -21,11 +21,12 @@ class HTTPSitemapTests(SitemapTestsBase):
21 21
     def test_simple_sitemap_index(self):
22 22
         "A simple sitemap index can be rendered"
23 23
         response = self.client.get('/simple/index.xml')
24  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  24
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
25 25
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
26 26
 <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
27 27
 </sitemapindex>
28  
-""" % self.base_url)
  28
+""" % self.base_url
  29
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
29 30
 
30 31
     @override_settings(
31 32
         TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
@@ -33,30 +34,34 @@ def test_simple_sitemap_index(self):
33 34
     def test_simple_sitemap_custom_index(self):
34 35
         "A simple sitemap index can be rendered with a custom template"
35 36
         response = self.client.get('/simple/custom-index.xml')
36  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  37
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
37 38
 <!-- This is a customised template -->
38 39
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
39 40
 <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
40 41
 </sitemapindex>
41  
-""" % self.base_url)
  42
+""" % self.base_url
  43
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
  44
+
42 45
 
43 46
     def test_simple_sitemap_section(self):
44 47
         "A simple sitemap section can be rendered"
45 48
         response = self.client.get('/simple/sitemap-simple.xml')
46  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  49
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
47 50
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
48 51
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
49 52
 </urlset>
50  
-""" % (self.base_url, date.today()))
  53
+""" % (self.base_url, date.today())
  54
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
51 55
 
52 56
     def test_simple_sitemap(self):
53 57
         "A simple sitemap can be rendered"
54 58
         response = self.client.get('/simple/sitemap.xml')
55  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  59
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
56 60
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
57 61
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
58 62
 </urlset>
59  
-""" % (self.base_url, date.today()))
  63
+""" % (self.base_url, date.today())
  64
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
60 65
 
61 66
     @override_settings(
62 67
         TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
@@ -64,12 +69,13 @@ def test_simple_sitemap(self):
64 69
     def test_simple_custom_sitemap(self):
65 70
         "A simple sitemap can be rendered with a custom template"
66 71
         response = self.client.get('/simple/custom-sitemap.xml')
67  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  72
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
68 73
 <!-- This is a customised template -->
69 74
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
70 75
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
71 76
 </urlset>
72  
-""" % (self.base_url, date.today()))
  77
+""" % (self.base_url, date.today())
  78
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
73 79
 
74 80
     @skipUnless(settings.USE_I18N, "Internationalization is not enabled")
75 81
     @override_settings(USE_L10N=True)
@@ -90,11 +96,12 @@ def test_requestsite_sitemap(self):
90 96
         # installed doesn't raise an exception
91 97
         Site._meta.installed = False
92 98
         response = self.client.get('/simple/sitemap.xml')
93  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  99
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
94 100
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
95 101
 <url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
96 102
 </urlset>
97  
-""" % date.today())
  103
+""" % date.today()
  104
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
98 105
 
99 106
     @skipUnless("django.contrib.sites" in settings.INSTALLED_APPS,
100 107
                 "django.contrib.sites app not installed.")
@@ -131,8 +138,9 @@ def test_cached_sitemap_index(self):
131 138
         Check that a cached sitemap index can be rendered (#2713).
132 139
         """
133 140
         response = self.client.get('/cached/index.xml')
134  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  141
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
135 142
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
136 143
 <sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
137 144
 </sitemapindex>
138  
-""" % self.base_url)
  145
+""" % self.base_url
  146
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
20  django/contrib/sitemaps/tests/https.py
@@ -13,20 +13,22 @@ class HTTPSSitemapTests(SitemapTestsBase):
13 13
     def test_secure_sitemap_index(self):
14 14
         "A secure sitemap index can be rendered"
15 15
         response = self.client.get('/secure/index.xml')
16  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  16
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
17 17
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
18 18
 <sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
19 19
 </sitemapindex>
20  
-""" % self.base_url)
  20
+""" % self.base_url
  21
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
21 22
 
22 23
     def test_secure_sitemap_section(self):
23 24
         "A secure sitemap section can be rendered"
24 25
         response = self.client.get('/secure/sitemap-simple.xml')
25  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  26
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
26 27
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
27 28
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
28 29
 </urlset>
29  
-""" % (self.base_url, date.today()))
  30
+""" % (self.base_url, date.today())
  31
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
30 32
 
31 33
 
32 34
 @override_settings(SECURE_PROXY_SSL_HEADER=False)
@@ -36,17 +38,19 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
36 38
     def test_sitemap_index_with_https_request(self):
37 39
         "A sitemap index requested in HTTPS is rendered with HTTPS links"
38 40
         response = self.client.get('/simple/index.xml', **self.extra)
39  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  41
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
40 42
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
41 43
 <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
42 44
 </sitemapindex>
43  
-""" % self.base_url.replace('http://', 'https://'))
  45
+""" % self.base_url.replace('http://', 'https://')
  46
+        self.assertEqual(response.content, expected_content.encode('utf-8'))
44 47
 
45 48
     def test_sitemap_section_with_https_request(self):
46 49
         "A sitemap section requested in HTTPS is rendered with HTTPS links"
47 50
         response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
48  
-        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
  51
+        expected_content = """<?xml version="1.0" encoding="UTF-8"?>
49 52
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
50 53
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
51 54
 </urlset>
52  
-""" % (self.base_url.replace('http://', 'https://'), date.today()))
  55
+""" % (self.base_url.replace('http://', 'https://'), date.today())
  56
+        self.assertEqual(response.content, expected_content.encode('utf-8'))

0 notes on commit 37c9318

Please sign in to comment.
Something went wrong with that request. Please try again.