title: Can't mock a third party api call
body: <p>I have a view that perform a third party API call:</p>
  <pre class="lang-py prettyprint-override"><code>from .atoca_api_calls import atoca_api_call
  
  def atoca_api_call_view(request):
    # some code
    data = atoca_api_call(**params)  # the actual API call happens in this func
    # some code  
  </code></pre>
  <p>My intention is to mock just the <code>atoca_api_call()</code> func and not the whole view.</p>
  <pre class="lang-py prettyprint-override"><code>class AtocaTestCase(TestCase):
      def setUp(self):
        # some code
  
      @patch('crm.atoca_api_calls.atoca_api_call')
      def test_atoca_call(self, mock_atoca_api_call):
        mock_atoca_api_call.return_value = MagicMock(
          status_code=200,
          response=some_json # just returns some json
        )
        url = reverse('crm:atoca-api-call')  # url related to `atoca_api_call_view`
        response = self.client.post(url, some_others_params)
        # various asserts
  
  </code></pre>
  <p>The test works fine but <code>atoca_api_call()</code> is not mocked.
  I'm aware of <a href="https://docs.python.org/3/library/unittest.mock.html#where-to-patch" rel="nofollow noreferrer">where to patch</a>:</p>
  <pre><code>@patch('crm.views.atoca_api_call', autospec=True) 
  </code></pre>
  <p>Raises a <code>ValueError</code>:</p>
  <pre><code>ValueError: Failed to insert expression &quot;&lt;MagicMock name='mock.__getitem__().__getitem__().__getitem__()().resolve_expression()' id='140048216397424'&gt;&quot; on crm.Company.atoca_id. F() expressions can only be used to update, not to insert.
  </code></pre>
  <p>It's probably a simple issue I don't catch for inexperience, any help is really appreciated.</p>