tavern icon indicating copy to clipboard operation
tavern copied to clipboard

Use external function to create a url

Open abhinavasrivastava opened this issue 4 years ago • 3 comments

External function can be used only with headers, params and response. There should be a provision to use function anywhere. Example use case - Dynamically construct a url from a URI template.

abhinavasrivastava avatar Aug 06 '20 07:08 abhinavasrivastava

modify two files

{pythonpath}/Lib/site-packages/tavern/_plugins/rest/request.js

add one line code below add_request_args(optional_in_file, True)

optional_in_file.append("url")

like

...
add_request_args(required_in_file, False)
add_request_args(optional_in_file, True)

optional_in_file.append("url")

if "auth" in fspec:
    request_args["auth"] = tuple(fspec["auth"])
...

{pythonpath}/Lib/site-packages/tavern/schemas/tests.schema.yaml

find "url" and modify url.type to any

like

...
request:
  type: map
  required: false
  mapping:
    url:
      type: any
      required: true
...

ChangedenCZD avatar Aug 25 '20 09:08 ChangedenCZD

right now, you can write url by functional in your yaml file.

...
stages:
  - name: test functional url
    request:
      url:
        $ext:
          function: utils.url_generator:test_functional
          extra_kwargs:
            env: "{variablesname}"
    response:
...

ChangedenCZD avatar Aug 25 '20 09:08 ChangedenCZD

I also need this feature, my usecase: I need to pass filesystem path to the url and support different OS, so I need to generate url dynamic.

triklozoid avatar Dec 09 '21 12:12 triklozoid

Fixed in 2.4.0.

michaelboulton avatar Sep 18 '23 14:09 michaelboulton