Merge "Add optional run_metadata filter to get_test_runs_by_test_test_id"
This commit is contained in:
@@ -646,7 +646,7 @@ def get_test_runs_by_test_id(test_id, session=None):
|
||||
|
||||
|
||||
def get_test_runs_by_test_test_id(test_id, start_date=None, stop_date=None,
|
||||
session=None):
|
||||
session=None, key=None, value=None):
|
||||
"""Get all test runs for a specific test by the test'stest_id column
|
||||
|
||||
:param str test_id: The test's test_id (the test_id column in the test
|
||||
@@ -657,6 +657,12 @@ def get_test_runs_by_test_test_id(test_id, start_date=None, stop_date=None,
|
||||
results
|
||||
:param datetime.datetime stop_date: The date to use as the cutoff date for
|
||||
results
|
||||
:param str key: an optional key for run metadata to filter the test runs
|
||||
on. Must be specified with a value otherwise it does
|
||||
nothing.
|
||||
:param str value: an optional value for run metadata to filter the test
|
||||
runs on. Must be specified with a key otherwise it does
|
||||
nothing.
|
||||
|
||||
:return list: The list of test run objects for the specified test
|
||||
:rtype: subunit2sql.models.TestRun
|
||||
@@ -673,6 +679,12 @@ def get_test_runs_by_test_test_id(test_id, start_date=None, stop_date=None,
|
||||
if stop_date:
|
||||
test_runs_query = test_runs_query.filter(
|
||||
models.TestRun.start_time <= stop_date)
|
||||
if key and value:
|
||||
test_runs_query = test_runs_query.join(
|
||||
models.RunMetadata,
|
||||
models.TestRun.run_id == models.RunMetadata.run_id).filter(
|
||||
models.RunMetadata.key == key,
|
||||
models.RunMetadata.value == value)
|
||||
test_runs = test_runs_query.all()
|
||||
return test_runs
|
||||
|
||||
|
||||
@@ -313,6 +313,23 @@ class TestDatabaseAPI(base.TestCase):
|
||||
self.assertEqual(test_b.id, res[0].test_id)
|
||||
self.assertEqual(run.id, res[0].run_id)
|
||||
|
||||
def test_get_test_runs_test_test_id_with_run_metadata(self):
|
||||
run_a = api.create_run()
|
||||
run_b = api.create_run()
|
||||
api.add_run_metadata({'a_key': 'a_value'}, run_a.id)
|
||||
api.add_run_metadata({'b_key': 'b_value'}, run_b.id)
|
||||
test_a = api.create_test('fake_test')
|
||||
test_b = api.create_test('less_fake_test')
|
||||
api.create_test_run(test_a.id, run_a.id, 'success')
|
||||
api.create_test_run(test_a.id, run_b.id, 'success')
|
||||
api.create_test_run(test_b.id, run_a.id, 'success')
|
||||
api.create_test_run(test_b.id, run_b.id, 'success')
|
||||
res = api.get_test_runs_by_test_test_id('less_fake_test', key='a_key',
|
||||
value='a_value')
|
||||
self.assertEqual(1, len(res))
|
||||
self.assertEqual(test_b.id, res[0].test_id)
|
||||
self.assertEqual(run_a.id, res[0].run_id)
|
||||
|
||||
def test_get_all_run_metadata_keys(self):
|
||||
run = api.create_run()
|
||||
meta_dict = {
|
||||
|
||||
Reference in New Issue
Block a user