Avoid duplicating prefix when re-using urls

If a reponse includes an absolute link, re-using that link as the
url in a subsequent test when a prefix is being used in the tests
can result in a 404 because the prefix will be duplicated.

This change ensures that the prefix will not be duplicated if the
URL already begins with the prefix.

Fixes #165
This commit is contained in:
Chris Dent 2017-02-22 10:23:26 -05:00
parent 637a48983a
commit 561c76ccc5
3 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,16 @@
tests:
- name: provide a link in response
POST: /
request_headers:
content-type: application/json
data:
link: $ENVIRON['GABBI_PREFIX']/barnabas
- name: get that link
GET: $RESPONSE['$.link']
response_headers:
x-gabbi-url: "///[a-f0-9:-]+$ENVIRON['GABBI_PREFIX']/barnabas/"

View File

@ -53,7 +53,8 @@ def create_url(base_url, host, port=None, prefix='', ssl=False):
path = parsed_url.path
# Guard against a prefix of None
if prefix:
# Without the startswith check, the tests in prefix.yaml fail.
if prefix and not path.startswith(prefix):
path = '%s%s' % (prefix, path)
return urlparse.urlunsplit((scheme, netloc, path, query_string, ''))

View File

@ -8,6 +8,7 @@ deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
install_command = pip install -U {opts} {packages}
commands = python setup.py testr --testr-args="{posargs}"
setenv = GABBI_PREFIX=
passenv = GABBI_* HOME
[testenv:venv]