From cc79b5fd98aefea99ce9af8f7862091f040655a4 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Fri, 24 Feb 2017 11:59:35 -0500 Subject: [PATCH] Add a test for a relative link and add a comment The comment explains how this is a pragmatic fix that could be done in a more robust way by changing data structures to distinguish between server and gabbi test generated urls. --- gabbi/tests/gabbits_intercept/prefix.yaml | 10 +++++++--- gabbi/utils.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gabbi/tests/gabbits_intercept/prefix.yaml b/gabbi/tests/gabbits_intercept/prefix.yaml index d005c21..3d6d0dc 100644 --- a/gabbi/tests/gabbits_intercept/prefix.yaml +++ b/gabbi/tests/gabbits_intercept/prefix.yaml @@ -1,16 +1,20 @@ tests: -- name: provide a link in response +- 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: + 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/" diff --git a/gabbi/utils.py b/gabbi/utils.py index 8542f5d..39e0331 100644 --- a/gabbi/utils.py +++ b/gabbi/utils.py @@ -52,8 +52,16 @@ def create_url(base_url, host, port=None, prefix='', ssl=False): query_string = parsed_url.query path = parsed_url.path - # Guard against a prefix of None - # Without the startswith check, the tests in prefix.yaml fail. + # Guard against a prefix of None or the url already having the + # prefix. Without the startswith check, the tests in prefix.yaml + # 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): path = '%s%s' % (prefix, path)