mirror of https://github.com/django/django.git
[py3] Various minor syntax fixes in the test suite
This commit is contained in:
parent
7d0f883192
commit
6602103338
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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 (<type 'int'>)", "Weight = 1.2 (<type 'float'>)")
|
||||
("Count = 42 (<%s 'int'>)" % ('class' if PY3 else 'type'),
|
||||
"Weight = 1.2 (<%s 'float'>)" % ('class' if PY3 else 'type'))
|
||||
]
|
||||
)
|
||||
finally:
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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/')
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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/')
|
||||
|
|
Loading…
Reference in New Issue