Merge "Enable returning run id in get_test_runs_by_status_for_run_ids()"

This commit is contained in:
Jenkins 2016-05-20 13:29:29 +00:00 committed by Gerrit Code Review
commit 6e79c4c569
3 changed files with 42 additions and 3 deletions

View File

@ -0,0 +1,4 @@
---
features:
- A new option on get_test_runs_by_status_for_run_ids(), include_run_id, to
include the run uuid in the run dicts returned

View File

@ -1607,7 +1607,7 @@ def get_runs_by_status_grouped_by_run_metadata(key, start_date=None,
def get_test_runs_by_status_for_run_ids(status, run_ids, key=None,
session=None):
session=None, include_run_id=False):
"""Get a list of test run dicts by status for all the specified runs
:param str status: The test status to filter the returned test runs on
@ -1617,6 +1617,8 @@ def get_test_runs_by_status_for_run_ids(status, run_ids, key=None,
to the output dict for each test_run
:param session: Optional session object if one isn't provided a new session
will be acquired for the duration of this operation
:param bool include_run_id: boolean flag to enable including the run uuid
in the test run dicts returned
:return test_runs: A list of dicts for the test_runs and associated data
:rtype: list
@ -1638,13 +1640,15 @@ def get_test_runs_by_status_for_run_ids(status, run_ids, key=None,
models.TestRun.start_time_microsecond,
models.TestRun.stop_time,
models.TestRun.stop_time_microsecond,
models.RunMetadata.value)
models.RunMetadata.value,
models.Run.uuid)
else:
results = query.values(models.Test.test_id, models.Run.artifacts,
models.TestRun.start_time,
models.TestRun.start_time_microsecond,
models.TestRun.stop_time,
models.TestRun.stop_time_microsecond)
models.TestRun.stop_time_microsecond,
models.Run.uuid)
test_runs = []
for result in results:
test_run = {
@ -1653,6 +1657,8 @@ def get_test_runs_by_status_for_run_ids(status, run_ids, key=None,
'start_time': result.start_time,
'stop_time': result.stop_time,
}
if include_run_id:
test_run['uuid'] = result.uuid
if result.start_time_microsecond is not None:
test_run['start_time'] = test_run['start_time'].replace(
microsecond=result.start_time_microsecond)

View File

@ -658,6 +658,35 @@ class TestDatabaseAPI(base.TestCase):
'a_key': 'b',
}, result[0])
def test_get_test_runs_by_status_for_run_ids_with_run_id(self):
run_b = api.create_run(artifacts='fake_url')
run_a = api.create_run()
run_c = api.create_run()
test_a = api.create_test('fake_test')
api.add_run_metadata({'a_key': 'b'}, run_b.id)
api.add_run_metadata({'a_key': 'a'}, run_a.id)
api.add_run_metadata({'a_key': 'c'}, run_c.id)
start_timestamp = datetime.datetime(1914, 6, 28, 10, 45, 0)
stop_timestamp = datetime.datetime(1914, 6, 28, 10, 50, 0)
api.create_test_run(test_a.id, run_a.id, 'success',
datetime.datetime.utcnow())
api.create_test_run(test_a.id, run_b.id, 'fail',
start_timestamp, stop_timestamp)
api.create_test_run(test_a.id, run_c.id, 'success',
datetime.datetime.utcnow())
result = api.get_test_runs_by_status_for_run_ids(
'fail', [run_a.uuid, run_b.uuid, run_c.uuid], key='a_key',
include_run_id=True)
self.assertEqual(1, len(result))
self.assertEqual({
'test_id': u'fake_test',
'link': u'fake_url',
'start_time': start_timestamp,
'stop_time': stop_timestamp,
'a_key': 'b',
'uuid': run_b.uuid,
}, result[0])
def test_get_all_runs_time_series_by_key_with_overlap(self):
time_a = datetime.datetime(1914, 6, 28, 10, 45, 0)
run_a = api.create_run(run_at=time_a)