title: Django unittest and mocking the requests module
body: <p>I am new to Mock and am writing a unit test for this function:</p>
  
  <pre><code># utils.py
  import requests    
  
  def some_function(user):
      payload = {'Email': user.email}
      url = 'http://api.example.com'
      response = requests.get(url, params=payload)      
  
      if response.status_code == 200:
         return response.json()
      else:
          return None
  </code></pre>
  
  <p>I am using <a href="http://www.voidspace.org.uk/python/mock/index.html" rel="noreferrer">Michael Foord's Mock</a> library as part of my unit test and am having difficulty mocking the <code>response.json()</code> to return a json structure. Here is my unit test:</p>
  
  <pre><code># tests.py
  from .utils import some_function
  
  class UtilsTestCase(unittest.TestCase):
      def test_some_function(self):
          with patch('utils.requests') as mock_requests:
              mock_requests.get.return_value.status_code = 200
              mock_requests.get.return_value.content = '{"UserId":"123456"}'
              results = some_function(self.user)
              self.assertEqual(results['UserId'], '123456')
  </code></pre>
  
  <p>I have tried numerous combinations of different mock settings after reading the docs with no luck. If I print the <code>results</code> in my unit test it always displays the following instead of the json data structure I want:</p>
  
  <pre><code>&lt;MagicMock name=u'requests.get().json().__getitem__().__getitem__()' id='30315152'&gt;
  </code></pre>
  
  <p>Thoughts on what I am doing wrong?</p>