数据驱动方式尝试

This commit is contained in:
dongxiaoyan
2020-12-15 19:58:08 +08:00
parent da2e33850b
commit fe1127b3a3
16 changed files with 711 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
*** Settings ***
Library Collections
Library RequestsLibrary
Resource ../../../03-Variable/BifangApiVariable.txt
Resource ../../common/ApiHttpRequest.robot
Variables ../../../05-Other/variable/policy/apipolicyrequesttest.py
*** Variables ***
${policyapiv2} /v2/policy/compile
${objectapiv1} /v1/policy/object
${hosturl} http://${host}:${port}
${header} Create Dictionary Content-Type=application/json Authorization=${token}
*** Keywords ***
GetRequestResposeCodePrivate
[Arguments] ${data}
[Documentation] [Get方法封装第二层]
${header} Create Dictionary Content-Type=application/json Authorization=${token}
${response} GetRequestBase http://${hosturl}:${port} ${policyapiv2} ${header} ${data}
${response} to json ${response}
${code} get from dictionary ${response} code
[Return] ${code}
GetPolicyData
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
[Documentation] [Get方法封装第二层]
${response} GetRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
${response} to json ${response}
${returnValue} get from dictionary ${response} ${returnKey}
[Return] ${returnValue}
AddPolicyData
[Arguments] ${data} ${returnKey}
[Documentation] [Get方法封装第二层]
${response} PostRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
${response} to json ${response}
${returnValue} get from dictionary ${response} ${returnKey}
[Return] ${returnValue}
AddObjectData
[Arguments] ${data} ${returnKey}
[Documentation] [Get方法封装第二层]
${response} PostHttpRequestBase ${hosturl} ${objectapiv1} ${header} ${data}
${response} to json ${response}
${returnValue} get from dictionary ${response} ${returnKey}
[Return] ${returnValue}
AddPolicyBase
[Arguments] ${host} ${api} ${header} ${body}
${header} Create Dictionary Content-Type=application/json Authorization=${token}
Create Session api ${hosturl} headers=${header}
${remoteResponse} Post Request api ${api} data=${body}
[Return] ${remoteResponse.content}
AddPolicyCode
[Arguments] ${host} ${api} ${header} ${data}
[Documentation] [Get方法封装第二层]
${response} PostRequestBase ${hosturl} ${api} ${header} ${data}
${response} to json ${response}
${code} get from dictionary ${response} code
[Return] ${code}

View File

@@ -0,0 +1,38 @@
*** Settings ***
Test Teardown DeletePolicyAndGroupObject ${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
*** Variables ***
*** Test Cases ***
Test-GetRequestResposeCodePrivate
[Tags] test
${data} Set Variable pageSize=20&pageNo=1&policyType=tsg_security
${code} GetRequestResposeCodePrivate ${data}
Should Be Equal As Strings ${code} 200
log ${code}
Test-AddPolicyData
[Tags] test
log ${IP_OBJ}
${returnKey} Set Variable data
${header} Create Dictionary Content-Type=application/json Authorization=${token}
${ipid} AddObjectData ${Test-AddPolicyData_IP_OBJ} ${returnKey}
log ${FQDN_OBJ}
${fqdnid} AddObjectData ${FQDN_OBJ}
log ${SECURITY_POLICY}
${POLICY} Replace String ${SECURITY_POLICY} IP_OBJ ${ipid}
${POLICY} Replace String ${SECURITY_POLICY} FQDN_OBJ ${fqdnid}
${policyid} AddPolicyData ${POLICY}
Test-GetRandomIP
[Tags] test
${ip} GetRandomIP ipv4
log ${ip}
${ip} GetRandomIP ipv6
log ${ip}