Skip to content

Instantly share code, notes, and snippets.

@007bsd
Created October 18, 2017 09:43
Show Gist options
  • Select an option

  • Save 007bsd/c4e2792ea47a4a239b0d8f6820d27f58 to your computer and use it in GitHub Desktop.

Select an option

Save 007bsd/c4e2792ea47a4a239b0d8f6820d27f58 to your computer and use it in GitHub Desktop.
*** Keywords ***
GET AUTH_TOKEN
[Arguments] ${CREDENTIALS}
Create Session AUTH ${ROOT_URL} verify=${True}
${resp}= POST Request AUTH /token
... headers=${HEADERS}
... data=${CREDENTIALS}
... timeout=${timeout}
Should Be Equal As Strings ${resp.status_code} 200
${response}= Set Variable ${resp.json()}
${access_token}= Set Variable Bearer ${response['access_token']}
Set Suite Variable ${auth_token} ${access_token}
# Log To Console ${auth_token}
[Return] ${auth_token}
Create Admin Session
[Documentation] Admin session for API foo bar
${admin_token}= GET AUTH_TOKEN ${ADMIN}
${admin_headers}= Create Dictionary Authorization=${admin_token}
... Content-Type=application/json # or what ever you need
Create Session ADMIN ${YOUR_API_ROOT_URL} verify=True
... headers=${admin_headers}
... max_retries=5
... backoff_factor=0.5
... timeout=${timeout}
Create ${ROLE_BASED} Session
[Documentation] Create session for specific user role.
... Valid roles: ADMIN, USER_1, USER_2, ...
${bearer_token}= GET AUTH_TOKEN ${${ROLE_BASED}}
${session_headers}= Create Dictionary Authorization=${bearer_token}
... Content-Type=application/json
Create Session ${ROLE_BASED} ${ROOT_URL} verify=True
... headers=${session_headers}
... max_retries=5
... backoff_factor=0.5
... timeout=${timeout}
# Calling above keyword
Create ADMIN Session
Create USER_1 Session
Create USER_2 Session
*** Test Cases ***
000 Get Email Information of Foo Bar
As ADMIN Call GET /my_api/vers001/endpoint/email
# VERIFICATION
Response Should Return Status Code 200
Response Should Contain Value foo bar
Response Should Contain Key foo_bar=bar_foo
...
*** Keywords ***
As ${ROLE} Call ${METHOD} ${ENDPOINT}
${response}= Run Keyword ${METHOD} Request ${ROLE} ${ENDPOINT}
Set Test Variable ${response}
Log ${response.content}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment