调通用例;

完善引用变量关键字;
This commit is contained in:
dongxiaoyan
2020-12-25 15:10:10 +08:00
parent d1190f48f8
commit 2991afcf3b
3 changed files with 154 additions and 18 deletions

View File

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

View File

@@ -1,10 +1,10 @@
*** Settings ***
Test Teardown DeletePolicyAndGroupObject ${policyIds} ${objectIds}
Test Teardown DelPolicysAndGroupObjects ${policyIds} ${objectIds}
Resource ../../common/ApiHttpRequest.robot
Resource ../../common/Util.robot
Resource ApiPolicyRequest.robot
Variables ../../../05-Other/variable/policy/apipolicyrequesttest.py
Resource ../../tsg_bfapi/PolicyObject.robot
#Resource ../../tsg_bfapi/PolicyObject.robot
*** Variables ***
@@ -18,16 +18,38 @@ Test-GetRequestResposeCodePrivate
Test-AddPolicyData
[Tags] test
#获取当前Case名称
log ${TEST NAME}
#从变量文件中加载的新增对象JSON串
log ${IP_OBJ}
${returnKey} Set Variable data
${header} Create Dictionary Content-Type=application/json Authorization=${token}
${ipid} AddObjectData ${Test-AddPolicyData_IP_OBJ} ${returnKey}
#add Objectreturn statuscodeobjectid 多个返回以英文逗号分隔
${returncode} ${ipid} AddObjectData 1 ${IP_OBJ}
#新增对象添加到删除对象列表,及时添加避免下面异常导致遗留垃圾数据
${objectid} Set Variable ${ipid}
${objectIds} Create List [${objectid}]
#从变量文件中加载的新增对象JSON串
log ${FQDN_OBJ}
${fqdnid} AddObjectData ${FQDN_OBJ}
#add Objectreturn statcodeobjectid
${returncode} ${fqdnid} AddObjectData 1 ${FQDN_OBJ}
#新增对象添加到删除对象列表,及时添加避免下面异常导致遗留垃圾数据
${objectid} Catenate SEPARATOR=, ${objectid} ${fqdnid}
${objectIds} Create List [${objectid}]
#从变量文件中加载的新增策略的JSON串
log ${SECURITY_POLICY}
${POLICY} Replace String ${SECURITY_POLICY} IP_OBJ ${ipid}
${POLICY} Replace String ${SECURITY_POLICY} FQDN_OBJ ${fqdnid}
${policyid} AddPolicyData ${POLICY}
#替换策略中的引用内容,需要在变量文件中提前固定内容
#替换策略中的引用内容,源、目的对象对象引用
${SECURITY_POLICY} Replace String ${SECURITY_POLICY} IP_OBJ ${ipid}
#替换策略中的引用内容filtersni对象对象引用
${SECURITY_POLICY} Replace String ${SECURITY_POLICY} FQDN_OBJ ${fqdnid}
#替换策略中的策略名称
${SECURITY_POLICY} Replace String ${SECURITY_POLICY} policyNameautotest ${TEST NAME}
log ${SECURITY_POLICY}
#add Policyreturn statuscodepolicyid 多个返回以逗号分隔
${returncode} ${policyid} AddPolicyData 1 ${SECURITY_POLICY}
#新增对象添加到删除策略列表,及时添加避免后面异常导致遗留垃圾数据
${policyId1} set Variable {"policyType":"tsg_security","policyIds":[${policyid}]}
${policyIds} Create List ${policyId1}
Test-GetRandomIP
[Tags] test

View File

@@ -1,7 +1,7 @@
def get_variables():
variables = {"IP_OBJ":'{"opAction":"add","refuseCode":true,"returnData":1,"objectList":{"objectType":"ip","objectSubType":"endpoint","isValid":1,"isInitialize":0,"isExclusion":0,"objectName":"autotest","objectDesc":"autotest","subObjectIds":[],"addItemList":[{"ip":"192.168.32.69","ipIf":false,"portIf":false,"port":"1-65535","itemId":"","clientIp1":"192.168.32.69","clientIp2":"192.168.32.69","clientPort1":"1","clientPort2":"65535","clientIpFormat":"range","clientPortFormat":"range","addrType":4,"direction":0,"temporaryItemId":1606647164},{"ip":"1.1.1.1","ipIf":false,"portIf":false,"port":"0-65535","itemId":"","clientIp1":"1.1.1.1","clientIp2":"1.1.1.1","clientPort1":"","clientPort2":"","clientIpFormat":"range","clientPortFormat":"range","addrType":4,"direction":0,"temporaryItemId":1606647177}],"updateItemList":[],"deleteItemIds":[],"iconColor":"#31739C"}}',
"FQDN_OBJ":'"{"opAction":"add","returnData":1,"objectList":{"objectType":"fqdn","objectSubType":"fqdn","isValid":1,"isInitialize":0,"isExclusion":0,"objectName":"autotest","objectDesc":"","subObjectIds":[],"addItemList":[{"keywordArray":["$www.test.com"],"t":1606647302921,"itemId":"","isHexbin":0,"state":2},{"keywordArray":["*autotest.com"],"t":1606647302921,"isHexbin":0,"state":2}],"updateItemList":[],"deleteItemIds":[],"objectId":""}}"',
"SECURITY_POLICY":'{"opAction":"add","refuseCode":true,"policyList":{"policyId":"","policyName":"autotest","policyType":"tsg_security","action":"intercept","userTags":"","doBlacklist":0,"doLog":1,"policyDesc":"dxytest","effectiveRange":{"tag_sets":[[]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":1,"mirror_profile":25}},"source":[{"objectId":IP_OBJ,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[{"objectId":IP_OBJ,"protocolField":"TSG_SECURITY_DESTINATION_ADDR"}],"filterList":[{"filter":[{"objectId":FQDN_OBJ,"protocolField":"TSG_FIELD_SSL_SNI"}]}],"appIdObjects":[44],"appSelectorObjects":[],"isValid":1,"scheduleId":[]}}',
"FQDN_OBJ":'{"opAction":"add","refuseCode":true,"returnData":1,"objectList":{"objectType":"fqdn","objectSubType":"fqdn","isValid":1,"isInitialize":0,"isExclusion":0,"objectName":"autotest","objectDesc":"","subObjectIds":[],"addItemList":[{"keywordArray":["*autotest.com"],"t":"16088629755980","itemId":"","isHexbin":0,"state":2},{"keywordArray":["$www.test.com"],"t":"16088629755981","isHexbin":0,"state":2}],"updateItemList":[],"deleteItemIds":[],"iconColor":"#31739C"}}',
"SECURITY_POLICY":'{"opAction":"add","refuseCode":true,"returnData":1,"policyList":{"policyId":"","policyName":"policyNameautotest","policyType":"tsg_security","action":"intercept","userTags":"","doBlacklist":0,"doLog":1,"policyDesc":"autotest","effectiveRange":{"tag_sets":[[]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":0,"mirror_profile":null}},"source":[{"objectId":IP_OBJ,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[{"objectId":IP_OBJ,"protocolField":"TSG_SECURITY_DESTINATION_ADDR"}],"filterList":[{"filter":[{"objectId":FQDN_OBJ,"protocolField":"TSG_FIELD_SSL_SNI"}]}],"appIdObjects":[44],"appSelectorObjects":[],"isValid":1,"scheduleId":[55]}}',
"STRINGS":["one","two","kolme","four"],
"NUMBERS":[1,66,3.1415926],
"MAPPING":'{"one":1,"two":2,"three":3}',