From f519640c7b7f9d3ddf78308bbc7b30a37f1daba3 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 6 May 2015 16:26:34 -0400 Subject: [PATCH] Add db api method to get uuid from test_id This commit adds 2 new db api methods to deal with taking the test_id column and finding the value of the matching id. The first method will return the id value for a given test_id, while the second returns the list of all ids in the tests table. Change-Id: I696aebd499ed47a20af0c13415fc568f2b54f188 --- subunit2sql/db/api.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index f3e4b47..f4e0af6 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -672,3 +672,29 @@ def delete_old_test_runs(expire_age=186, session=None): db_utils.model_query(models.TestRun, session).filter( models.TestRun.start_time < expire_date).delete( synchronize_session='evaluate') + + +def get_id_from_test_id(test_id, session=None): + """Return the id (uuid primary key) for a test given it's test_id value + + :param str test_id: + :param session: optional session object if one isn't provided a new session + will be acquired for the duration of this operation + :return: The id for the specified test + :rtype: str + """ + session = session or get_session() + return db_utils.model_query(models.Test, session).filter_by( + test_id=test_id).value('id') + + +def get_ids_for_all_tests(session=None): + """Return a list of ids (uuid primary key) for all tests in the database + + :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 all ids for tests in the tests table + :rtype: list + """ + session = session or get_session() + return db_utils.model_query(models.Test, session).value(models.Test.id)