diff --git a/rest_framework/test.py b/rest_framework/test.py index df5a5b3b3..dfec698ba 100644 --- a/rest_framework/test.py +++ b/rest_framework/test.py @@ -3,6 +3,10 @@ # Note that we import as `DjangoRequestFactory` and `DjangoClient` in order # to make it harder for the user to import the wrong thing without realizing. from __future__ import unicode_literals +try: + from urllib import unquote +except ImportError: + from urllib.parse import unquote import django from django.conf import settings from django.test.client import Client as DjangoClient @@ -169,3 +173,16 @@ if django.VERSION >= (1, 4): class APILiveServerTestCase(testcases.LiveServerTestCase): client_class = APIClient + + +class IEClient(DjangoClient): + def request(self, **kwargs): + try: + kwargs['QUERY_STRING'] = unquote(kwargs['QUERY_STRING']) + except: + pass + return super(IEClient, self).request(**kwargs) + + +class IETestCase(testcases.TestCase): + client_class = IEClient diff --git a/rest_framework/tests/test_request.py b/rest_framework/tests/test_request.py index c0b50f330..e32a50b88 100644 --- a/rest_framework/tests/test_request.py +++ b/rest_framework/tests/test_request.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ Tests for content parsing, and form-overloaded content parsing. """ @@ -19,7 +20,7 @@ from rest_framework.parsers import ( from rest_framework.request import Request, Empty from rest_framework.response import Response from rest_framework.settings import api_settings -from rest_framework.test import APIRequestFactory, APIClient +from rest_framework.test import APIRequestFactory, APIClient, IETestCase from rest_framework.views import APIView from rest_framework.compat import six from io import BytesIO @@ -272,6 +273,9 @@ class MockView(APIView): return Response(status=status.INTERNAL_SERVER_ERROR) + def get(self, request): + return Response({}) + urlpatterns = patterns('', (r'^$', MockView.as_view()), ) @@ -345,3 +349,12 @@ class TestAuthSetter(TestCase): request = Request(factory.get('/')) request.auth = 'DUMMY' self.assertEqual(request.auth, 'DUMMY') + + +class TestQueryString(IETestCase): + urls = 'rest_framework.tests.test_request' + + def test_query_string_utf8(self): + qs = {'q': 'pølse'} + response = self.client.get('/', qs) + self.assertEqual(status.HTTP_200_OK, response.status_code)