title: Writing a Django unit test for a function with a HttpResponse
body: <p>I'm writing a unit test to check to see if the <strong>telecasts</strong> key is in the JSON data returned in this function (in my views.py):</p>
  
  <pre><code>def my_function(request, date1='', date2='', date3='', date4=''):
      ::some other functions...::
      return HttpResponse(data, content_type='application/json')
  </code></pre>
  
  <p>As you see, the JSON I want to check is sent via a HttpResponse as the variable <strong>data</strong></p>
  
  <p>This JSON data, when received on the front-end, is structured like:</p>
  
  <pre><code>{"records": [ {"program": "WWE ENTERTAINMENT", "telecasts": 201,...}, {..} ]
  </code></pre>
  
  <p>So this is how I'm trying to write the unit test, but I'm getting an error when I run it:</p>
  
  <pre><code>    def my_test(self):
      """Data returned has telecasts key"""
  
      request = self.client.get(
          '/apps/myapp/2014-08-01/2015-06-10/2016-01-13/2016-03-23/',
          {dictionary of optional parameters}
      )
  
      force_authenticate(request, user=self.user)
  
      response = my_function(
          request,
          '2014-08-01',
          '2015-06-10',
          '2016-01-13',
          '2016-03-23'
      )
  
      telecasts_check = response['records'][0]['telecasts']
      self.assertRaises(KeyError, lambda: telecasts_check)
  </code></pre>