Add api to get recent failed runs by run_metadata
This commit adds a new DB API method to get a list of failed runs by run_metadata. Change-Id: Ic3463c1f9d9b4a20145467b3da1cdbf5344bbceb
This commit is contained in:
parent
6a00ad755f
commit
a26a6f0cfb
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Adds a new DB API method get_recent_failed_runs_by_run_metadata() that
|
||||||
|
will return a list of models.Run objects for recent failures on runs
|
||||||
|
with a specified run_metadata key value pair
|
@ -1522,6 +1522,31 @@ def add_test_run_attachments(attach_dict, test_run_id, session=None):
|
|||||||
return attachments
|
return attachments
|
||||||
|
|
||||||
|
|
||||||
|
def get_recent_failed_runs_by_run_metadata(key, value, num_runs=10,
|
||||||
|
start_date=None, session=None):
|
||||||
|
"""Get a list of recent failed runs for a given run metadata pair
|
||||||
|
|
||||||
|
:param str key: the run_metadata key to get failed runs
|
||||||
|
:param str value: The run_metadata value to get failed runs
|
||||||
|
:param int num_runs: The number of results to fetch, defaults to 10
|
||||||
|
:param datetime start_date: the optional starting dates to get runs from.
|
||||||
|
Nothing older than this date will be returned
|
||||||
|
:param session: optional session object if one isn't provided a new session
|
||||||
|
will be acquired for the duration of this operation
|
||||||
|
|
||||||
|
:return list: The list of recent failed Run objects
|
||||||
|
:rtype: subunit2sql.models.Run
|
||||||
|
"""
|
||||||
|
session = session or get_session()
|
||||||
|
query = db_utils.model_query(models.Run, session).join(
|
||||||
|
models.RunMetadata, models.Run.id == models.RunMetadata.run_id).filter(
|
||||||
|
models.RunMetadata.key == key,
|
||||||
|
models.RunMetadata.value == value)
|
||||||
|
query = _filter_runs_by_date(query, start_date)
|
||||||
|
return query.filter(models.Run.fails > 0).order_by(
|
||||||
|
models.Run.run_at.desc()).limit(num_runs).all()
|
||||||
|
|
||||||
|
|
||||||
def get_runs_by_status_grouped_by_run_metadata(key, start_date=None,
|
def get_runs_by_status_grouped_by_run_metadata(key, start_date=None,
|
||||||
stop_date=None, session=None):
|
stop_date=None, session=None):
|
||||||
session = session or get_session()
|
session = session or get_session()
|
||||||
|
@ -790,3 +790,28 @@ class TestDatabaseAPI(base.TestCase):
|
|||||||
for meta in test_metadata:
|
for meta in test_metadata:
|
||||||
self.assertIn(meta.key, test_meta.keys())
|
self.assertIn(meta.key, test_meta.keys())
|
||||||
self.assertIn(meta.value, test_meta.values())
|
self.assertIn(meta.value, test_meta.values())
|
||||||
|
|
||||||
|
def test_get_recent_failed_runs_by_run_metadata_no_start_date(self):
|
||||||
|
run_a = api.create_run(fails=1)
|
||||||
|
api.create_run()
|
||||||
|
run_c = api.create_run(fails=2)
|
||||||
|
api.add_run_metadata({'fake_key': 'fake_value'}, run_a.id)
|
||||||
|
api.add_run_metadata({'zeon': 'zaku'}, run_c.id)
|
||||||
|
results = api.get_recent_failed_runs_by_run_metadata('zeon', 'zaku')
|
||||||
|
self.assertEqual(1, len(results))
|
||||||
|
self.assertEqual(run_c.id, results[0].id)
|
||||||
|
|
||||||
|
def test_get_recent_failed_runs_by_run_metadata_with_start_date(self):
|
||||||
|
run_a = api.create_run(fails=1)
|
||||||
|
api.create_run()
|
||||||
|
run_c = api.create_run(fails=2)
|
||||||
|
run_d = api.create_run(fails=3,
|
||||||
|
run_at=datetime.datetime(1914, 6, 28,
|
||||||
|
10, 45, 0))
|
||||||
|
api.add_run_metadata({'fake_key': 'fake_value'}, run_a.id)
|
||||||
|
api.add_run_metadata({'zeon': 'zaku'}, run_c.id)
|
||||||
|
api.add_run_metadata({'zeon': 'zaku'}, run_d.id)
|
||||||
|
results = api.get_recent_failed_runs_by_run_metadata(
|
||||||
|
'zeon', 'zaku', start_date=datetime.date(1970, 1, 1))
|
||||||
|
self.assertEqual(1, len(results))
|
||||||
|
self.assertEqual(run_c.id, results[0].id)
|
||||||
|
Loading…
Reference in New Issue
Block a user