title: Django - Mocking the save method on a model
body: <p>I'm still here with my beginner questions about Django unit tests ^^</p>
  
  <p>I'm trying to test that the save function of a model was called, without actually call the save.</p>
  
  <p>Here is the method i want to test :</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth import models as auth_model
  from allauth.socialaccount import models as allauth_model
  
  class KangaUserManager(models.Manager):
      def create(self, username, email, password, last_name, first_name, request, registered=True, send_confirmation=True):
          kanga_user = KangaUser()
          kanga_user.user = auth_model.User.objects.create_user(
              username=username,
              email=email,
              password=password,
              first_name=first_name,
              last_name=last_name
          )
          kanga_user.preferred_language = translation.get_language()
          kanga_user.registered = registered
          kanga_user.save()
  
          return kanga_user
  </code></pre>
  
  <p>Here is the test</p>
  
  <pre><code>@mock.patch('model.models.KangaUser')
  @mock.patch('django.contrib.auth.models.User')
  def test_create(self, UserMock, KangaUserMock):
      # Mocking configuration
      # User
      UserMock.objects = mock.MagicMock()
      UserMock.objects.create_user = mock.MagicMock()
      user_return_value = User(id=1)
      UserMock.objects.create_user.return_value = user_return_value
  
       # Test
      kangauser_manager = models.KangaUserManager()
      kanga_user = kangauser_manager.create(self.username, self.email, self.password, self.last_name, self.first_name, self.request, self.registered, self.send_confirmation)
  
      # Checks
      # create_user called with good parameters
      UserMock.objects.create_user.assert_called_with(username=self.username, email=self.email, password=self.password, first_name=self.first_name, last_name=self.last_name)
      # KangaUser 
      self.assertTrue(models.KangaUser.save.called)
  </code></pre>
  
  <p>The first test (UserMock.objects.create_user.assert_called_with) is ok, but for the second, I always end up having "AssertionError: False is not true"</p>