2020-04-01 12:42:05 +08:00
|
|
|
|
*** Settings ***
|
|
|
|
|
|
Resource ../../03-Variable/BifangApiVariable.txt
|
2020-06-16 16:42:04 +08:00
|
|
|
|
Library REST http://${host}:${port}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
Library Collections
|
|
|
|
|
|
Library RequestsLibrary
|
|
|
|
|
|
|
|
|
|
|
|
*** Keywords ***
|
2020-06-16 15:10:02 +08:00
|
|
|
|
ManageApistr
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 描述:入口,apistr 为调用api地址
|
|
|
|
|
|
... 本关键字的作用是判断地址前有没有加版本号,如果没有加上
|
|
|
|
|
|
... policy/compile -> /v1/policy/compile
|
|
|
|
|
|
... /policy/compile -> /v1/policy/compile
|
|
|
|
|
|
... v1/policy/compile -> /v1/policy/compile
|
|
|
|
|
|
... /v1/policy/compile -> /v1/policy/compile
|
|
|
|
|
|
[Arguments] ${apistr}
|
|
|
|
|
|
${apiStart} Evaluate '${apistr}'[0:1]
|
|
|
|
|
|
${apiStart1} Evaluate '${apistr}'[0:2]
|
|
|
|
|
|
${apistr} Run Keyword If "${apiStart}"!="/" and "${apiStart}"!="v"
|
|
|
|
|
|
... Set Variable /${version}/${apistr}
|
|
|
|
|
|
... ELSE IF "${apiStart}"=="/" and "${apiStart1}"!="/v"
|
|
|
|
|
|
... Set Variable /${version}${apistr}
|
|
|
|
|
|
... ELSE IF "${apiStart}"=="v" Set Variable /${apistr}
|
|
|
|
|
|
... ELSE IF "${apiStart1}"=="/v" Set Variable ${apistr}
|
|
|
|
|
|
... ELSE Set Variable ${apistr}
|
|
|
|
|
|
log ${apistr}
|
|
|
|
|
|
[Return] ${apistr}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
BasePostRequest
|
2020-06-16 15:10:02 +08:00
|
|
|
|
[Arguments] ${apistr} ${body}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
Set Headers {"Authorization":"${token}","Content-Type":"application/json"}
|
2020-04-29 19:39:52 +08:00
|
|
|
|
log 111111111111111111111111${apistr}
|
2020-04-07 12:51:52 +08:00
|
|
|
|
&{httpResponse} Post ${apistr} ${body}
|
|
|
|
|
|
#Output response body
|
2020-04-01 12:42:05 +08:00
|
|
|
|
Object response body
|
|
|
|
|
|
#Integer $.code 200
|
|
|
|
|
|
#Array $.data.policyList
|
|
|
|
|
|
${response} Set Variable ${httpResponse.body}
|
2020-04-29 20:04:46 +08:00
|
|
|
|
[Return] ${response}
|
2020-06-18 16:07:38 +08:00
|
|
|
|
|
|
|
|
|
|
BasePostRequestOK
|
|
|
|
|
|
[Arguments] ${apistr} ${body}
|
|
|
|
|
|
${response} BasePostRequest ${apistr} ${body}
|
|
|
|
|
|
log ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${response['code']} 200
|
|
|
|
|
|
[Return] ${response}
|
|
|
|
|
|
|
|
|
|
|
|
BasePostRequestForV2
|
2020-06-16 15:10:02 +08:00
|
|
|
|
[Arguments] ${requestUri} ${data} ${apiVersion}
|
|
|
|
|
|
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
|
|
|
|
|
|
create session api http://${host}:${port}/${apiVersion} ${headers}
|
|
|
|
|
|
${response}= Post Request api ${requestUri} data=${data}
|
|
|
|
|
|
log return data =${response}
|
|
|
|
|
|
Should Be Equal As Strings ${response.status_code} 200
|
|
|
|
|
|
${response} to json ${response.content}
|
|
|
|
|
|
[Return] ${response}
|
2020-04-29 20:04:46 +08:00
|
|
|
|
BaseGetRequest
|
|
|
|
|
|
[Arguments] ${apistr} ${body}
|
|
|
|
|
|
Set Headers {"Authorization":"${token}","Content-Type":"application/json"}
|
2020-06-16 16:42:04 +08:00
|
|
|
|
&{httpResponse} Get /${apistr}?${body}
|
2020-04-29 20:04:46 +08:00
|
|
|
|
#Output response body
|
|
|
|
|
|
Object response body
|
|
|
|
|
|
#Integer $.code 200
|
|
|
|
|
|
#Array $.data.policyList
|
|
|
|
|
|
${response} Set Variable ${httpResponse.body}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
[Return] ${response}
|
2020-06-19 11:35:37 +08:00
|
|
|
|
BaseGetRequestOK
|
|
|
|
|
|
[Arguments] ${apistr} ${body}
|
|
|
|
|
|
${response} BaseGetRequest ${apistr} ${body}
|
|
|
|
|
|
log ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${response['code']} 200
|
|
|
|
|
|
[Return] ${response}
|
2020-06-16 15:10:02 +08:00
|
|
|
|
BaseGetRequestForV2
|
|
|
|
|
|
[Arguments] ${requestUri} ${data} ${apiVersion}
|
|
|
|
|
|
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
|
|
|
|
|
|
create session api http://${host}:${port}/${apiVersion} ${headers}
|
|
|
|
|
|
${response}= Get Request api ${requestUri}?${data}
|
|
|
|
|
|
log return data =${response}
|
|
|
|
|
|
Should Be Equal As Strings ${response.status_code} 200
|
|
|
|
|
|
${response} to json ${response.content}
|
|
|
|
|
|
[Return] ${response}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
BaseDeleteRequest
|
|
|
|
|
|
[Arguments] ${requestUri} ${data}
|
|
|
|
|
|
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
|
2020-06-16 16:42:04 +08:00
|
|
|
|
create session api http://${host}:${port} ${headers}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
${response}= Delete Request api ${requestUri} data=${data}
|
|
|
|
|
|
log return data =${response}
|
|
|
|
|
|
Should Be Equal As Strings ${response.status_code} 200
|
|
|
|
|
|
${response} to json ${response.content}
|
|
|
|
|
|
[Return] ${response}
|
2020-06-19 11:35:37 +08:00
|
|
|
|
|
|
|
|
|
|
BaseDeleteRequestOK
|
|
|
|
|
|
[Arguments] ${apistr} ${body}
|
|
|
|
|
|
${response} BaseDeleteRequest ${apistr} ${body}
|
|
|
|
|
|
log ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${response['code']} 200
|
|
|
|
|
|
[Return] ${response}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
|
|
|
|
|
|
BaseEditRequest
|
|
|
|
|
|
[Arguments] ${requestUri} ${data}
|
|
|
|
|
|
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
|
2020-06-16 16:42:04 +08:00
|
|
|
|
create session api http://${host}:${port} ${headers}
|
2020-04-01 12:42:05 +08:00
|
|
|
|
${response}= Put Request api ${requestUri} data=${data}
|
|
|
|
|
|
log return data =${response}
|
|
|
|
|
|
Should Be Equal As Strings ${response.status_code} 200
|
|
|
|
|
|
${response} to json ${response.content}
|
|
|
|
|
|
[Return] ${response}
|
2020-06-19 11:35:37 +08:00
|
|
|
|
|
|
|
|
|
|
BaseEditRequestOK
|
|
|
|
|
|
[Arguments] ${apistr} ${body}
|
|
|
|
|
|
${response} BaseEditRequest ${apistr} ${body}
|
|
|
|
|
|
log ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${response['code']} 200
|
|
|
|
|
|
[Return] ${response}
|
2020-06-16 19:40:59 +08:00
|
|
|
|
BaseEditRequestForV2
|
|
|
|
|
|
[Arguments] ${requestUri} ${data} ${apiVersion}
|
|
|
|
|
|
${apiStart} Evaluate '${requestUri}'[0:1]
|
|
|
|
|
|
${requestUri} Run Keyword If "${apiStart}"=="/" set variable /${apiVersion}${requestUri}
|
|
|
|
|
|
... ELSE set variable /${apiVersion}/${requestUri}
|
|
|
|
|
|
${response} BaseEditRequest ${requestUri} ${data}
|
2020-06-18 16:29:17 +08:00
|
|
|
|
[Return] ${response}
|
|
|
|
|
|
#拼接字典类型数据为get请求的字符串
|
|
|
|
|
|
Dictionary-To-QueryParams
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 接收get参数字典,转换为请求字符串
|
|
|
|
|
|
[Arguments] ${params}
|
|
|
|
|
|
${paramsString} = Set Variable ${EMPTY}
|
|
|
|
|
|
FOR ${key} IN @{params}
|
|
|
|
|
|
${value} = Get From Dictionary ${params} ${key}
|
|
|
|
|
|
${paramStr} = Catenate SEPARATOR=\= ${key} ${value}
|
|
|
|
|
|
${len} = Get Length ${paramsString}
|
|
|
|
|
|
${paramsString} = Run Keyword If ${len} != 0 Catenate SEPARATOR=& ${paramsString} ${paramStr}
|
|
|
|
|
|
... ELSE Set Variable ${paramStr}
|
|
|
|
|
|
END
|
|
|
|
|
|
Log To Console ${paramsString}
|
|
|
|
|
|
[Return] ${paramsString}
|
|
|
|
|
|
BaseFormRequest
|
|
|
|
|
|
[Arguments] ${requestUri} ${data} ${apiVersion}
|
|
|
|
|
|
${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"}
|
|
|
|
|
|
create session api http://${host}:${port}/${apiVersion} ${headers}
|
|
|
|
|
|
${response} Run Keyword If "${data}"=="${EMPTY}" Get Request api ${requestUri}
|
|
|
|
|
|
... ELSE Get Request api ${requestUri}?${data}
|
|
|
|
|
|
log return data =${response}
|
|
|
|
|
|
Should Be Equal As Strings ${response.status_code} 200
|
|
|
|
|
|
${response} to json ${response.content}
|
2020-06-16 19:40:59 +08:00
|
|
|
|
[Return] ${response}
|