title: How to unittest that a django model method called with unittest.mock?
body: <p>I'm having a hard time understanding how to use <code>unittest.mock</code> library.<br>
  I have this model:</p>
  
  <pre><code>from django.db import models
  
  class Data(models.Model):
      field1 = models.CharField(max_length=50)
      field2 = models.CharField(max_length=50)
      // ... more fields
  
      _PASSWORD_KEY = 'some_random_password_key'
      _password = models.CharField(max_length=255, db_column='password')
  
      def _set_password(self, raw_password):
          """
          Encode raw_password and save as self._password
          """
          // do some Vigenère magic
  
      def _get_password(self):
          """
          Decode encrypted password with _PASSWORD_KEY and return the original.
          """
          return raw_password
  
      password = property(_get_password, _set_password)
  </code></pre>
  
  <p>I want to test that <code>_set_password</code> is called when I do <code>data = Data(password='password')</code>.<br>
  I manually confirmed it is called, but this unit test fails (which I brought from the examples of unittest.mock documentation):</p>
  
  <pre><code>from mock import patch
  from someapp.models import Data
  
  def test_set_password_is_called(self):
      with patch.object(Data, '_set_password') as password_method:
          data = Data(password='password123')
  
      password_method.assert_called_once_with('password123')
  </code></pre>
  
  <p>With this message:</p>
  
  <pre><code>Failure
  Traceback (most recent call last):
    File "/Users/walkman/project/someapp/tests.py", line 75, in test_set_password_is_called
      password_method.assert_called_once_with('password123')
    File "/usr/local/lib/python2.7/site-packages/mock.py", line 845, in assert_called_once_with
      raise AssertionError(msg)
  AssertionError: Expected to be called once. Called 0 times.
  </code></pre>
  
  <p>What do I do wrong ?</p>