I experience really strange behavior when using a test client in django.
I am using POST
to send data to my django application. I usually do this from an iPhone application and / or html test form. On the server side, as I understand it:
def handle_query(request): print request q = con.QueryLog() q.ID = request.POST.get('ID', '') q.device = request.POST.get('device-model', '') ....
This print statement looks as you would expect, i.e. each parameter in the mail request turns into a key in the dictionary:
POST: QueryDict: {u'app-version ': [u'3.0'], u'server-version ': [u'v3d0'],
However, I started to write some tests using the Django test client, and no matter what I try, the dictionary of POST parameters that I send in the mail request is grouped into one key in QueryDict
. Let me illustrate with some code:
class SearchTest (TestCase): def setUp (self): pass
def test_search(self): request = HttpRequest() data = '{"amzn_locale": "com"}'
The same print statement on the server side shows an inexplicable grouping of the dictionary into a string:
POST: QueryDict: {u'{"amzn_locale":"com"}': [u'']}>,
If I install data into a real dictionary, the same
data = {"amzn_locale": "com"}
Setting request._raw_post_data does not change anything. Also does not change
content_type='application/json'
Any help would be greatly appreciated. From this stackoverflow question, it seems like I'm not the first to come across this . Iphone Json POST request to Django server creates QueryDict in QueryDict