title: django: Testing POST-based views with json objects
body: <p>I have a django application with several views that accept json objects via POST requests. The json objects are medium-complex with a few layers of nesting, so I'm using the json library to parse raw_post_data, as shown here:</p>
  
  <pre><code>def handle_ajax_call(request):
      post_json = json.loads(request.raw_post_data)
  
      ... (do stuff with json query)
  </code></pre>
  
  <p>Next, I want to write tests for these views.  Unfortunately, I can't figure out how to pass the json object to the Client.  Here's a simplest-case version of my code:</p>
  
  <pre><code>def test_ajax_call(self):
      c = Client()
      call_command('loadfixtures', 'temp-fixtures-1') #Custom command to populate the DB
  
      J = {
        some_info : {
          attr1 : "AAAA",
          attr2 : "BBBB",
          list_attr : [ "x", "y", "z" ]
        },
        more_info : { ... },
        info_list : [ 1, 22, 23, 24, 5, 26, 7 ]
      }
  
      J_string = json.dumps(J)
      response = c.post('/ajax/call/', data=J_string )
  </code></pre>
  
  <p>When I run the test, it fails with:</p>
  
  <pre><code>AttributeError: 'str' object has no attribute 'items'
  </code></pre>
  
  <p>How can I pass the JSON object in the Client.post method?</p>