Ticket #27895: patch.diff

File patch.diff, 2.8 KB (added by Aniruddha Maru, 8 years ago)

patch.diff

  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index 87b59af..d22b122 100644
    a b class Client(RequestFactory):  
    679679                    'Content-Type header is "{0}", not "application/json"'
    680680                    .format(response.get('Content-Type'))
    681681                )
    682             response._json = json.loads(response.content.decode(), **extra)
     682            response._json = json.loads(response.content.decode('utf-8'), **extra)
    683683        return response._json
    684684
    685685    def _handle_redirects(self, response, **extra):
  • tests/test_client_regress/tests.py

    diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
    index e110032..b3046d3 100644
    a b class RequestMethodStringDataTests(SimpleTestCase):  
    12061206            self.assertEqual(response['Content-Type'], content_type)
    12071207            self.assertEqual(response.json(), {'key': 'value'})
    12081208
     1209    def test_unicode_json(self):
     1210        response = self.client.get('/unicode_json_response/')
     1211        self.assertEqual(response.json(), {'峠': 'とうげ tōge "mountain pass"'})
     1212
    12091213    def test_json_multiple_access(self):
    12101214        response = self.client.get('/json_response/')
    12111215        self.assertIs(response.json(), response.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 854cdc3..91b300a 100644
    a b  
     1# -*- coding:utf-8 -*-
     2
    13import json
    24from urllib.parse import urlencode
    35
    def return_json_response(request):  
    111113    return JsonResponse({'key': 'value'}, **kwargs)
    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