Merge "Add recent/detail openstack-health api."
This commit is contained in:
commit
9f95c43f97
|
@ -276,25 +276,40 @@ def get_runs_by_run_metadata_key(run_metadata_key, value):
|
|||
@app.route('/runs/key/<path:run_metadata_key>/<path:value>/recent',
|
||||
methods=['GET'])
|
||||
def get_recent_runs(run_metadata_key, value):
|
||||
runs = get_recent_runs_data(run_metadata_key, value)
|
||||
return jsonify(runs)
|
||||
|
||||
|
||||
@app.route('/runs/key/<path:run_metadata_key>/<path:value>/recent/detail',
|
||||
methods=['GET'])
|
||||
def get_recent_runs_detail(run_metadata_key, value):
|
||||
runs = get_recent_runs_data(run_metadata_key, value, detail=True)
|
||||
return jsonify(runs)
|
||||
|
||||
|
||||
def get_recent_runs_data(run_metadata_key, value, detail=False):
|
||||
num_runs = flask.request.args.get('num_runs', 10)
|
||||
with session_scope() as session:
|
||||
results = api.get_recent_runs_by_key_value_metadata(
|
||||
run_metadata_key, value, num_runs, session)
|
||||
runs = []
|
||||
for result in results:
|
||||
if result.passes > 0 and result.fails == 0:
|
||||
status = 'success'
|
||||
elif result.fails > 0:
|
||||
status = 'fail'
|
||||
if detail:
|
||||
run = result.to_dict()
|
||||
else:
|
||||
continue
|
||||
if result.passes > 0 and result.fails == 0:
|
||||
status = 'success'
|
||||
elif result.fails > 0:
|
||||
status = 'fail'
|
||||
else:
|
||||
continue
|
||||
|
||||
run = {
|
||||
'id': result.uuid,
|
||||
'status': status,
|
||||
'start_date': result.run_at.isoformat(),
|
||||
'link': result.artifacts,
|
||||
}
|
||||
run = {
|
||||
'id': result.uuid,
|
||||
'status': status,
|
||||
'start_date': result.run_at.isoformat(),
|
||||
'link': result.artifacts,
|
||||
}
|
||||
|
||||
run_meta = api.get_run_metadata(result.uuid, session)
|
||||
for meta in run_meta:
|
||||
|
@ -302,7 +317,7 @@ def get_recent_runs(run_metadata_key, value):
|
|||
run['build_name'] = meta.value
|
||||
break
|
||||
runs.append(run)
|
||||
return jsonify(runs)
|
||||
return runs
|
||||
|
||||
|
||||
@app.route('/tests/recent/<string:status>', methods=['GET'])
|
||||
|
|
|
@ -768,6 +768,36 @@ class TestRestAPI(base.TestCase):
|
|||
}]
|
||||
self.assertEqual(expected_res, response_data)
|
||||
|
||||
@mock.patch('subunit2sql.db.api.get_run_metadata',
|
||||
return_value=[models.RunMetadata(key='build_name',
|
||||
value='job')])
|
||||
@mock.patch('subunit2sql.db.api.get_recent_runs_by_key_value_metadata',
|
||||
return_value=[
|
||||
models.Run(uuid='uuid', run_at=timestamp_a,
|
||||
artifacts='http://fake_url', passes=2, fails=0,
|
||||
id='a_id', run_time=174, skips=10),
|
||||
])
|
||||
def test_get_recent_runs_detail(self, api_mock, api_meta_mock):
|
||||
api.Session = mock.MagicMock()
|
||||
res = self.app.get('/runs/key/a_key/a_value/recent/detail')
|
||||
self.assertEqual(200, res.status_code)
|
||||
api_mock.assert_called_once_with('a_key', 'a_value',
|
||||
10, api.Session())
|
||||
response_data = json.loads(res.data.decode('utf-8'))
|
||||
format_time = timestamp_a.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
expected_res = [{
|
||||
u'artifacts': u'http://fake_url',
|
||||
u'id': u'a_id',
|
||||
u'build_name': u'job',
|
||||
u'fails': 0,
|
||||
u'passes': 2,
|
||||
u'skips': 10,
|
||||
u'run_at': format_time,
|
||||
u'run_time': 174,
|
||||
u'uuid': u'uuid'
|
||||
}]
|
||||
self.assertEqual(expected_res, response_data)
|
||||
|
||||
@mock.patch('subunit2sql.db.api.get_recent_failed_runs',
|
||||
return_value=['a_convincing_id'])
|
||||
@mock.patch('subunit2sql.db.api.get_test_runs_by_status_for_run_ids',
|
||||
|
|
Loading…
Reference in New Issue