title: Mocking a function called in django form
body: <p>I have two modules.</p>
  
  <p>a.py</p>
  
  <pre><code>def get_resource(arg1, arg2):
     return Modelobject based on arg1 and arg2 or None
  </code></pre>
  
  <p>b.py (form)</p>
  
  <pre><code>from a import get_resource
  class A(forms.Form):
   arg1 = forms.CharField()
   arg2 = forms.CharField()
   def clean(self):
     res = get_resource(arg1, arg2)
     if res is None:
      validationerror
     else:
      cleaned_data.update(res_key=res)
  </code></pre>
  
  <p>Now I need to mock the get_resource part so that I donot need any database but I couldnot get it to work.</p>
  
  <p>Here is what I tried but it doesnot work. What am I doing wrong ?</p>
  
  <pre><code>class Test(TestCase):
    def test_form_a(self):
      with patch('b.get_resource') as mock_tool:
        mock_tool.return_value = MagicMock(spec=MusicModel)
        form_data = {'arg1': '1', 'arg2': 'Music'}
        form = A(data=form_data)
  </code></pre>
  
  <p>Also I tried side_effects with a function</p>
  
  <pre><code>def my_side_effect(*args, **kwargs):
    return value based on arg[0] and arg[1]
  
  mock_tool.side_effect = my_side_effect
  </code></pre>
  
  <p>Since I am quite novice at mock and testing, Can anyone show me right direction ?</p>