title: How to send requests with JSON in unit tests
body: <p>I have code within a Flask application that uses JSONs in the request, and I can get the JSON object like so:</p>
  
  <pre><code>Request = request.get_json()
  </code></pre>
  
  <p>This has been working fine, however I am trying to create unit tests using Python's unittest module and I'm having difficulty finding a way to send a JSON with the request.</p>
  
  <pre><code>response=self.app.post('/test_function', 
                         data=json.dumps(dict(foo = 'bar')))
  </code></pre>
  
  <p>This gives me:</p>
  
  <pre><code>&gt;&gt;&gt; request.get_data()
  '{"foo": "bar"}'
  &gt;&gt;&gt; request.get_json()
  None
  </code></pre>
  
  <p>Flask seems to have a JSON argument where you can set json=dict(foo='bar') within the post request, but I don't know how to do that with the unittest module.</p>