diff --git a/releasenotes/notes/fix-get_ids_for_all_tests-typo-and-update-the-docstring-552735ca593c4613.yaml b/releasenotes/notes/fix-get_ids_for_all_tests-typo-and-update-the-docstring-552735ca593c4613.yaml new file mode 100644 index 0000000..478ec34 --- /dev/null +++ b/releasenotes/notes/fix-get_ids_for_all_tests-typo-and-update-the-docstring-552735ca593c4613.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Fix the get_ids_for_all_tests API typo and + update the docstring. (Story 2000580) diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 4532c90..aea807a 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -1157,15 +1157,15 @@ def get_id_from_test_id(test_id, session=None): def get_ids_for_all_tests(session=None): - """Return a list of ids (uuid primary key) for all tests in the database + """Return an iterator 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 + :return: The iterator of all ids for tests in the tests table + :rtype: iterator """ session = session or get_session() - return db_utils.model_query(models.Test, session).value(models.Test.id) + return db_utils.model_query(models.Test, session).values(models.Test.id) def get_run_times_grouped_by_run_metadata_key(key, start_date=None, diff --git a/subunit2sql/tests/db/test_api.py b/subunit2sql/tests/db/test_api.py index 7c76aee..faf990b 100644 --- a/subunit2sql/tests/db/test_api.py +++ b/subunit2sql/tests/db/test_api.py @@ -13,6 +13,7 @@ # under the License. import datetime +import types from six import moves import testscenarios @@ -1010,3 +1011,14 @@ class TestDatabaseAPI(base.TestCase): self.assertIn('attach_label_a', [x.label for x in res]) self.assertIn(b'attach', [x.attachment for x in res]) self.assertIn(b'attach_a', [x.attachment for x in res]) + + def test_get_ids_for_all_tests(self): + test_a = api.create_test('fake_test') + test_b = api.create_test('fake_test1') + test_c = api.create_test('fake_test2') + res = api.get_ids_for_all_tests() + self.assertIsInstance(res, types.GeneratorType) + res = list(res) + self.assertIn((test_c.id,), res) + self.assertIn((test_b.id,), res) + self.assertIn((test_a.id,), res)