调通用例;
完善引用变量关键字;
This commit is contained in:
@@ -4,6 +4,8 @@ Library RequestsLibrary
|
||||
Resource ../../../03-Variable/BifangApiVariable.txt
|
||||
Resource ../../common/ApiHttpRequest.robot
|
||||
Variables ../../../05-Other/variable/policy/apipolicyrequesttest.py
|
||||
Library REST http://${host}:${port}
|
||||
Library json
|
||||
|
||||
*** Variables ***
|
||||
${policyapiv2} /v2/policy/compile
|
||||
@@ -29,20 +31,24 @@ GetPolicyData
|
||||
[Return] ${returnValue}
|
||||
|
||||
AddPolicyData
|
||||
[Arguments] ${data} ${returnKey}
|
||||
[Arguments] ${returnData} ${data}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
|
||||
${response} PostHttpRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
${policyIds} Run Keyword If "${returnData}" == "1" GetPolicyIds ${response}
|
||||
... ELSE Create List
|
||||
${rescode} Set Variable ${response['code']}
|
||||
[Return] ${rescode} ${policyIds}
|
||||
|
||||
AddObjectData
|
||||
[Arguments] ${data} ${returnKey}
|
||||
[Arguments] ${returnData} ${data}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostHttpRequestBase ${hosturl} ${objectapiv1} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
${objectIds} Run Keyword If "${returnData}" == "1" GetObjectIds ${response}
|
||||
... ELSE Create List
|
||||
${rescode} Set Variable ${response['code']}
|
||||
[Return] ${rescode} ${objectIds}
|
||||
|
||||
AddPolicyBase
|
||||
[Arguments] ${host} ${api} ${header} ${body}
|
||||
@@ -59,3 +65,111 @@ AddPolicyCode
|
||||
${code} get from dictionary ${response} code
|
||||
[Return] ${code}
|
||||
|
||||
|
||||
GetObjectIds
|
||||
[Documentation]
|
||||
... 获取结果中的对象ID
|
||||
[Arguments] ${value}
|
||||
Log Call Get-ObjectIds
|
||||
${objectIds} Create List
|
||||
${objectIdsTemp} Set Variable ${EMPTY}
|
||||
${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
|
||||
Return From Keyword If "${return}"=="FAIL" ${objectIdsTemp}
|
||||
|
||||
FOR ${object} IN @{value['data']['objectList']}
|
||||
Append To List ${objectIds} ${object['objectId']}
|
||||
END
|
||||
${json} json.Dumps ${objectIds} ensure_ascii=False
|
||||
${json} Remove String ${json} [
|
||||
${json} Remove String ${json} ]
|
||||
[Return] ${json}
|
||||
|
||||
GetPolicyIds
|
||||
[Arguments] ${value}
|
||||
[Documentation] 获取结果中的策略ID
|
||||
${policyIds} Create List
|
||||
FOR ${policy} IN @{value['data']['policyList']}
|
||||
#${policyIdList} Create List ${policy['policyId']}
|
||||
#${policyObj} Create Dictionary policyType=${policy['policyType']} policyIds=${policyIdList}
|
||||
#Append To List ${policyIds} ${policyObj}
|
||||
Append To List ${policyIds} ${policy['policyId']}
|
||||
END
|
||||
${len} Get Length ${policyIds}
|
||||
${policyIds} Run Keyword If ${len}==1 Set Variable ${policyIds[0]}
|
||||
... ELSE Set Variable ${policyIds}
|
||||
[Return] ${policyIds}
|
||||
|
||||
|
||||
DelPolicysAndGroupObjects
|
||||
[Arguments] ${policyids} ${objectids}
|
||||
#引用此关键字,${objectids}参数必须是双层列表,eg:['[1]','[2,3]','[4,5,6,7]']
|
||||
#删除和对象
|
||||
#删除策略
|
||||
log toDeletePolicy_DelPolicys
|
||||
${listlenth}= Get Length ${policyids}
|
||||
Run Keyword If "${listlenth}"=="0" log no Policys to del
|
||||
... ELSE DelPolicys ${policyids}
|
||||
#删除对象
|
||||
log todeleteobj_DelGroupObjects
|
||||
Run Keyword If "${objectids}"=="${EMPTY}" log no Objects to del
|
||||
... ELSE DelGroupObjects ${objectids}
|
||||
|
||||
DelPolicys
|
||||
[Arguments] ${policyids}
|
||||
${listlenth}= Get Length ${policyids}
|
||||
FOR ${var} IN RANGE ${listlenth}
|
||||
log ${var}
|
||||
DelPolicy ${policyids}[${var}]
|
||||
END
|
||||
|
||||
DelPolicy
|
||||
[Arguments] ${body}
|
||||
#删除策略
|
||||
log toDeletePolicy_DeletePolicyDeletePolicy
|
||||
${response} DeleteRequestBase /${version}/policy/compile ${body}
|
||||
#{"policyType":"tsg_security","policyIds":[${policyids}]}
|
||||
${response_code} Get From Dictionary ${response} code
|
||||
Should Be Equal As Strings ${response_code} 200
|
||||
${response} Convert to String ${response}
|
||||
log ${response}
|
||||
#Should Be Equal As Strings ${response} {'code': 200, 'msg': 'Success', 'success': True}
|
||||
|
||||
DelGroupObjects
|
||||
[Arguments] ${objectids}
|
||||
FOR ${var} IN @{objectids}
|
||||
log ${var}
|
||||
DelGroupObject ${var}
|
||||
END
|
||||
|
||||
DelGroupObject
|
||||
[Arguments] ${objectids}
|
||||
#删除对象
|
||||
log todeleteobj
|
||||
${response} DeleteRequestBase /${version}/policy/object {"objectIds":${objectids}}
|
||||
${response_code} Get From Dictionary ${response} code
|
||||
Should Be Equal As Strings ${response_code} 200
|
||||
${response} Convert to String ${response}
|
||||
log ${response}
|
||||
|
||||
|
||||
DelPolicyAndObjectAndProfile
|
||||
[Arguments] ${policyids} ${objectids} ${profiles}
|
||||
DelPolicysAndGroupObjects ${policyids} ${objectids}
|
||||
DelProfiles ${profiles}
|
||||
|
||||
DelProfiles
|
||||
[Arguments] ${profiles}
|
||||
FOR ${profile} IN @{profiles}
|
||||
Run Keyword If "${profile}"!="" and ${profile}!="${EMPTY}" DelProfile ${profile}[typeUrl] ${profile}[profileIds]
|
||||
END
|
||||
|
||||
DelProfile
|
||||
[Arguments] ${typeUrl} ${profileIds}
|
||||
#删除对象
|
||||
log DeleteProfile
|
||||
${response} DeleteRequestBase /${version}/policy/profile/${typeUrl} {"profileIds":[${profileIds}]}
|
||||
${response_code} Get From Dictionary ${response} code
|
||||
Should Be Equal As Strings ${response_code} 200
|
||||
#Integer ${response_code} 200
|
||||
${response} Convert to String ${response}
|
||||
log ${response}
|
||||
Reference in New Issue
Block a user