mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and Jannis Leidel for the review.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
"""
|
||||
Regression tests for the Test Client, especially the customized assertions.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
@@ -12,7 +14,7 @@ from django.template import (TemplateDoesNotExist, TemplateSyntaxError,
|
||||
import django.template.context
|
||||
from django.test import Client, TestCase
|
||||
from django.test.client import encode_file, RequestFactory
|
||||
from django.test.utils import ContextList, override_settings
|
||||
from django.test.utils import ContextList, override_settings, str_prefix
|
||||
from django.template.response import SimpleTemplateResponse
|
||||
from django.http import HttpResponse
|
||||
|
||||
@@ -117,14 +119,14 @@ class AssertContainsTests(TestCase):
|
||||
"Unicode characters can be found in template context"
|
||||
#Regression test for #10183
|
||||
r = self.client.get('/test_client_regress/check_unicode/')
|
||||
self.assertContains(r, u'さかき')
|
||||
self.assertContains(r, 'さかき')
|
||||
self.assertContains(r, b'\xe5\xb3\xa0'.decode('utf-8'))
|
||||
|
||||
def test_unicode_not_contains(self):
|
||||
"Unicode characters can be searched for, and not found in template context"
|
||||
#Regression test for #10183
|
||||
r = self.client.get('/test_client_regress/check_unicode/')
|
||||
self.assertNotContains(r, u'はたけ')
|
||||
self.assertNotContains(r, 'はたけ')
|
||||
self.assertNotContains(r, b'\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8'))
|
||||
|
||||
def test_assert_contains_renders_template_response(self):
|
||||
@@ -488,11 +490,11 @@ class AssertFormErrorTests(TestCase):
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'email', 'Some error.')
|
||||
except AssertionError as e:
|
||||
self.assertIn("The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])", str(e))
|
||||
self.assertIn(str_prefix("The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [%(_)s'Enter a valid e-mail address.'])"), str(e))
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc')
|
||||
except AssertionError as e:
|
||||
self.assertIn("abc: The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])", str(e))
|
||||
self.assertIn(str_prefix("abc: The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [%(_)s'Enter a valid e-mail address.'])"), str(e))
|
||||
|
||||
def test_unknown_nonfield_error(self):
|
||||
"""
|
||||
@@ -784,7 +786,7 @@ class RequestMethodStringDataTests(TestCase):
|
||||
def test_post(self):
|
||||
"Request a view with string data via request method POST"
|
||||
# Regression test for #11371
|
||||
data = u'{"test": "json"}'
|
||||
data = '{"test": "json"}'
|
||||
response = self.client.post('/test_client_regress/request_methods/', data=data, content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, b'request method: POST')
|
||||
@@ -792,7 +794,7 @@ class RequestMethodStringDataTests(TestCase):
|
||||
def test_put(self):
|
||||
"Request a view with string data via request method PUT"
|
||||
# Regression test for #11371
|
||||
data = u'{"test": "json"}'
|
||||
data = '{"test": "json"}'
|
||||
response = self.client.put('/test_client_regress/request_methods/', data=data, content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, b'request method: PUT')
|
||||
@@ -853,7 +855,7 @@ class UnicodePayloadTests(TestCase):
|
||||
def test_simple_unicode_payload(self):
|
||||
"A simple ASCII-only unicode JSON document can be POSTed"
|
||||
# Regression test for #10571
|
||||
json = u'{"english": "mountain pass"}'
|
||||
json = '{"english": "mountain pass"}'
|
||||
response = self.client.post("/test_client_regress/parse_unicode_json/", json,
|
||||
content_type="application/json")
|
||||
self.assertEqual(response.content, json)
|
||||
@@ -861,7 +863,7 @@ class UnicodePayloadTests(TestCase):
|
||||
def test_unicode_payload_utf8(self):
|
||||
"A non-ASCII unicode data encoded as UTF-8 can be POSTed"
|
||||
# Regression test for #10571
|
||||
json = u'{"dog": "собака"}'
|
||||
json = '{"dog": "собака"}'
|
||||
response = self.client.post("/test_client_regress/parse_unicode_json/", json,
|
||||
content_type="application/json; charset=utf-8")
|
||||
self.assertEqual(response.content, json.encode('utf-8'))
|
||||
@@ -869,7 +871,7 @@ class UnicodePayloadTests(TestCase):
|
||||
def test_unicode_payload_utf16(self):
|
||||
"A non-ASCII unicode data encoded as UTF-16 can be POSTed"
|
||||
# Regression test for #10571
|
||||
json = u'{"dog": "собака"}'
|
||||
json = '{"dog": "собака"}'
|
||||
response = self.client.post("/test_client_regress/parse_unicode_json/", json,
|
||||
content_type="application/json; charset=utf-16")
|
||||
self.assertEqual(response.content, json.encode('utf-16'))
|
||||
@@ -877,7 +879,7 @@ class UnicodePayloadTests(TestCase):
|
||||
def test_unicode_payload_non_utf(self):
|
||||
"A non-ASCII unicode data as a non-UTF based encoding can be POSTed"
|
||||
#Regression test for #10571
|
||||
json = u'{"dog": "собака"}'
|
||||
json = '{"dog": "собака"}'
|
||||
response = self.client.post("/test_client_regress/parse_unicode_json/", json,
|
||||
content_type="application/json; charset=koi8-r")
|
||||
self.assertEqual(response.content, json.encode('koi8-r'))
|
||||
|
||||
Reference in New Issue
Block a user