Fixed tests introduced in previous commit on Python 2. Refs #20557.

This commit is contained in:
Aymeric Augustin 2013-09-07 10:43:44 -05:00
parent 8aaca651cf
commit f5add4712f
1 changed files with 8 additions and 3 deletions

View File

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