pyresttest
pyresttest copied to clipboard
Double slash when templating a URL using a single variable
When using variables in templates as URL, pyresttest will add slashes if there is none present but also if the expanded form of the template has a starting slash:
---
- config:
- testset: "Server Tests"
- variable_binds: {foobar: '/foobar'}
- test:
- name: "Test some URL"
- url: {template: "$foobar"}
changing the variable to foobar
and the url to {template: "/$foobar"}
works fine. Otherwise it will produce double slashes: http://127.0.0.1//foobar
Interestingly, this does not happen, if there is something else than a single variable in the template:
---
- config:
- testset: "Server Tests"
- variable_binds: {foobar: '/foobar'}
- test:
- name: "Test some URL"
- url: {template: "$foobar/blafoo"}
It then contacts the correct url http://127.0.0.1/foobar/blafoo
I noticed this issue when using extracted variables as the next url, see http://stackoverflow.com/questions/39096872/double-slash-when-using-a-template-in-pyresttest
Edit: I see where the problem might coming from:
Here https://github.com/svanoort/pyresttest/blob/53e105161bc0822a62599fa4c92ba208be2074e6/pyresttest/tests.py#L471 is the URL concatenated with the base_url. But this happens before the template is actually parsed. So urlparse.urljoin
will of course add a slash if there is none.
But that does not explain why the second yaml file works.