def test_unit_editform(self): """ This test case is for EditForm in auth_forms and test if it can correctly edit user information as the user intended. """ with patch('user_auth.auth_forms.forms') as form: form.CharField = MagicMock(return_value="CharField") form.ImageField = MagicMock(return_value="ImageField") ins = EditForm() ins.cleaned_data = MagicMock(return_value="cleaned_data") with patch('user_auth.auth_forms.UserInfo') as userinfo: userinfo.objects.get = MagicMock() # need to mock user user = MagicMock() # call the function. ins.process(user) # check self.assertTrue(userinfo.objects.get.called) self.assertTrue(user.save.called)