Loading tests/handlers/tests.py +8 −3 Original line number Diff line number Diff line # coding: utf-8 from __future__ import unicode_literals from django.core.handlers.wsgi import WSGIHandler, WSGIRequest Loading @@ -5,6 +7,7 @@ from django.core.signals import request_started, request_finished from django.db import close_old_connections, connection from django.test import RequestFactory, TestCase, TransactionTestCase from django.test.utils import override_settings from django.utils.encoding import force_str from django.utils import six Loading Loading @@ -41,10 +44,12 @@ class HandlerTests(TestCase): def test_non_ascii_cookie(self): """Test that non-ASCII cookies set in JavaScript are properly decoded (#20557).""" environ = RequestFactory().get('/').environ raw_cookie = 'want="café"'.encode('utf-8') environ['HTTP_COOKIE'] = raw_cookie if six.PY2 else raw_cookie.decode('iso-8859-1') raw_cookie = 'want="café"' if six.PY3: raw_cookie = raw_cookie.encode('utf-8').decode('iso-8859-1') environ['HTTP_COOKIE'] = raw_cookie request = WSGIRequest(environ) self.assertEqual(request.COOKIES['want'], "café") self.assertEqual(request.COOKIES['want'], force_str("café")) class TransactionsPerRequestTests(TransactionTestCase): Loading Loading
tests/handlers/tests.py +8 −3 Original line number Diff line number Diff line # coding: utf-8 from __future__ import unicode_literals from django.core.handlers.wsgi import WSGIHandler, WSGIRequest Loading @@ -5,6 +7,7 @@ from django.core.signals import request_started, request_finished from django.db import close_old_connections, connection from django.test import RequestFactory, TestCase, TransactionTestCase from django.test.utils import override_settings from django.utils.encoding import force_str from django.utils import six Loading Loading @@ -41,10 +44,12 @@ class HandlerTests(TestCase): def test_non_ascii_cookie(self): """Test that non-ASCII cookies set in JavaScript are properly decoded (#20557).""" environ = RequestFactory().get('/').environ raw_cookie = 'want="café"'.encode('utf-8') environ['HTTP_COOKIE'] = raw_cookie if six.PY2 else raw_cookie.decode('iso-8859-1') raw_cookie = 'want="café"' if six.PY3: raw_cookie = raw_cookie.encode('utf-8').decode('iso-8859-1') environ['HTTP_COOKIE'] = raw_cookie request = WSGIRequest(environ) self.assertEqual(request.COOKIES['want'], "café") self.assertEqual(request.COOKIES['want'], force_str("café")) class TransactionsPerRequestTests(TransactionTestCase): Loading