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:
parent
637a48983a
commit
561c76ccc5
|
@ -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/"
|
||||
|
||||
|
|
@ -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, ''))
|
||||
|
|
Loading…
Reference in New Issue