Merge "Add DB API function to get list of runs from ids"

This commit is contained in:
Jenkins 2016-08-10 07:38:06 +00:00 committed by Gerrit Code Review
commit 3ea602d94d
3 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
features:
- A new DB API function, get_runs_by_ids(), was added. This function returns
a list of Run objects from a list of run ids.

View File

@ -753,6 +753,22 @@ def get_run_by_id(id, session=None):
return run
def get_runs_by_ids(ids, session=None):
"""Get a list of runs by their ids.
:param list id: A list of run ids for the run
:param session: Optional session object if one isn't provided a new session
will be acquired for the duration of this operation
:return: The list of the specified run objects
:rtype: list
"""
session = session or get_session()
run = db_utils.model_query(models.Run, session).filter(
models.Run.id.in_(ids)).all()
return run
def get_test_run_by_id(test_run_id, session=None):
"""Get an individual test run by it's id.

View File

@ -804,6 +804,15 @@ class TestDatabaseAPI(base.TestCase):
self.assertEqual(res.id, run.id)
self.assertEqual(res.uuid, run.uuid)
def test_get_runs_by_ids(self):
run_a = api.create_run()
run_b = api.create_run()
res = api.get_runs_by_ids([run_a.id, run_b.id])
self.assertIn(run_a.id, [x.id for x in res])
self.assertIn(run_b.id, [x.id for x in res])
self.assertIn(run_a.uuid, [x.uuid for x in res])
self.assertIn(run_b.uuid, [x.uuid for x in res])
def test_get_test_runs_by_test_id(self):
run_a = api.create_run()
run_b = api.create_run()