Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Compared response.content with bytes.

  • Loading branch information...
commit faf570df187bc82a3bcffa5613165a6e6cc56a57 1 parent d1452f6
Aymeric Augustin authored August 14, 2012
4  django/contrib/sitemaps/tests/generic.py
... ...
@@ -1,3 +1,5 @@
  1
+from __future__ import unicode_literals
  2
+
1 3
 from django.contrib.auth.models import User
2 4
 from django.test.utils import override_settings
3 5
 
@@ -12,7 +14,7 @@ def test_generic_sitemap(self):
12 14
         expected = ''
13 15
         for username in User.objects.values_list("username", flat=True):
14 16
             expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
15  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  17
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
16 18
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
17 19
 %s
18 20
 </urlset>
14  django/contrib/sitemaps/tests/http.py
@@ -21,7 +21,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
  24
+        self.assertEqual(response.content, b"""<?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>
@@ -33,7 +33,7 @@ def test_simple_sitemap_index(self):
33 33
     def test_simple_sitemap_custom_index(self):
34 34
         "A simple sitemap index can be rendered with a custom template"
35 35
         response = self.client.get('/simple/custom-index.xml')
36  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  36
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
37 37
 <!-- This is a customised template -->
38 38
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
39 39
 <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
@@ -43,7 +43,7 @@ def test_simple_sitemap_custom_index(self):
43 43
     def test_simple_sitemap_section(self):
44 44
         "A simple sitemap section can be rendered"
45 45
         response = self.client.get('/simple/sitemap-simple.xml')
46  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  46
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
47 47
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
48 48
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
49 49
 </urlset>
@@ -52,7 +52,7 @@ def test_simple_sitemap_section(self):
52 52
     def test_simple_sitemap(self):
53 53
         "A simple sitemap can be rendered"
54 54
         response = self.client.get('/simple/sitemap.xml')
55  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  55
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
56 56
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
57 57
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
58 58
 </urlset>
@@ -64,7 +64,7 @@ def test_simple_sitemap(self):
64 64
     def test_simple_custom_sitemap(self):
65 65
         "A simple sitemap can be rendered with a custom template"
66 66
         response = self.client.get('/simple/custom-sitemap.xml')
67  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  67
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
68 68
 <!-- This is a customised template -->
69 69
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
70 70
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
@@ -90,7 +90,7 @@ def test_requestsite_sitemap(self):
90 90
         # installed doesn't raise an exception
91 91
         Site._meta.installed = False
92 92
         response = self.client.get('/simple/sitemap.xml')
93  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  93
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
94 94
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
95 95
 <url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
96 96
 </urlset>
@@ -131,7 +131,7 @@ def test_cached_sitemap_index(self):
131 131
         Check that a cached sitemap index can be rendered (#2713).
132 132
         """
133 133
         response = self.client.get('/cached/index.xml')
134  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  134
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
135 135
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
136 136
 <sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
137 137
 </sitemapindex>
10  django/contrib/sitemaps/tests/https.py
... ...
@@ -1,3 +1,5 @@
  1
+from __future__ import unicode_literals
  2
+
1 3
 from datetime import date
2 4
 
3 5
 from django.test.utils import override_settings
@@ -11,7 +13,7 @@ class HTTPSSitemapTests(SitemapTestsBase):
11 13
     def test_secure_sitemap_index(self):
12 14
         "A secure sitemap index can be rendered"
13 15
         response = self.client.get('/secure/index.xml')
14  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  16
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
15 17
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
16 18
 <sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
17 19
 </sitemapindex>
@@ -20,7 +22,7 @@ def test_secure_sitemap_index(self):
20 22
     def test_secure_sitemap_section(self):
21 23
         "A secure sitemap section can be rendered"
22 24
         response = self.client.get('/secure/sitemap-simple.xml')
23  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  25
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
24 26
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
25 27
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
26 28
 </urlset>
@@ -34,7 +36,7 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
34 36
     def test_sitemap_index_with_https_request(self):
35 37
         "A sitemap index requested in HTTPS is rendered with HTTPS links"
36 38
         response = self.client.get('/simple/index.xml', **self.extra)
37  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  39
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
38 40
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
39 41
 <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
40 42
 </sitemapindex>
@@ -43,7 +45,7 @@ def test_sitemap_index_with_https_request(self):
43 45
     def test_sitemap_section_with_https_request(self):
44 46
         "A sitemap section requested in HTTPS is rendered with HTTPS links"
45 47
         response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
46  
-        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  48
+        self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
47 49
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
48 50
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
49 51
 </urlset>
2  tests/modeltests/test_client/models.py
@@ -91,7 +91,7 @@ def test_raw_post(self):
91 91
                                     content_type="text/xml")
92 92
         self.assertEqual(response.status_code, 200)
93 93
         self.assertEqual(response.templates[0].name, "Book template")
94  
-        self.assertEqual(response.content, "Blink - Malcolm Gladwell")
  94
+        self.assertEqual(response.content, b"Blink - Malcolm Gladwell")
95 95
 
96 96
     def test_redirect(self):
97 97
         "GET a URL that redirects elsewhere"
2  tests/regressiontests/admin_views/tests.py
@@ -787,7 +787,7 @@ def testCustomAdminSitePasswordChangeDoneTemplate(self):
787 787
     def testCustomAdminSiteView(self):
788 788
         self.client.login(username='super', password='secret')
789 789
         response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
790  
-        self.assertEqual(response.content, "Django is a magical pony!")
  790
+        self.assertEqual(response.content, b"Django is a magical pony!")
791 791
 
792 792
 def get_perm(Model, perm):
793 793
     """Return the permission object, for the Model"""
36  tests/regressiontests/cache/tests.py
@@ -1592,43 +1592,43 @@ def test_view_decorator(self):
1592 1592
 
1593 1593
         # Request the view once
1594 1594
         response = default_view(request, '1')
1595  
-        self.assertEqual(response.content, 'Hello World 1')
  1595
+        self.assertEqual(response.content, b'Hello World 1')
1596 1596
 
1597 1597
         # Request again -- hit the cache
1598 1598
         response = default_view(request, '2')
1599  
-        self.assertEqual(response.content, 'Hello World 1')
  1599
+        self.assertEqual(response.content, b'Hello World 1')
1600 1600
 
1601 1601
         # Requesting the same view with the explicit cache should yield the same result
1602 1602
         response = explicit_default_view(request, '3')
1603  
-        self.assertEqual(response.content, 'Hello World 1')
  1603
+        self.assertEqual(response.content, b'Hello World 1')
1604 1604
 
1605 1605
         # Requesting with a prefix will hit a different cache key
1606 1606
         response = explicit_default_with_prefix_view(request, '4')
1607  
-        self.assertEqual(response.content, 'Hello World 4')
  1607
+        self.assertEqual(response.content, b'Hello World 4')
1608 1608
 
1609 1609
         # Hitting the same view again gives a cache hit
1610 1610
         response = explicit_default_with_prefix_view(request, '5')
1611  
-        self.assertEqual(response.content, 'Hello World 4')
  1611
+        self.assertEqual(response.content, b'Hello World 4')
1612 1612
 
1613 1613
         # And going back to the implicit cache will hit the same cache
1614 1614
         response = default_with_prefix_view(request, '6')
1615  
-        self.assertEqual(response.content, 'Hello World 4')
  1615
+        self.assertEqual(response.content, b'Hello World 4')
1616 1616
 
1617 1617
         # Requesting from an alternate cache won't hit cache
1618 1618
         response = other_view(request, '7')
1619  
-        self.assertEqual(response.content, 'Hello World 7')
  1619
+        self.assertEqual(response.content, b'Hello World 7')
1620 1620
 
1621 1621
         # But a repeated hit will hit cache
1622 1622
         response = other_view(request, '8')
1623  
-        self.assertEqual(response.content, 'Hello World 7')
  1623
+        self.assertEqual(response.content, b'Hello World 7')
1624 1624
 
1625 1625
         # And prefixing the alternate cache yields yet another cache entry
1626 1626
         response = other_with_prefix_view(request, '9')
1627  
-        self.assertEqual(response.content, 'Hello World 9')
  1627
+        self.assertEqual(response.content, b'Hello World 9')
1628 1628
 
1629 1629
         # Request from the alternate cache with a new prefix and a custom timeout
1630 1630
         response = other_with_timeout_view(request, '10')
1631  
-        self.assertEqual(response.content, 'Hello World 10')
  1631
+        self.assertEqual(response.content, b'Hello World 10')
1632 1632
 
1633 1633
         # But if we wait a couple of seconds...
1634 1634
         time.sleep(2)
@@ -1636,38 +1636,38 @@ def test_view_decorator(self):
1636 1636
         # ... the default cache will still hit
1637 1637
         cache = get_cache('default')
1638 1638
         response = default_view(request, '11')
1639  
-        self.assertEqual(response.content, 'Hello World 1')
  1639
+        self.assertEqual(response.content, b'Hello World 1')
1640 1640
 
1641 1641
         # ... the default cache with a prefix will still hit
1642 1642
         response = default_with_prefix_view(request, '12')
1643  
-        self.assertEqual(response.content, 'Hello World 4')
  1643
+        self.assertEqual(response.content, b'Hello World 4')
1644 1644
 
1645 1645
         # ... the explicit default cache will still hit
1646 1646
         response = explicit_default_view(request, '13')
1647  
-        self.assertEqual(response.content, 'Hello World 1')
  1647
+        self.assertEqual(response.content, b'Hello World 1')
1648 1648
 
1649 1649
         # ... the explicit default cache with a prefix will still hit
1650 1650
         response = explicit_default_with_prefix_view(request, '14')
1651  
-        self.assertEqual(response.content, 'Hello World 4')
  1651
+        self.assertEqual(response.content, b'Hello World 4')
1652 1652
 
1653 1653
         # .. but a rapidly expiring cache won't hit
1654 1654
         response = other_view(request, '15')
1655  
-        self.assertEqual(response.content, 'Hello World 15')
  1655
+        self.assertEqual(response.content, b'Hello World 15')
1656 1656
 
1657 1657
         # .. even if it has a prefix
1658 1658
         response = other_with_prefix_view(request, '16')
1659  
-        self.assertEqual(response.content, 'Hello World 16')
  1659
+        self.assertEqual(response.content, b'Hello World 16')
1660 1660
 
1661 1661
         # ... but a view with a custom timeout will still hit
1662 1662
         response = other_with_timeout_view(request, '17')
1663  
-        self.assertEqual(response.content, 'Hello World 10')
  1663
+        self.assertEqual(response.content, b'Hello World 10')
1664 1664
 
1665 1665
         # And if we wait a few more seconds
1666 1666
         time.sleep(2)
1667 1667
 
1668 1668
         # the custom timeouot cache will miss
1669 1669
         response = other_with_timeout_view(request, '18')
1670  
-        self.assertEqual(response.content, 'Hello World 18')
  1670
+        self.assertEqual(response.content, b'Hello World 18')
1671 1671
 
1672 1672
 
1673 1673
 @override_settings(
4  tests/regressiontests/conditional_processing/models.py
... ...
@@ -1,4 +1,6 @@
1 1
 # -*- coding:utf-8 -*-
  2
+from __future__ import unicode_literals
  3
+
2 4
 from datetime import datetime
3 5
 
4 6
 from django.test import TestCase
@@ -28,7 +30,7 @@ def assertFullResponse(self, response, check_last_modified=True, check_etag=True
28 30
 
29 31
     def assertNotModified(self, response):
30 32
         self.assertEqual(response.status_code, 304)
31  
-        self.assertEqual(response.content, '')
  33
+        self.assertEqual(response.content, b'')
32 34
 
33 35
     def testWithoutConditions(self):
34 36
         response = self.client.get('/condition/')
34  tests/regressiontests/templates/response.py
... ...
@@ -1,3 +1,5 @@
  1
+from __future__ import unicode_literals
  2
+
1 3
 import os
2 4
 import pickle
3 5
 import time
@@ -29,16 +31,16 @@ def _response(self, template='foo', *args, **kwargs):
29 31
     def test_template_resolving(self):
30 32
         response = SimpleTemplateResponse('first/test.html')
31 33
         response.render()
32  
-        self.assertEqual('First template\n', response.content)
  34
+        self.assertEqual(response.content, b'First template\n')
33 35
 
34 36
         templates = ['foo.html', 'second/test.html', 'first/test.html']
35 37
         response = SimpleTemplateResponse(templates)
36 38
         response.render()
37  
-        self.assertEqual('Second template\n', response.content)
  39
+        self.assertEqual(response.content, b'Second template\n')
38 40
 
39 41
         response = self._response()
40 42
         response.render()
41  
-        self.assertEqual(response.content, 'foo')
  43
+        self.assertEqual(response.content, b'foo')
42 44
 
43 45
     def test_explicit_baking(self):
44 46
         # explicit baking
@@ -50,17 +52,17 @@ def test_explicit_baking(self):
50 52
     def test_render(self):
51 53
         # response is not re-rendered without the render call
52 54
         response = self._response().render()
53  
-        self.assertEqual(response.content, 'foo')
  55
+        self.assertEqual(response.content, b'foo')
54 56
 
55 57
         # rebaking doesn't change the rendered content
56 58
         response.template_name = Template('bar{{ baz }}')
57 59
         response.render()
58  
-        self.assertEqual(response.content, 'foo')
  60
+        self.assertEqual(response.content, b'foo')
59 61
 
60 62
         # but rendered content can be overridden by manually
61 63
         # setting content
62 64
         response.content = 'bar'
63  
-        self.assertEqual(response.content, 'bar')
  65
+        self.assertEqual(response.content, b'bar')
64 66
 
65 67
     def test_iteration_unrendered(self):
66 68
         # unrendered response raises an exception on iteration
@@ -77,7 +79,7 @@ def test_iteration_rendered(self):
77 79
         # iteration works for rendered responses
78 80
         response = self._response().render()
79 81
         res = [x for x in response]
80  
-        self.assertEqual(res, ['foo'])
  82
+        self.assertEqual(res, [b'foo'])
81 83
 
82 84
     def test_content_access_unrendered(self):
83 85
         # unrendered response raises an exception when content is accessed
@@ -89,7 +91,7 @@ def test_content_access_unrendered(self):
89 91
     def test_content_access_rendered(self):
90 92
         # rendered response content can be accessed
91 93
         response = self._response().render()
92  
-        self.assertEqual(response.content, 'foo')
  94
+        self.assertEqual(response.content, b'foo')
93 95
 
94 96
     def test_set_content(self):
95 97
         # content can be overriden
@@ -97,23 +99,23 @@ def test_set_content(self):
97 99
         self.assertFalse(response.is_rendered)
98 100
         response.content = 'spam'
99 101
         self.assertTrue(response.is_rendered)
100  
-        self.assertEqual(response.content, 'spam')
  102
+        self.assertEqual(response.content, b'spam')
101 103
         response.content = 'baz'
102  
-        self.assertEqual(response.content, 'baz')
  104
+        self.assertEqual(response.content, b'baz')
103 105
 
104 106
     def test_dict_context(self):
105 107
         response = self._response('{{ foo }}{{ processors }}',
106 108
                                   {'foo': 'bar'})
107 109
         self.assertEqual(response.context_data, {'foo': 'bar'})
108 110
         response.render()
109  
-        self.assertEqual(response.content, 'bar')
  111
+        self.assertEqual(response.content, b'bar')
110 112
 
111 113
     def test_context_instance(self):
112 114
         response = self._response('{{ foo }}{{ processors }}',
113 115
                                   Context({'foo': 'bar'}))
114 116
         self.assertEqual(response.context_data.__class__, Context)
115 117
         response.render()
116  
-        self.assertEqual(response.content, 'bar')
  118
+        self.assertEqual(response.content, b'bar')
117 119
 
118 120
     def test_kwargs(self):
119 121
         response = self._response(content_type = 'application/json', status=504)
@@ -140,7 +142,7 @@ def post2(obj):
140 142
 
141 143
         # When the content is rendered, all the callbacks are invoked, too.
142 144
         response.render()
143  
-        self.assertEqual('First template\n', response.content)
  145
+        self.assertEqual(response.content, b'First template\n')
144 146
         self.assertEqual(post, ['post1','post2'])
145 147
 
146 148
 
@@ -202,17 +204,17 @@ def _response(self, template='foo', *args, **kwargs):
202 204
 
203 205
     def test_render(self):
204 206
         response = self._response('{{ foo }}{{ processors }}').render()
205  
-        self.assertEqual(response.content, 'yes')
  207
+        self.assertEqual(response.content, b'yes')
206 208
 
207 209
     def test_render_with_requestcontext(self):
208 210
         response = self._response('{{ foo }}{{ processors }}',
209 211
                                   {'foo': 'bar'}).render()
210  
-        self.assertEqual(response.content, 'baryes')
  212
+        self.assertEqual(response.content, b'baryes')
211 213
 
212 214
     def test_render_with_context(self):
213 215
         response = self._response('{{ foo }}{{ processors }}',
214 216
                                   Context({'foo': 'bar'})).render()
215  
-        self.assertEqual(response.content, 'bar')
  217
+        self.assertEqual(response.content, b'bar')
216 218
 
217 219
     def test_kwargs(self):
218 220
         response = self._response(content_type = 'application/json',
8  tests/regressiontests/urlpatterns_reverse/tests.py
... ...
@@ -1,7 +1,7 @@
1 1
 """
2 2
 Unit tests for reverse URL lookups.
3 3
 """
4  
-from __future__ import absolute_import
  4
+from __future__ import absolute_import, unicode_literals
5 5
 
6 6
 from django.conf import settings
7 7
 from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
@@ -405,8 +405,8 @@ def tearDown(self):
405 405
     def test_urlconf(self):
406 406
         response = self.client.get('/test/me/')
407 407
         self.assertEqual(response.status_code, 200)
408  
-        self.assertEqual(response.content, 'outer:/test/me/,'
409  
-                                           'inner:/inner_urlconf/second_test/')
  408
+        self.assertEqual(response.content, b'outer:/test/me/,'
  409
+                                           b'inner:/inner_urlconf/second_test/')
410 410
         response = self.client.get('/inner_urlconf/second_test/')
411 411
         self.assertEqual(response.status_code, 200)
412 412
         response = self.client.get('/second_test/')
@@ -422,7 +422,7 @@ def test_urlconf_overridden(self):
422 422
         self.assertEqual(response.status_code, 404)
423 423
         response = self.client.get('/second_test/')
424 424
         self.assertEqual(response.status_code, 200)
425  
-        self.assertEqual(response.content, 'outer:,inner:/second_test/')
  425
+        self.assertEqual(response.content, b'outer:,inner:/second_test/')
426 426
 
427 427
     def test_urlconf_overridden_with_null(self):
428 428
         settings.MIDDLEWARE_CLASSES += (

0 notes on commit faf570d

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