Guest User

Untitled

a guest
Oct 18th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. *** Keywords ***
  2. GET AUTH_TOKEN
  3. [Arguments] ${CREDENTIALS}
  4. Create Session AUTH ${ROOT_URL} verify=${True}
  5. ${resp}= POST Request AUTH /token
  6. ... headers=${HEADERS}
  7. ... data=${CREDENTIALS}
  8. ... timeout=${timeout}
  9.  
  10. Should Be Equal As Strings ${resp.status_code} 200
  11.  
  12. ${response}= Set Variable ${resp.json()}
  13. ${access_token}= Set Variable Bearer ${response['access_token']}
  14. Set Suite Variable ${auth_token} ${access_token}
  15. # Log To Console ${auth_token}
  16. [Return] ${auth_token}
  17.  
  18.  
  19.  
  20. Create Admin Session
  21. [Documentation] Admin session for API foo bar
  22. ${admin_token}= GET AUTH_TOKEN ${ADMIN}
  23. ${admin_headers}= Create Dictionary Authorization=${admin_token}
  24. ... Content-Type=application/json # or what ever you need
  25. Create Session ADMIN ${YOUR_API_ROOT_URL} verify=True
  26. ... headers=${admin_headers}
  27. ... max_retries=5
  28. ... backoff_factor=0.5
  29. ... timeout=${timeout}
  30.  
  31.  
  32.  
  33. Create ${ROLE_BASED} Session
  34. [Documentation] Create session for specific user role.
  35. ... Valid roles: ADMIN, USER_1, USER_2, ...
  36.  
  37. ${bearer_token}= GET AUTH_TOKEN ${${ROLE_BASED}}
  38. ${session_headers}= Create Dictionary Authorization=${bearer_token}
  39. ... Content-Type=application/json
  40. Create Session ${ROLE_BASED} ${ROOT_URL} verify=True
  41. ... headers=${session_headers}
  42. ... max_retries=5
  43. ... backoff_factor=0.5
  44. ... timeout=${timeout}
  45.  
  46.  
  47. # Calling above keyword
  48.  
  49. Create ADMIN Session
  50. Create USER_1 Session
  51. Create USER_2 Session
  52.  
  53.  
  54.  
  55. *** Test Cases ***
  56. 000 Get Email Information of Foo Bar
  57. As ADMIN Call GET /my_api/vers001/endpoint/email
  58.  
  59. # VERIFICATION
  60. Response Should Return Status Code 200
  61. Response Should Contain Value foo bar
  62. Response Should Contain Key foo_bar=bar_foo
  63. ...
  64.  
  65. *** Keywords ***
  66. As ${ROLE} Call ${METHOD} ${ENDPOINT}
  67. ${response}= Run Keyword ${METHOD} Request ${ROLE} ${ENDPOINT}
  68. Set Test Variable ${response}
  69. Log ${response.content}
Add Comment
Please, Sign In to add comment