Handle '/' in build_name for getting test_runs

According to this snippet:
http://flask.pocoo.org/snippets/76/

we can change string to path. Path type has the same behavior
as string but it allows the '/' character.

Change-Id: I7c19c7366b698d66a1cef13a822955c0da840a5a
Closes-Bug: #1720255
This commit is contained in:
Trevor McCasland 2017-09-29 11:06:07 -05:00
parent 870833fc37
commit c2ed46cf5a
2 changed files with 10 additions and 4 deletions

View File

@ -273,7 +273,7 @@ def _group_runs_by_key(runs_by_time, groupby_key):
return grouped_runs_by
@app.route('/build_name/<string:build_name>/test_runs', methods=['GET'])
@app.route('/build_name/<path:build_name>/test_runs', methods=['GET'])
def get_test_runs_by_build_name(build_name):
value = parse.unquote(build_name)
if not value:

View File

@ -87,13 +87,13 @@ class TestRestAPI(base.TestCase):
'start_time': timestamp_a,
'stop_time': timestamp_b}
])
def test_get_test_runs_by_build_name(self, api_mock):
def _test_get_test_runs_by_build_name(self, build_name, api_mock):
api.region = mock.MagicMock()
api.region.cache_on_arguments = mock.MagicMock()
api.region.cache_on_arguments.return_value = lambda x: x
res = self.app.get('/build_name/fake_tests/test_runs')
res = self.app.get('/build_name/%s/test_runs' % build_name)
self.assertEqual(200, res.status_code)
api_mock.assert_called_once_with('build_name', 'fake_tests', None,
api_mock.assert_called_once_with('build_name', build_name, None,
None, api.Session())
expected_response = {
six.text_type(timestamp_a.isoformat()): {
@ -112,6 +112,12 @@ class TestRestAPI(base.TestCase):
self.assertEqual({u'tests': expected_response},
json.loads(res.data.decode('utf-8')))
def test_get_test_runs_by_build_name(self):
self._test_get_test_runs_by_build_name('fake_tests')
def test_get_test_runs_by_build_name_with_forward_slash(self):
self._test_get_test_runs_by_build_name('fake/tests')
def test_list_routes(self):
res = self.app.get('/')
res_dict = json.loads(res.data.decode('utf-8'))