This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
dongxiaoyan-tsg-autotest/02-Keyword/common/ApiHttpRequest.robot
2020-12-15 19:58:08 +08:00

93 lines
4.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

*** Settings ***
Library Collections
Library RequestsLibrary
Resource ../../03-Variable/BifangApiVariable.txt
*** Variables ***
*** Keywords ***
GetRequestBase
[Arguments] ${host} ${api} ${header} ${data}
[Documentation] [Get方法封装第一层]
Create Session api ${host} headers=${header}
${apiurl}= Run Keyword If '${data}' != '${EMPTY}' Set Variable ${api}?${data}
... ELSE Set Variable ${api}
${remoteResponse} Get Request api ${apiurl}
[Return] ${remoteResponse.content}
GetRequestResposeCode
[Arguments] ${host} ${api} ${header} ${data}
[Documentation] [Get方法封装第二层]
${response} GetRequestBase ${host} ${api} ${header} ${data}
${response} to json ${response}
${code} get from dictionary ${response} code
[Return] ${code}
GetRequestResposeData
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
[Documentation] [Get方法封装第二层]
${response} GetRequestBase ${host} ${api} ${header} ${data}
${response} to json ${response}
${returnValue} get from dictionary ${response} ${returnKey}
[Return] ${returnValue}
PostHttpRequestBase
[Arguments] ${host} ${api} ${header} ${body}
${header} Create Dictionary Content-Type=application/json Authorization=${token}
Create Session api ${host} headers=${header}
${remoteResponse} Post Request api ${api} data=${body}
[Return] ${remoteResponse.content}
PostRequestResposeCode
[Arguments] ${host} ${api} ${header} ${data}
[Documentation] [Get方法封装第二层]
${response} PostRequestBase ${host} ${api} ${header} ${data}
${response} to json ${response}
${code} get from dictionary ${response} code
[Return] ${code}
PostRequestResposeData
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
[Documentation] [Get方法封装第二层]
${response} PostRequestBase ${host} ${api} ${header} ${data}
${response} to json ${response}
${returnValue} get from dictionary ${response} ${returnKey}
[Return] ${returnValue}
PutRequestBase
[Arguments] ${requestUri} ${data}
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
create session api http://${host}:${port} ${headers}
${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}
DeleteRequestBase
[Arguments] ${url} ${data}
${header} Create Dictionary Content-Type=application/json Authorization=${token}
Create Session api http://${host}:${port} headers=${header}
${remoteResponse} Delete Request api ${url} data=${data} headers=${header}
${response} to json ${remoteResponse.content}
Should Be Equal As Strings ${remoteResponse.status_code} 200
[Return] ${response}
UpFileRequest
[Arguments] ${url} ${data} ${files} ${fileDesc}
${header} Set To Dictionary ${fileDesc} Authorization=${token}
Create Session api http://${host}:${port} headers=${header}
${remoteResponse} Post Request api ${url} data=${data} files=${files} headers=${header}
${response} to json ${remoteResponse.content}
Should Be Equal As Strings ${remoteResponse.status_code} 200
[Return] ${response}
PutFileRequest
[Arguments] ${url} ${data} ${files} ${fileDesc}
${header} Set To Dictionary ${fileDesc} Authorization=${token}
Create Session api http://${host}:${port} headers=${header}
${remoteResponse} Put Request api ${url} params=${data} files=${files} headers=${header}
${response} to json ${remoteResponse.content}
Should Be Equal As Strings ${remoteResponse.status_code} 200
[Return] ${response}