tavern
tavern copied to clipboard
Use external function to create a url
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.
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
...
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:
...
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.
Fixed in 2.4.0.