diff --git a/django/contrib/sitemaps/tests/generic.py b/django/contrib/sitemaps/tests/generic.py
index e392cbf909..f63c5bf6e7 100644
--- a/django/contrib/sitemaps/tests/generic.py
+++ b/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 @@ 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, """
+ self.assertEqual(response.content, b"""
%s
diff --git a/django/contrib/sitemaps/tests/http.py b/django/contrib/sitemaps/tests/http.py
index d71907e09a..5cff67c238 100644
--- a/django/contrib/sitemaps/tests/http.py
+++ b/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, """
+ self.assertEqual(response.content, b"""
%s/simple/sitemap-simple.xml
@@ -33,7 +33,7 @@ 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, """
+ self.assertEqual(response.content, b"""
%s/simple/sitemap-simple.xml
@@ -43,7 +43,7 @@ class HTTPSitemapTests(SitemapTestsBase):
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, """
+ self.assertEqual(response.content, b"""
%s/location/%snever0.5
@@ -52,7 +52,7 @@ class HTTPSitemapTests(SitemapTestsBase):
def test_simple_sitemap(self):
"A simple sitemap can be rendered"
response = self.client.get('/simple/sitemap.xml')
- self.assertEqual(response.content, """
+ self.assertEqual(response.content, b"""
%s/location/%snever0.5
@@ -64,7 +64,7 @@ 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, """
+ self.assertEqual(response.content, b"""
%s/location/%snever0.5
@@ -90,7 +90,7 @@ class HTTPSitemapTests(SitemapTestsBase):
# installed doesn't raise an exception
Site._meta.installed = False
response = self.client.get('/simple/sitemap.xml')
- self.assertEqual(response.content, """
+ self.assertEqual(response.content, b"""
http://testserver/location/%snever0.5
@@ -131,7 +131,7 @@ class HTTPSitemapTests(SitemapTestsBase):
Check that a cached sitemap index can be rendered (#2713).
"""
response = self.client.get('/cached/index.xml')
- self.assertEqual(response.content, """
+ self.assertEqual(response.content, b"""
%s/cached/sitemap-simple.xml
diff --git a/django/contrib/sitemaps/tests/https.py b/django/contrib/sitemaps/tests/https.py
index d4f9053fc8..34d992fc78 100644
--- a/django/contrib/sitemaps/tests/https.py
+++ b/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, """
+ self.assertEqual(response.content, b"""
%s/secure/sitemap-simple.xml
@@ -20,7 +22,7 @@ class HTTPSSitemapTests(SitemapTestsBase):
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, """
+ self.assertEqual(response.content, b"""
%s/location/%snever0.5
@@ -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, """
+ self.assertEqual(response.content, b"""
%s/simple/sitemap-simple.xml
@@ -43,7 +45,7 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
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, """
+ self.assertEqual(response.content, b"""
%s/location/%snever0.5
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index 399d2906a8..1d9c999f21 100644
--- a/tests/modeltests/test_client/models.py
+++ b/tests/modeltests/test_client/models.py
@@ -91,7 +91,7 @@ class ClientTest(TestCase):
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"
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 09be55baba..c86d35ca3e 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -787,7 +787,7 @@ class CustomModelAdminTest(AdminViewBasicTest):
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"""
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index 4ffca2d458..24cab64c10 100644
--- a/tests/regressiontests/cache/tests.py
+++ b/tests/regressiontests/cache/tests.py
@@ -1592,43 +1592,43 @@ class CacheMiddlewareTest(TestCase):
# 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 @@ class CacheMiddlewareTest(TestCase):
# ... 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(
diff --git a/tests/regressiontests/conditional_processing/models.py b/tests/regressiontests/conditional_processing/models.py
index d1a8ac605b..dacea34a83 100644
--- a/tests/regressiontests/conditional_processing/models.py
+++ b/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 @@ class ConditionalGet(TestCase):
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/')
diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
index 3c45b7a9d4..93919b95cd 100644
--- a/tests/regressiontests/templates/response.py
+++ b/tests/regressiontests/templates/response.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import os
import pickle
import time
@@ -29,16 +31,16 @@ class SimpleTemplateResponseTest(TestCase):
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 @@ class SimpleTemplateResponseTest(TestCase):
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 @@ class SimpleTemplateResponseTest(TestCase):
# 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 @@ class SimpleTemplateResponseTest(TestCase):
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 @@ class SimpleTemplateResponseTest(TestCase):
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 @@ class SimpleTemplateResponseTest(TestCase):
# 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 @@ class TemplateResponseTest(TestCase):
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',
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index 500a0e0327..207cc56488 100644
--- a/tests/regressiontests/urlpatterns_reverse/tests.py
+++ b/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 @@ class RequestURLconfTests(TestCase):
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 @@ class RequestURLconfTests(TestCase):
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 += (