I have a problem very similar to Django's Querydict: weird behavior: empty POST words in one key and Unit testing Django JSON View . However, none of the questions / answers in these threads really indicate the task that I have. I am trying to use a Django test client to send a request with a nested JSON object (which works well with JSON objects with values ββother than JSON).
Attempt # 1: Here is my initial code:
response = c.post('/verifyNewMobileUser/', {'phoneNumber': user.get_profile().phone_number, 'pinNumber': user.get_profile().pin, 'deviceInfo': {'deviceID': '68753A44-4D6F-1226-9C60-0050E4C00067', 'deviceType': 'I'}})
As you can see, I have a nested JSON object in my request data. However, this is what the .POST request looks like:
<QueryDict: {u'phoneNumber': [u'+15551234567'], u'pinNumber': [u'4171'], u'deviceInfo': [u'deviceType', u'deviceID']}>
Attempt # 2: Then I tried to add the value of the content-type parameter as follows:
response = c.post('/verifyNewMobileUser/', {'phoneNumber': user.get_profile().phone_number, 'pinNumber': user.get_profile().pin, 'deviceInfo': {'deviceID': '68753A44-4D6F-1226-9C60-0050E4C00067', 'deviceType': 'I'}}, 'application/json')
And what am I getting now for the .POST request -
<QueryDict: {u"{'deviceInfo': {'deviceType': 'I', 'deviceID': '68753A44-4D6F-1226-9C60-0050E4C00067'}, 'pinNumber': 5541, 'phoneNumber': u' 15551234567'}": [u'']}>
All I want to do is specify the attached dict file for my request data. Is there an easy way to do this?