Merge "Add caching on get_test_runs_by_build_name"
This commit is contained in:
commit
8d3faff9a4
@ -251,23 +251,30 @@ def _group_runs_by_key(runs_by_time, groupby_key):
|
|||||||
|
|
||||||
@app.route('/build_name/<string:build_name>/test_runs', methods=['GET'])
|
@app.route('/build_name/<string:build_name>/test_runs', methods=['GET'])
|
||||||
def get_test_runs_by_build_name(build_name):
|
def get_test_runs_by_build_name(build_name):
|
||||||
key = 'build_name'
|
|
||||||
value = parse.unquote(build_name)
|
value = parse.unquote(build_name)
|
||||||
if not key or not value:
|
if not value:
|
||||||
return 'A key and value must be specified', 400
|
return 'A build name must be specified', 400
|
||||||
start_date = _parse_datetimes(flask.request.args.get('start_date', None))
|
start_date = _parse_datetimes(flask.request.args.get('start_date', None))
|
||||||
stop_date = _parse_datetimes(flask.request.args.get('stop_date', None))
|
stop_date = _parse_datetimes(flask.request.args.get('stop_date', None))
|
||||||
datetime_resolution = flask.request.args.get('datetime_resolution', 'sec')
|
datetime_resolution = flask.request.args.get('datetime_resolution', 'sec')
|
||||||
if datetime_resolution not in ['sec', 'min', 'hour', 'day']:
|
if datetime_resolution not in ['sec', 'min', 'hour', 'day']:
|
||||||
return ('Datetime resolution: %s, is not a valid'
|
return ('Datetime resolution: %s, is not a valid'
|
||||||
' choice' % datetime_resolution), 400
|
' choice' % datetime_resolution), 400
|
||||||
|
|
||||||
|
@region.cache_on_arguments()
|
||||||
|
def _query_test_runs_by_build_name(name, start_date, stop_date):
|
||||||
with session_scope() as session:
|
with session_scope() as session:
|
||||||
tests = api.get_test_run_dict_by_run_meta_key_value(key, value,
|
tests = api.get_test_run_dict_by_run_meta_key_value('build_name',
|
||||||
|
name,
|
||||||
start_date,
|
start_date,
|
||||||
stop_date, session)
|
stop_date,
|
||||||
|
session)
|
||||||
tests = test_run_aggregator.TestRunAggregator(tests).aggregate(
|
tests = test_run_aggregator.TestRunAggregator(tests).aggregate(
|
||||||
datetime_resolution=datetime_resolution)
|
datetime_resolution=datetime_resolution)
|
||||||
return jsonify({'tests': tests})
|
return tests
|
||||||
|
|
||||||
|
output = _query_test_runs_by_build_name(value, start_date, stop_date)
|
||||||
|
return jsonify({'tests': output})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/runs', methods=['GET'])
|
@app.route('/runs', methods=['GET'])
|
||||||
|
@ -87,6 +87,9 @@ class TestRestAPI(base.TestCase):
|
|||||||
'stop_time': timestamp_b}
|
'stop_time': timestamp_b}
|
||||||
])
|
])
|
||||||
def test_get_test_runs_by_build_name(self, api_mock):
|
def test_get_test_runs_by_build_name(self, 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/fake_tests/test_runs')
|
||||||
self.assertEqual(200, res.status_code)
|
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', 'fake_tests', None,
|
||||||
|
Loading…
Reference in New Issue
Block a user