title: Unit-testing Python: Mocking function calls inside function
body: <p>I have a django view like this</p>
  
  <pre><code># Django view
  
  from some_module import f2
  def f1(request, version):
      # some code
  
      f2(**kargs)
  
      # more code
      return HTTPResponse(response)
  </code></pre>
  
  <p>The function f2 is in another module</p>
  
  <pre><code># some_module
  def f2(**kargs):
      # some code
  </code></pre>
  
  <p>The Django view is part of an API so, the request and response are in json</p>
  
  <p>How do I :</p>
  
  <ol>
  <li>write a unit test for this function while mocking the request</li>
  <li>mock f2, which is a database based function and avoid database connections entirely</li>
  </ol>
  
  <p>EDIT:</p>
  
  <p>The database I am using is Cassandra, so I cannot use django.db </p>