Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Compared response.content with bytes.

  • Loading branch information...
commit faf570df187bc82a3bcffa5613165a6e6cc56a57 1 parent d1452f6
@aaugustin aaugustin authored
View
4 django/contrib/sitemaps/tests/generic.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
from django.contrib.auth.models import User
from django.test.utils import override_settings
@@ -12,7 +14,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
%s
</urlset>
View
14 django/contrib/sitemaps/tests/http.py
@@ -21,7 +21,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -33,7 +33,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -43,7 +43,7 @@ def test_simple_sitemap_custom_index(self):
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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -52,7 +52,7 @@ def test_simple_sitemap_section(self):
def test_simple_sitemap(self):
"A simple sitemap can be rendered"
response = self.client.get('/simple/sitemap.xml')
- self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -64,7 +64,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -90,7 +90,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -131,7 +131,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
View
10 django/contrib/sitemaps/tests/https.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
from datetime import date
from django.test.utils import override_settings
@@ -11,7 +13,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -20,7 +22,7 @@ def test_secure_sitemap_index(self):
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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -34,7 +36,7 @@ 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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
@@ -43,7 +45,7 @@ def test_sitemap_index_with_https_request(self):
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, """<?xml version="1.0" encoding="UTF-8"?>
+ self.assertEqual(response.content, b"""<?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>
View
2  tests/modeltests/test_client/models.py
@@ -91,7 +91,7 @@ def test_raw_post(self):
content_type="text/xml")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.templates[0].name, "Book template")
- self.assertEqual(response.content, "Blink - Malcolm Gladwell")
+ self.assertEqual(response.content, b"Blink - Malcolm Gladwell")
def test_redirect(self):
"GET a URL that redirects elsewhere"
View
2  tests/regressiontests/admin_views/tests.py
@@ -787,7 +787,7 @@ def testCustomAdminSitePasswordChangeDoneTemplate(self):
def testCustomAdminSiteView(self):
self.client.login(username='super', password='secret')
response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
- self.assertEqual(response.content, "Django is a magical pony!")
+ self.assertEqual(response.content, b"Django is a magical pony!")
def get_perm(Model, perm):
"""Return the permission object, for the Model"""
View
36 tests/regressiontests/cache/tests.py
@@ -1592,43 +1592,43 @@ def test_view_decorator(self):
# Request the view once
response = default_view(request, '1')
- self.assertEqual(response.content, 'Hello World 1')
+ self.assertEqual(response.content, b'Hello World 1')
# Request again -- hit the cache
response = default_view(request, '2')
- self.assertEqual(response.content, 'Hello World 1')
+ self.assertEqual(response.content, b'Hello World 1')
# Requesting the same view with the explicit cache should yield the same result
response = explicit_default_view(request, '3')
- self.assertEqual(response.content, 'Hello World 1')
+ self.assertEqual(response.content, b'Hello World 1')
# Requesting with a prefix will hit a different cache key
response = explicit_default_with_prefix_view(request, '4')
- self.assertEqual(response.content, 'Hello World 4')
+ self.assertEqual(response.content, b'Hello World 4')
# Hitting the same view again gives a cache hit
response = explicit_default_with_prefix_view(request, '5')
- self.assertEqual(response.content, 'Hello World 4')
+ self.assertEqual(response.content, b'Hello World 4')
# And going back to the implicit cache will hit the same cache
response = default_with_prefix_view(request, '6')
- self.assertEqual(response.content, 'Hello World 4')
+ self.assertEqual(response.content, b'Hello World 4')
# Requesting from an alternate cache won't hit cache
response = other_view(request, '7')
- self.assertEqual(response.content, 'Hello World 7')
+ self.assertEqual(response.content, b'Hello World 7')
# But a repeated hit will hit cache
response = other_view(request, '8')
- self.assertEqual(response.content, 'Hello World 7')
+ self.assertEqual(response.content, b'Hello World 7')
# And prefixing the alternate cache yields yet another cache entry
response = other_with_prefix_view(request, '9')
- self.assertEqual(response.content, 'Hello World 9')
+ self.assertEqual(response.content, b'Hello World 9')
# Request from the alternate cache with a new prefix and a custom timeout
response = other_with_timeout_view(request, '10')
- self.assertEqual(response.content, 'Hello World 10')
+ self.assertEqual(response.content, b'Hello World 10')
# But if we wait a couple of seconds...
time.sleep(2)
@@ -1636,38 +1636,38 @@ def test_view_decorator(self):
# ... the default cache will still hit
cache = get_cache('default')
response = default_view(request, '11')
- self.assertEqual(response.content, 'Hello World 1')
+ self.assertEqual(response.content, b'Hello World 1')
# ... the default cache with a prefix will still hit
response = default_with_prefix_view(request, '12')
- self.assertEqual(response.content, 'Hello World 4')
+ self.assertEqual(response.content, b'Hello World 4')
# ... the explicit default cache will still hit
response = explicit_default_view(request, '13')
- self.assertEqual(response.content, 'Hello World 1')
+ self.assertEqual(response.content, b'Hello World 1')
# ... the explicit default cache with a prefix will still hit
response = explicit_default_with_prefix_view(request, '14')
- self.assertEqual(response.content, 'Hello World 4')
+ self.assertEqual(response.content, b'Hello World 4')
# .. but a rapidly expiring cache won't hit
response = other_view(request, '15')
- self.assertEqual(response.content, 'Hello World 15')
+ self.assertEqual(response.content, b'Hello World 15')
# .. even if it has a prefix
response = other_with_prefix_view(request, '16')
- self.assertEqual(response.content, 'Hello World 16')
+ self.assertEqual(response.content, b'Hello World 16')
# ... but a view with a custom timeout will still hit
response = other_with_timeout_view(request, '17')
- self.assertEqual(response.content, 'Hello World 10')
+ self.assertEqual(response.content, b'Hello World 10')
# And if we wait a few more seconds
time.sleep(2)
# the custom timeouot cache will miss
response = other_with_timeout_view(request, '18')
- self.assertEqual(response.content, 'Hello World 18')
+ self.assertEqual(response.content, b'Hello World 18')
@override_settings(
View
4 tests/regressiontests/conditional_processing/models.py
@@ -1,4 +1,6 @@
# -*- coding:utf-8 -*-
+from __future__ import unicode_literals
+
from datetime import datetime
from django.test import TestCase
@@ -28,7 +30,7 @@ def assertFullResponse(self, response, check_last_modified=True, check_etag=True
def assertNotModified(self, response):
self.assertEqual(response.status_code, 304)
- self.assertEqual(response.content, '')
+ self.assertEqual(response.content, b'')
def testWithoutConditions(self):
response = self.client.get('/condition/')
View
34 tests/regressiontests/templates/response.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import os
import pickle
import time
@@ -29,16 +31,16 @@ def _response(self, template='foo', *args, **kwargs):
def test_template_resolving(self):
response = SimpleTemplateResponse('first/test.html')
response.render()
- self.assertEqual('First template\n', response.content)
+ self.assertEqual(response.content, b'First template\n')
templates = ['foo.html', 'second/test.html', 'first/test.html']
response = SimpleTemplateResponse(templates)
response.render()
- self.assertEqual('Second template\n', response.content)
+ self.assertEqual(response.content, b'Second template\n')
response = self._response()
response.render()
- self.assertEqual(response.content, 'foo')
+ self.assertEqual(response.content, b'foo')
def test_explicit_baking(self):
# explicit baking
@@ -50,17 +52,17 @@ def test_explicit_baking(self):
def test_render(self):
# response is not re-rendered without the render call
response = self._response().render()
- self.assertEqual(response.content, 'foo')
+ self.assertEqual(response.content, b'foo')
# rebaking doesn't change the rendered content
response.template_name = Template('bar{{ baz }}')
response.render()
- self.assertEqual(response.content, 'foo')
+ self.assertEqual(response.content, b'foo')
# but rendered content can be overridden by manually
# setting content
response.content = 'bar'
- self.assertEqual(response.content, 'bar')
+ self.assertEqual(response.content, b'bar')
def test_iteration_unrendered(self):
# unrendered response raises an exception on iteration
@@ -77,7 +79,7 @@ def test_iteration_rendered(self):
# iteration works for rendered responses
response = self._response().render()
res = [x for x in response]
- self.assertEqual(res, ['foo'])
+ self.assertEqual(res, [b'foo'])
def test_content_access_unrendered(self):
# unrendered response raises an exception when content is accessed
@@ -89,7 +91,7 @@ def test_content_access_unrendered(self):
def test_content_access_rendered(self):
# rendered response content can be accessed
response = self._response().render()
- self.assertEqual(response.content, 'foo')
+ self.assertEqual(response.content, b'foo')
def test_set_content(self):
# content can be overriden
@@ -97,23 +99,23 @@ def test_set_content(self):
self.assertFalse(response.is_rendered)
response.content = 'spam'
self.assertTrue(response.is_rendered)
- self.assertEqual(response.content, 'spam')
+ self.assertEqual(response.content, b'spam')
response.content = 'baz'
- self.assertEqual(response.content, 'baz')
+ self.assertEqual(response.content, b'baz')
def test_dict_context(self):
response = self._response('{{ foo }}{{ processors }}',
{'foo': 'bar'})
self.assertEqual(response.context_data, {'foo': 'bar'})
response.render()
- self.assertEqual(response.content, 'bar')
+ self.assertEqual(response.content, b'bar')
def test_context_instance(self):
response = self._response('{{ foo }}{{ processors }}',
Context({'foo': 'bar'}))
self.assertEqual(response.context_data.__class__, Context)
response.render()
- self.assertEqual(response.content, 'bar')
+ self.assertEqual(response.content, b'bar')
def test_kwargs(self):
response = self._response(content_type = 'application/json', status=504)
@@ -140,7 +142,7 @@ def post2(obj):
# When the content is rendered, all the callbacks are invoked, too.
response.render()
- self.assertEqual('First template\n', response.content)
+ self.assertEqual(response.content, b'First template\n')
self.assertEqual(post, ['post1','post2'])
@@ -202,17 +204,17 @@ def _response(self, template='foo', *args, **kwargs):
def test_render(self):
response = self._response('{{ foo }}{{ processors }}').render()
- self.assertEqual(response.content, 'yes')
+ self.assertEqual(response.content, b'yes')
def test_render_with_requestcontext(self):
response = self._response('{{ foo }}{{ processors }}',
{'foo': 'bar'}).render()
- self.assertEqual(response.content, 'baryes')
+ self.assertEqual(response.content, b'baryes')
def test_render_with_context(self):
response = self._response('{{ foo }}{{ processors }}',
Context({'foo': 'bar'})).render()
- self.assertEqual(response.content, 'bar')
+ self.assertEqual(response.content, b'bar')
def test_kwargs(self):
response = self._response(content_type = 'application/json',
View
8 tests/regressiontests/urlpatterns_reverse/tests.py
@@ -1,7 +1,7 @@
"""
Unit tests for reverse URL lookups.
"""
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
@@ -405,8 +405,8 @@ def tearDown(self):
def test_urlconf(self):
response = self.client.get('/test/me/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'outer:/test/me/,'
- 'inner:/inner_urlconf/second_test/')
+ self.assertEqual(response.content, b'outer:/test/me/,'
+ b'inner:/inner_urlconf/second_test/')
response = self.client.get('/inner_urlconf/second_test/')
self.assertEqual(response.status_code, 200)
response = self.client.get('/second_test/')
@@ -422,7 +422,7 @@ def test_urlconf_overridden(self):
self.assertEqual(response.status_code, 404)
response = self.client.get('/second_test/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'outer:,inner:/second_test/')
+ self.assertEqual(response.content, b'outer:,inner:/second_test/')
def test_urlconf_overridden_with_null(self):
settings.MIDDLEWARE_CLASSES += (
Please sign in to comment.
Something went wrong with that request. Please try again.