cdent / gabbi

Declarative HTTP Testing for Python and anything else
http://gabbi.readthedocs.org/
Other
148 stars 34 forks source link

Substitution not occurring for header key #231

Closed joshleeb closed 6 years ago

joshleeb commented 6 years ago

Substitution doesn't seem to occur for the key of request_headers. For example:

Having this test works as expected, where $ENVIRON['HEADER_VAL'] is replaced by the value of HEADER_VAL.

- name: Working test
  desc: This is a working test
  GET: /api/some/endpoint
  request_headers:
    Header-Key: $ENVIRON['HEADER_VAL']
  status: 200

Yet, this test doesn't work as $ENVIRON['HEADER_KEY'] isn't substituted with HEADER_KEY.

- name: Failing test
  desc: This is a failing test
  GET: /api/some/endpoint
  request_headers:
    $ENVIRON['HEADER_KEY']: $ENVIRON['HEADER_VAL']
  status: 200

As a side note, this may have some relevance to #219.

cdent commented 6 years ago

Thanks for noticing this and for providing #232. It's mostly something that wasn't done initially because there was no immediate use case. I suspect I was also maintaining some kind of bias against unpredictable headers.

Out of curiosity, what's your use case? What are the headers that you have that aren't predictable?

joshleeb commented 6 years ago

I use a wrapper around gabbi that, amongst other things, helps to handle request authentication throughout the suite of e2e tests. Specifically, this wrapper sets variables in $ENVIRON which are read from a config file. It's then possible to dynamically provide the required authentication token in a request header.

Up until recently, the header key hasn't changed, but now I am needing to extend the wrapper to read the header key from the config as well so it can by dynamically changed in the tests.

Overall it provides a bit more flexibility with the test suite in being able to run it with different authentication methods and tokens.