Python Mock 补丁 ldap3 搜索响应

问题描述

我正在尝试模拟以下函数,但我不确定如何模拟连接响应:

def get_user_res(user,pass):
    res = None
    server = Server('my_server')
    connnection = Connection(server,user,pass,strategy=SAFE_SYNC,auto_bind=True)
    if connection.bind():
        connection.search(search_base,search_filter,SUBTREE)
        res = connection.response
        connection.unbind()
    return res
@mock.patch("ldap3.Server")
@mock.patch("ldap3.Connection.response")
def test_get_user_res(mock_connection,mock_server):
    mock_connection.return_value = ""
    retrived_res = get_user_res("fake_user","fake_password")
    expected_res = ""
    assert retrived_res == expected_res

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)