如何检查是否在模拟方法中调用函数?

时间:2016-09-13 21:42:21

标签: python django python-2.7 unit-testing django-models

AuthUser是一个包含delete方法的类。 我想测试模拟删除方法是否在给定方法的参数的情况下调用函数。

@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)

1 个答案:

答案 0 :(得分:0)

library(tidyr)
df %>% extract(Postcodes, "Postcodes", "(.*)..$")
#  Postcodes
#1      AB46
#2     AR148
#3       D49
#4      CB39