我創建Python函數通過如下LDAP對象搜索:如何將一個ldap對象轉換爲一個Python函數中的整數?
def my_search(l, baseDN, searchScope=ldap.SCOPE_ONELEVEL, searchFilter="objectClass=*", retrieveAttributes=None):
logger.console("Reachedhere")
try:
logger.console("Reachedhereinsidetry\n")
ldap_result_id = l.search_s(baseDN,searchScope,searchFilter,retrieveAttributes)
logger.console("Gotresult\n")
所以我現在調用這個關鍵字在機器人測試用例像這樣:
*** Settings ***
Documentation This testsuite checks the LDAP functionalities of DB nodes.
Resource ../../COMMON/Libraries/SDL-DB-COMMON-LIB.txt
Library ../../COMMON/Libraries/pythonldap.py
*** Test Cases ***
Perform Ldap Operations
${ldapObj} ldapopen ${DB_1_EXT_APP_IP}
Log to Console ${ldapObj}
${SearchReturn} my_search ${ldapObj} "uid=5000000,ds=CRIBER,o=D,dc=CN" ldap.SCOPE_ONELEVEL "objectClass=*" None
當我運行這個TC,它拋出我的錯誤,像這樣的搜索:
TypeError: an integer is required
的錯誤,絕對是「ldap_result_id = l.search_s(基本DN,SearchScope的,searchFilter,檢索屬性)「行,因爲我可以打印先前的評論。
這裏有什麼問題?
這裏的問題是無法通過Robot從上面傳遞的作用域級別。我所做的更改是:
def my_search(l, baseDN, searchScopeLevel, searchFilter="objectClass=*", retrieveAttributes=None):
try:
if searchScopeLevel == 'ONE':
searchScope=ldap.SCOPE_ONELEVEL
elif searchScopeLevel == 'BASE':
searchScope=ldap.SCOPE_BASE
elif searchScopeLevel == 'SUB':
searchScope=ldap.SCOPE_SUBTREE
ldap_result_id = l.search(baseDN,searchScope,searchFilter,retrieveAttributes)
機器人TC的變化:
*** Test Cases ***
Perform Ldap Operations
${ldapObj} ldapopen ${DB_1_EXT_APP_IP}
${SearchReturn} my_search ${ldapObj} uid=205000000,ds=CRIBER,o=DEFT,dc=C ONE objectClass=*
而且問題得到解決。 :)
請至少在my_search關鍵字中提供一些細節,至少在哪裏會引起錯誤猜測。由於這裏存在字符限制,將會出現明顯問題的答案,但以這種細節爲準,這是一個瘋狂的猜測。 – Todor