Merge "Return valid url when querying versions endpoint"
This commit is contained in:
commit
0fdd8a3fc9
|
@ -85,7 +85,7 @@ def _get_common_links(req):
|
||||||
self_uri = req.uri
|
self_uri = req.uri
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
self_uri = self_uri.decode(rest_utils.ENCODING)
|
self_uri = self_uri.decode(rest_utils.ENCODING)
|
||||||
base_uri = self_uri.replace(req.path, '')
|
base_uri = self_uri.rpartition(req.path)[0]
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'rel': 'self',
|
'rel': 'self',
|
||||||
|
@ -106,7 +106,7 @@ def _parse_version(version_id, req):
|
||||||
self_uri = req.uri
|
self_uri = req.uri
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
self_uri = self_uri.decode(rest_utils.ENCODING)
|
self_uri = self_uri.decode(rest_utils.ENCODING)
|
||||||
base_uri = self_uri.replace(req.path, '')
|
base_uri = self_uri.rpartition(req.path)[0]
|
||||||
|
|
||||||
# need to get template dict, consecutive calls
|
# need to get template dict, consecutive calls
|
||||||
# needs to operate on unmodified instance
|
# needs to operate on unmodified instance
|
||||||
|
|
|
@ -27,6 +27,7 @@ class TestApiVersions(base.BaseApiTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestApiVersions, self).setUp()
|
super(TestApiVersions, self).setUp()
|
||||||
self.versions = versions.Versions()
|
self.versions = versions.Versions()
|
||||||
|
self.app.add_route("/", self.versions)
|
||||||
self.app.add_route("/version/", self.versions)
|
self.app.add_route("/version/", self.versions)
|
||||||
self.app.add_route("/version/{version_id}", self.versions)
|
self.app.add_route("/version/{version_id}", self.versions)
|
||||||
|
|
||||||
|
@ -73,23 +74,31 @@ class TestApiVersions(base.BaseApiTestCase):
|
||||||
self.assertIn('rel', link)
|
self.assertIn('rel', link)
|
||||||
key = link.get('rel')
|
key = link.get('rel')
|
||||||
self.assertIn(key, expected_links_keys)
|
self.assertIn(key, expected_links_keys)
|
||||||
|
href = link.get('href')
|
||||||
|
self.assertTrue(href.startswith(expected_url))
|
||||||
|
|
||||||
expected_versions = 'v2.0', 'v3.0'
|
expected_versions = 'v2.0', 'v3.0'
|
||||||
expected_links_keys = 'self', 'version', 'healthcheck'
|
expected_links_keys = 'self', 'version', 'healthcheck'
|
||||||
|
expected_protocol = 'http'
|
||||||
|
expected_host = 'fakehost.com'
|
||||||
|
expected_url = '{}://{}'.format(expected_protocol, expected_host)
|
||||||
|
|
||||||
res = self.simulate_request(
|
for expected_path in ['/', '/version']:
|
||||||
path='/version',
|
res = self.simulate_request(
|
||||||
method='GET',
|
path=expected_path,
|
||||||
headers={
|
protocol=expected_protocol,
|
||||||
'Content-Type': 'application/json'
|
host=expected_host,
|
||||||
}
|
method='GET',
|
||||||
)
|
headers={
|
||||||
self.assertEqual(falcon.HTTP_200, res.status)
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.assertEqual(falcon.HTTP_200, res.status)
|
||||||
|
|
||||||
response = res.json
|
response = res.json
|
||||||
|
|
||||||
_check_elements()
|
_check_elements()
|
||||||
_check_global_links()
|
_check_global_links()
|
||||||
|
|
||||||
def test_should_return_expected_version_id(self):
|
def test_should_return_expected_version_id(self):
|
||||||
expected_versions = 'v2.0', 'v3.0'
|
expected_versions = 'v2.0', 'v3.0'
|
||||||
|
|
Loading…
Reference in New Issue