*** Settings ***
Library  Collections
Library  String
Library  RequestsLibrary
Suite Teardown  Delete All Sessions

*** Test Cases ***
Get Requests
    Create Session  google  http://www.google.com
    Create Session  github  http://github.com/api/v2/json
     
    ${resp}=  Get  google  /
    Should Be Equal As Strings  ${resp.status_code}  200

    ${resp}=  Get  github  /user/search/bulkan
    Should Be Equal As Strings  ${resp.status_code}  200
    ${jsondata}=  To Json  ${resp.content}
    Dictionary Should Contain Value  ${jsondata['users'][0]}  Bulkan Savun Evcimen


Get With Auth
    ${auth}  Create List  user   passwd
    Create Session  httpbin  http://httpbin.org  auth=${auth}

    ${resp}  Get  httpbin  /basic-auth/user/passwd
    Should Be Equal As Strings  ${resp.status_code}  200
    ${jsondata}=  To Json  ${resp.content}
    Should Be Equal As Strings  ${jsondata['authenticated']}  True


Post Request With No Data
    Create Session  httpbin  http://httpbin.org
    ${resp}  Post  httpbin  /post  
    Should Be Equal As Strings  ${resp.status_code}  200


Post Requests
    Create Session  httpbin  http://httpbin.org

    ${data}  Create Dictionary  name  bulkan  surname  evcimen
    ${headers}  Create Dictionary  Content-Type  application/x-www-form-urlencoded
    ${resp}  Post  httpbin  /post  data=${data}
    ${jsondata}=  To Json  ${resp.content}
    Dictionary Should Contain Value  ${jsondata['form']}  bulkan
    Dictionary Should Contain Value  ${jsondata['form']}  evcimen


Put Requests
    Create Session  httpbin  http://httpbin.org

    ${data}  Create Dictionary  name  bulkan  surname  evcimen
    ${headers}  Create Dictionary  Content-Type  application/x-www-form-urlencoded
    ${resp}  Put  httpbin  /put  data=${data}
    ${jsondata}=  To Json  ${resp.content}
    Dictionary Should Contain Value  ${jsondata['form']}  bulkan
    Dictionary Should Contain Value  ${jsondata['form']}  evcimen


Head Request
    Create Session  httpbin  http://httpbin.org
    ${resp}  Head  httpbin  /headers
    Should Be Equal As Strings  ${resp.status_code}  200


Delete Request With No Data
    Create Session  httpbin  http://httpbin.org
    ${resp}  Delete  httpbin  /delete
    Should Be Equal As Strings  ${resp.status_code}  200


Delete Request With Data
    Create Session  httpbin  http://httpbin.org
    ${data}  Create Dictionary  name  bulkan  surname  evcimen
    ${resp}  Delete  httpbin  /delete  data=${data}
    Should Be Equal As Strings  ${resp.status_code}  200
    ${jsondata}=  To Json  ${resp.content}
    Dictionary Should Contain Value  ${jsondata['args']}  bulkan
    Dictionary Should Contain Value  ${jsondata['args']}  evcimen
