Skip to content

Commit

Permalink
Use urlunparse to reconstruct base_url
Browse files Browse the repository at this point in the history
Using string replace to replace the new path back onto the old path
fails when there is no path setup in the catalog initially. Instead of
this lets use the inverse to the urlparse previously performed.

Change-Id: I931f0c558aafc8dfaa5519744c6e4e7fcffc3205
Closes-Bug: #1552475
  • Loading branch information
jamielennox committed Mar 7, 2016
1 parent 22dd1c9 commit 823a004
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions tempest/lib/auth.py
Expand Up @@ -325,13 +325,24 @@ def base_url(self, filters, auth_data=None):

parts = urlparse.urlparse(_base_url)
if filters.get('api_version', None) is not None:
version_path = '/%s' % filters['api_version']
path = re.sub(r'(^|/)+v\d+(?:\.\d+)?',
'/' + filters['api_version'],
version_path,
parts.path,
count=1)
_base_url = _base_url.replace(parts.path, path)
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
path or version_path,
parts.params,
parts.query,
parts.fragment))
if filters.get('skip_path', None) is not None and parts.path != '':
_base_url = _base_url.replace(parts.path, "/")
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
'/',
parts.params,
parts.query,
parts.fragment))

return _base_url

Expand Down Expand Up @@ -447,13 +458,24 @@ def base_url(self, filters, auth_data=None):

parts = urlparse.urlparse(_base_url)
if filters.get('api_version', None) is not None:
version_path = '/%s' % filters['api_version']
path = re.sub(r'(^|/)+v\d+(?:\.\d+)?',
'/' + filters['api_version'],
version_path,
parts.path,
count=1)
_base_url = _base_url.replace(parts.path, path)
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
path or version_path,
parts.params,
parts.query,
parts.fragment))
if filters.get('skip_path', None) is not None:
_base_url = _base_url.replace(parts.path, "/")
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
'/',
parts.params,
parts.query,
parts.fragment))

return _base_url

Expand Down

0 comments on commit 823a004

Please sign in to comment.