简体   繁体   中英

How do I check if a function is called in a mock method?

AuthUser is a class which contains the delete method. I want to test if the mock delete method calls a function, given the arguments for the method.

@mock.patch.object(AuthUser, 'delete')
@mock.patch('oscadmin.common.oscp.deactivate_user')
def test_delete(self, deactivate_user_mock, delete_mock):
    """Test the delete() method in AuthUser"""
    authUserObject = mock.Mock()
    authUserObject.oscp_id = 4

    """If delete_from_oscp = True && oscp_id isset"""
    delete_mock(self, True, authUserObject, mock.Mock())
    self.assertTrue(authUserObject.oscp_id)
delete_mock.method_expected_to_be_called.assert_called_once_with(args, kwargs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM