diff --git a/tests/modeltests/files/tests.py b/tests/modeltests/files/tests.py index 565d4c8942..daf2209605 100644 --- a/tests/modeltests/files/tests.py +++ b/tests/modeltests/files/tests.py @@ -135,6 +135,6 @@ class FileTests(unittest.TestCase): def test_file_mode(self): # Should not set mode to None if it is not present. # See #14681, stdlib gzip module crashes if mode is set to None - file = SimpleUploadedFile("mode_test.txt", "content") + file = SimpleUploadedFile("mode_test.txt", b"content") self.assertFalse(hasattr(file, 'mode')) g = gzip.GzipFile(fileobj=file) diff --git a/tests/regressiontests/decorators/tests.py b/tests/regressiontests/decorators/tests.py index dceaa62abc..7dc36aa479 100644 --- a/tests/regressiontests/decorators/tests.py +++ b/tests/regressiontests/decorators/tests.py @@ -220,7 +220,7 @@ class MethodDecoratorTests(TestCase): self.assertEqual(getattr(Test.method, 'myattr2', False), True) self.assertEqual(Test.method.__doc__, 'A method') - self.assertEqual(Test.method.__func__.__name__, 'method') + self.assertEqual(Test.method.__name__, 'method') class XFrameOptionsDecoratorsTests(TestCase): diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index 41be31ccd7..89d754c58e 100644 --- a/tests/regressiontests/fixtures_regress/tests.py +++ b/tests/regressiontests/fixtures_regress/tests.py @@ -13,7 +13,7 @@ from django.db.models import signals from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature) from django.test.utils import override_settings -from django.utils.six import StringIO +from django.utils.six import PY3, StringIO from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget, Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3, @@ -244,7 +244,8 @@ class TestFixtures(TestCase): self.assertEqual( pre_save_checks, [ - ("Count = 42 ()", "Weight = 1.2 ()") + ("Count = 42 (<%s 'int'>)" % ('class' if PY3 else 'type'), + "Weight = 1.2 (<%s 'float'>)" % ('class' if PY3 else 'type')) ] ) finally: diff --git a/tests/regressiontests/forms/tests/models.py b/tests/regressiontests/forms/tests/models.py index 7687335b48..c351509cee 100644 --- a/tests/regressiontests/forms/tests/models.py +++ b/tests/regressiontests/forms/tests/models.py @@ -178,7 +178,7 @@ class RelatedModelFormTests(TestCase): class Meta: model=A - self.assertRaises(ValueError, ModelFormMetaclass, b'Form', (ModelForm,), {'Meta': Meta}) + self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta}) class B(models.Model): pass @@ -196,4 +196,4 @@ class RelatedModelFormTests(TestCase): class Meta: model=A - self.assertTrue(issubclass(ModelFormMetaclass(b'Form', (ModelForm,), {'Meta': Meta}), ModelForm)) + self.assertTrue(issubclass(ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta}), ModelForm)) diff --git a/tests/regressiontests/generic_views/base.py b/tests/regressiontests/generic_views/base.py index fc3dc05fd7..5296f6941a 100644 --- a/tests/regressiontests/generic_views/base.py +++ b/tests/regressiontests/generic_views/base.py @@ -69,7 +69,7 @@ class ViewTest(unittest.TestCase): def _assert_simple(self, response): self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'This is a simple view') + self.assertEqual(response.content, b'This is a simple view') def test_no_init_kwargs(self): """ diff --git a/tests/regressiontests/generic_views/dates.py b/tests/regressiontests/generic_views/dates.py index ad65fd9f10..808582a6a5 100644 --- a/tests/regressiontests/generic_views/dates.py +++ b/tests/regressiontests/generic_views/dates.py @@ -480,7 +480,7 @@ class DayArchiveViewTests(TestCase): def test_next_prev_context(self): res = self.client.get('/dates/books/2008/oct/01/') - self.assertEqual(res.content, "Archive for Oct. 1, 2008. Previous day is May 1, 2006") + self.assertEqual(res.content, b"Archive for Oct. 1, 2008. Previous day is May 1, 2006") def test_custom_month_format(self): res = self.client.get('/dates/books/2008/10/01/') diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index 0f61c2d840..ad0ce4197e 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -260,29 +260,29 @@ class HttpResponseTests(unittest.TestCase): def test_non_string_content(self): #Bug 16494: HttpResponse should behave consistently with non-strings r = HttpResponse(12345) - self.assertEqual(r.content, '12345') + self.assertEqual(r.content, b'12345') #test content via property r = HttpResponse() r.content = 12345 - self.assertEqual(r.content, '12345') + self.assertEqual(r.content, b'12345') def test_iter_content(self): r = HttpResponse(['abc', 'def', 'ghi']) - self.assertEqual(r.content, 'abcdefghi') + self.assertEqual(r.content, b'abcdefghi') #test iter content via property r = HttpResponse() r.content = ['idan', 'alex', 'jacob'] - self.assertEqual(r.content, 'idanalexjacob') + self.assertEqual(r.content, b'idanalexjacob') r = HttpResponse() r.content = [1, 2, 3] - self.assertEqual(r.content, '123') + self.assertEqual(r.content, b'123') #test retrieval explicitly using iter and odd inputs r = HttpResponse() - r.content = ['1', '2', 3, unichr(1950)] + r.content = ['1', '2', 3, '\u079e'] result = [] my_iter = r.__iter__() while True: @@ -297,8 +297,8 @@ class HttpResponseTests(unittest.TestCase): #with Content-Encoding header r = HttpResponse([1,1,2,4,8]) r['Content-Encoding'] = 'winning' - self.assertEqual(r.content, '11248') - r.content = [unichr(1950),] + self.assertEqual(r.content, b'11248') + r.content = ['\u079e',] self.assertRaises(UnicodeEncodeError, getattr, r, 'content') diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py index a48bb25d0b..62bd82f4a7 100644 --- a/tests/regressiontests/views/tests/shortcuts.py +++ b/tests/regressiontests/views/tests/shortcuts.py @@ -12,44 +12,44 @@ class ShortcutTests(TestCase): def test_render_to_response(self): response = self.client.get('/shortcuts/render_to_response/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'FOO.BAR..\n') + self.assertEqual(response.content, b'FOO.BAR..\n') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') def test_render_to_response_with_request_context(self): response = self.client.get('/shortcuts/render_to_response/request_context/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n') + self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') def test_render_to_response_with_mimetype(self): response = self.client.get('/shortcuts/render_to_response/mimetype/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'FOO.BAR..\n') + self.assertEqual(response.content, b'FOO.BAR..\n') self.assertEqual(response['Content-Type'], 'application/x-rendertest') def test_render(self): response = self.client.get('/shortcuts/render/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n') + self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') self.assertEqual(response.context.current_app, None) def test_render_with_base_context(self): response = self.client.get('/shortcuts/render/base_context/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'FOO.BAR..\n') + self.assertEqual(response.content, b'FOO.BAR..\n') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') def test_render_with_content_type(self): response = self.client.get('/shortcuts/render/content_type/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n') + self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') self.assertEqual(response['Content-Type'], 'application/x-rendertest') def test_render_with_status(self): response = self.client.get('/shortcuts/render/status/') self.assertEqual(response.status_code, 403) - self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n') + self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') def test_render_with_current_app(self): response = self.client.get('/shortcuts/render/current_app/')