svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 325 forks source link

Unable to set value of extract binds #232

Closed mr-karan closed 7 years ago

mr-karan commented 7 years ago

I want to use an access token obtained from a previous Authentication route but I am unable to properly set it.

test.yaml

---
- config:
    - testset: "Basic tests"
- test:
    - name: "Get Auth Token"
    - url: "/o/token/"
    - method: "POST"
    - body: 'grant_type=password&client_id=&client_secret=&password=&username='
    - headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    - expected_status: [200]
    - extract_binds:
        - 'token': {'jsonpath_mini': 'access_token'}

- test:
    - name: "Get details"
    - url: "/api/details"
    - method: "GET"
    - headers: {'Authorization': 'Bearer $token'}
    - expected_status: [200]

Error Message

REQUEST:
GET http://localhost:8000/api/details
HEADERS:
{'Authorization': 'Bearer $token'}
Press ENTER when ready (0):
DEBUG:Initial Test Result, based on expected response code: False
RESPONSE:
{"detail":"Authentication credentials were not provided."}

This error message comes when the $token value isn't set i.e. Authentication token isn't provided.

Equivalent cURL request is

curl -X GET -H "Authorization: Bearer <token value>" -H "Cache-Control: no-cache"  "http://localhost:8000/api/details"

Any help is much appreciated

mr-karan commented 7 years ago

marking it as closed. found my answer 👍

https://github.com/svanoort/pyresttest/issues/99#issuecomment-150557452

imangohari1 commented 6 years ago

What was the issue?