Fix db API get_ids_for_all_tests

This commit fix the get_ids_for_all_tests API typo
and update the docstring.

Story: #2000580
Change-Id: Iaefac14153fa7fcae9e05ccf7e8ced5e63f2a9c6
This commit is contained in:
Dong Ma 2016-04-27 06:28:23 +08:00
parent 12e373f5e3
commit 0479c1abec
3 changed files with 20 additions and 4 deletions

View File

@ -0,0 +1,4 @@
---
fixes:
- Fix the get_ids_for_all_tests API typo and
update the docstring. (Story 2000580)

View File

@ -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,

View File

@ -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)