Fix APIClient.get() when path contains unicode arguments (#4458)

This commit is contained in:
Mathieu Pillard 2016-09-02 18:00:03 +02:00 committed by Tom Christie
parent 80bd3b9722
commit 07efbdb45e
2 changed files with 13 additions and 3 deletions

View File

@ -79,10 +79,13 @@ class APIRequestFactory(DjangoRequestFactory):
r = {
'QUERY_STRING': urlencode(data or {}, doseq=True),
}
# Fix to support old behavior where you have the arguments in the url
# See #1461
if not data and '?' in path:
r['QUERY_STRING'] = path.split('?')[1]
# Fix to support old behavior where you have the arguments in the
# url. See #1461.
query_string = force_bytes(path.split('?')[1])
if six.PY3:
query_string = query_string.decode('iso-8859-1')
r['QUERY_STRING'] = query_string
r.update(extra)
return self.generic('GET', path, **r)

View File

@ -245,3 +245,10 @@ class TestAPIRequestFactory(TestCase):
self.assertEqual(dict(request.GET), {'demo': ['test']})
request = factory.get('/view/', {'demo': 'test'})
self.assertEqual(dict(request.GET), {'demo': ['test']})
def test_request_factory_url_arguments_with_unicode(self):
factory = APIRequestFactory()
request = factory.get('/view/?demo=testé')
self.assertEqual(dict(request.GET), {'demo': ['testé']})
request = factory.get('/view/', {'demo': 'testé'})
self.assertEqual(dict(request.GET), {'demo': ['testé']})