Fix APIClient.get() when path contains unicode arguments by diox · Pull Request #4458 · encode/django-rest-framework (original) (raw)

If the URL contains unicode arguments, APIClient and APIRequestFactory .get() cause an exception to be raised when the request query dict is accessed, because we end up with an unicode QUERY_STRING and that's not what django expects.

Without this patch (which is adapted from django), the test I've added fails with:

tests/test_testing.py:252: in test_request_factory_url_arguments_with_unicode
    self.assertEqual(dict(request.GET), {'demo': [u'testé']})
../../.virtualenvs/drf-testing/local/lib/python2.7/site-packages/django/utils/functional.py:35: in __get__
    res = instance.__dict__[self.name] = self.func(instance)
../../.virtualenvs/drf-testing/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py:124: in GET
    return http.QueryDict(raw_query_string, encoding=self._encoding)
../../.virtualenvs/drf-testing/local/lib/python2.7/site-packages/django/http/request.py:398: in __init__
    value = value.decode(encoding)
../../.virtualenvs/drf-testing/lib/python2.7/encodings/utf_8.py:16: in decode
    return codecs.utf_8_decode(input, errors, True)
E   UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128)