Merge pull request #205 from cdent/fix-165
Avoid duplicating prefix when re-using urls
This commit is contained in:
commit
31163305a0
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
tests:
|
||||||
|
|
||||||
|
- name: provide a link
|
||||||
|
POST: /
|
||||||
|
request_headers:
|
||||||
|
content-type: application/json
|
||||||
|
data:
|
||||||
|
link: $ENVIRON['GABBI_PREFIX']/barnabas
|
||||||
|
relative: link
|
||||||
|
|
||||||
|
- name: get that link
|
||||||
|
GET: $RESPONSE['$.link']
|
||||||
|
response_headers:
|
||||||
|
x-gabbi-url: "///[a-f0-9:-]+$ENVIRON['GABBI_PREFIX']/barnabas/"
|
||||||
|
|
||||||
|
- name: get relative link
|
||||||
|
GET: $HISTORY['provide a link'].$RESPONSE['$.relative']
|
||||||
|
response_headers:
|
||||||
|
x-gabbi-url: "///[a-f0-9:-]+$ENVIRON['GABBI_PREFIX']/link/"
|
|
@ -52,9 +52,20 @@ def create_url(base_url, host, port=None, prefix='', ssl=False):
|
||||||
query_string = parsed_url.query
|
query_string = parsed_url.query
|
||||||
path = parsed_url.path
|
path = parsed_url.path
|
||||||
|
|
||||||
# Guard against a prefix of None
|
# Guard against a prefix of None or the url already having the
|
||||||
if prefix:
|
# prefix. Without the startswith check, the tests in prefix.yaml
|
||||||
path = '%s%s' % (prefix, path)
|
# fail. This is a pragmatic fix which does this for any URL in a
|
||||||
|
# test request that does not have a scheme and does not
|
||||||
|
# distinguish between URLs in a gabbi test file and those
|
||||||
|
# generated by the server. Idealy we would not mutate nor need
|
||||||
|
# to check URLs returned from the server. Doing that, however,
|
||||||
|
# would require more complex data handling than we have now and
|
||||||
|
# this covers most common cases and will be okay until someone
|
||||||
|
# reports a bug.
|
||||||
|
if prefix and not path.startswith(prefix):
|
||||||
|
prefix = prefix.rstrip('/')
|
||||||
|
path = path.lstrip('/')
|
||||||
|
path = '%s/%s' % (prefix, path)
|
||||||
|
|
||||||
return urlparse.urlunsplit((scheme, netloc, path, query_string, ''))
|
return urlparse.urlunsplit((scheme, netloc, path, query_string, ''))
|
||||||
|
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -8,6 +8,7 @@ deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
install_command = pip install -U {opts} {packages}
|
install_command = pip install -U {opts} {packages}
|
||||||
commands = python setup.py testr --testr-args="{posargs}"
|
commands = python setup.py testr --testr-args="{posargs}"
|
||||||
|
setenv = GABBI_PREFIX=
|
||||||
passenv = GABBI_* HOME
|
passenv = GABBI_* HOME
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
|
|
Loading…
Reference in New Issue