﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33219	django.test.client missconversion of json with internal dicts	Caperutxa	nobody	"django.test.client is used to tests post resquest in a django restframework application with json as file content.

For basic json works : {'name': 'Mateu', 'number': 25}

But if the json has internal dictionaries it is transformed to an array:
From {'name': 'Mateu', 'number': 25, sales: {'Hubble':25, 'Web':4, 'telescope': 0}}
To <QueryDict: {'name': 'Mateu', 'number': 25, sales: ['Hubble', 'Web', 'telescope']}
Then it is not possible to iterate over all sales key-value pairs

Also, if in the code a sales list is requested, it give only the last value (in that case telescope)

sales = request.data['sales']  --> sales will be 'telescope' instead of an array at least

NOTE, that starting the real server and run a request via curl or via web browser, it works as expected (a json with internal dictionaries or arrays)

----

django-cors-headers         3.10.0    
django-extensions           3.1.3     
django-storages             1.11.1    
djangorestframework         3.12.4    
pytest-django               4.4.0

linux system (ubuntu)

----

Sample code (set the urls yourself)

Inside views

{{{
    @api_view(['POST']) 
    def store_iteration(request):
        print(request.data)
        print(request.data['sales'])
}}}

Inside tests

{{{
    class IterationsTestCase(TestCase):
        def setUp(self):
            self.client = Client()

        def test_fake_up(self):
            response = self.client.post('/api/test_it',
                              {'name': 'Mateu', 'number': 25, sales: {'Hubble':25, 'Web':4, 'telescope': 0}},
                              format='json')
}}}
"	Bug	closed	Testing framework	3.2	Normal	invalid	test.client, complex json		Unreviewed	0	0	0	0	0	0
