Merge "Fix version replacement when path"
This commit is contained in:
commit
9aa74e4de9
|
@ -34,13 +34,15 @@ LOG = logging.getLogger(__name__)
|
||||||
def replace_version(url, new_version):
|
def replace_version(url, new_version):
|
||||||
parts = urlparse.urlparse(url)
|
parts = urlparse.urlparse(url)
|
||||||
version_path = '/%s' % new_version
|
version_path = '/%s' % new_version
|
||||||
path = re.sub(r'(^|/)+v\d+(?:\.\d+)?',
|
path, subs = re.subn(r'(^|/)+v\d+(?:\.\d+)?',
|
||||||
version_path,
|
version_path,
|
||||||
parts.path,
|
parts.path,
|
||||||
count=1)
|
count=1)
|
||||||
|
if not subs:
|
||||||
|
path = '%s%s' % (parts.path.rstrip('/'), version_path)
|
||||||
url = urlparse.urlunparse((parts.scheme,
|
url = urlparse.urlunparse((parts.scheme,
|
||||||
parts.netloc,
|
parts.netloc,
|
||||||
path or version_path,
|
path,
|
||||||
parts.params,
|
parts.params,
|
||||||
parts.query,
|
parts.query,
|
||||||
parts.fragment))
|
parts.fragment))
|
||||||
|
|
|
@ -597,21 +597,18 @@ class TestReplaceVersion(base.TestCase):
|
||||||
auth.replace_version('http://localhost:35357', 'v2.0'))
|
auth.replace_version('http://localhost:35357', 'v2.0'))
|
||||||
|
|
||||||
def test_no_version_base_solidus(self):
|
def test_no_version_base_solidus(self):
|
||||||
# TODO(blk-u): This doesn't look like it works as expected.
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'http://localhost:35357/',
|
'http://localhost:35357/v2.0',
|
||||||
auth.replace_version('http://localhost:35357/', 'v2.0'))
|
auth.replace_version('http://localhost:35357/', 'v2.0'))
|
||||||
|
|
||||||
def test_no_version_path(self):
|
def test_no_version_path(self):
|
||||||
# TODO(blk-u): This doesn't look like it works as expected.
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'http://localhost/identity',
|
'http://localhost/identity/v2.0',
|
||||||
auth.replace_version('http://localhost/identity', 'v2.0'))
|
auth.replace_version('http://localhost/identity', 'v2.0'))
|
||||||
|
|
||||||
def test_no_version_path_solidus(self):
|
def test_no_version_path_solidus(self):
|
||||||
# TODO(blk-u): This doesn't look like it works as expected.
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'http://localhost/identity/',
|
'http://localhost/identity/v2.0',
|
||||||
auth.replace_version('http://localhost/identity/', 'v2.0'))
|
auth.replace_version('http://localhost/identity/', 'v2.0'))
|
||||||
|
|
||||||
def test_path_version(self):
|
def test_path_version(self):
|
||||||
|
|
Loading…
Reference in New Issue