Ticket #27895: patch_stable:1.10.x.diff

File patch_stable:1.10.x.diff, 2.8 KB (added by Aniruddha Maru, 7 years ago)

patch_stable/1.10.x.diff

  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index 2b5840b..7b4ab63 100644
    a b class Client(RequestFactory):  
    683683                'Content-Type header is "{0}", not "application/json"'
    684684                .format(response.get('Content-Type'))
    685685            )
    686         return json.loads(response.content.decode(), **extra)
     686        return json.loads(response.content.decode('utf-8'), **extra)
    687687
    688688    def _handle_redirects(self, response, **extra):
    689689        "Follows any redirects by requesting responses from the server using GET."
  • tests/test_client_regress/tests.py

    diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
    index bb6d93b..2472fb3 100644
    a b class RequestMethodStringDataTests(SimpleTestCase):  
    12041204        response = self.client.get('/json_response/')
    12051205        self.assertEqual(response.json(), {'key': 'value'})
    12061206
     1207    def test_unicode_json(self):
     1208        response = self.client.get('/unicode_json_response/')
     1209        self.assertEqual(response.json(), {'峠': 'とうげ tōge "mountain pass"'})
     1210
     1211
    12071212    def test_json_wrong_header(self):
    12081213        response = self.client.get('/body/')
    12091214        msg = 'Content-Type header is "text/html; charset=utf-8", not "application/json"'
  • tests/test_client_regress/urls.py

    diff --git a/tests/test_client_regress/urls.py b/tests/test_client_regress/urls.py
    index 9821ea9..fcefeef 100644
    a b urlpatterns = [  
    3131    url(r'^check_unicode/$', views.return_unicode),
    3232    url(r'^check_binary/$', views.return_undecodable_binary),
    3333    url(r'^json_response/$', views.return_json_response),
     34    url(r'^unicode_json_response/$', views.return_unicode_json_response),
    3435    url(r'^parse_unicode_json/$', views.return_json_file),
    3536    url(r'^check_headers/$', views.check_headers),
    3637    url(r'^check_headers_redirect/$', RedirectView.as_view(url='/check_headers/')),
  • tests/test_client_regress/views.py

    diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py
    index abbf7e1..9195d7b 100644
    a b  
     1# -*- coding:utf-8 -*-
     2
    13import json
    24
    35from django.conf import settings
    def return_json_response(request):  
    111113    return JsonResponse({'key': 'value'})
    112114
    113115
     116def return_unicode_json_response(request):
     117    content_type = request.GET.get('content_type')
     118    kwargs = {'content_type': content_type} if content_type else {}
     119    kwargs['json_dumps_params'] = {'ensure_ascii': False}
     120    return JsonResponse({'峠': 'とうげ tōge "mountain pass"'}, **kwargs)
     121
     122
    114123def return_json_file(request):
    115124    "A view that parses and returns a JSON string as a file."
    116125    match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
Back to Top