From daf7eedd79a2dab00a452adcf88aa59373e776a4 Mon Sep 17 00:00:00 2001 From: Dong Ma Date: Mon, 11 Apr 2016 15:14:02 +0800 Subject: [PATCH] Fix get_test_metadata to use test_id The API should use test_id to get all the metadata. Change-Id: I99a3b1ebf6dc80378d2d5da28ad273702f9fad71 --- ...t_metadata-to-use-test_id-48217d4c7a22b9aa.yaml | 3 +++ subunit2sql/db/api.py | 2 +- subunit2sql/tests/db/test_api.py | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-get_test_metadata-to-use-test_id-48217d4c7a22b9aa.yaml diff --git a/releasenotes/notes/fix-get_test_metadata-to-use-test_id-48217d4c7a22b9aa.yaml b/releasenotes/notes/fix-get_test_metadata-to-use-test_id-48217d4c7a22b9aa.yaml new file mode 100644 index 0000000..0fcfe9a --- /dev/null +++ b/releasenotes/notes/fix-get_test_metadata-to-use-test_id-48217d4c7a22b9aa.yaml @@ -0,0 +1,3 @@ +--- +fixes: + - Fix get_test_metadata DB API using test_id to get all metadata. diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 1171576..ad3fbe8 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -446,7 +446,7 @@ def get_test_metadata(test_id, session=None): """ session = session or get_session() query = db_utils.model_query(models.TestMetadata, session).filter_by( - id=test_id) + test_id=test_id) return query.all() diff --git a/subunit2sql/tests/db/test_api.py b/subunit2sql/tests/db/test_api.py index ca7c1bd..766cc3f 100644 --- a/subunit2sql/tests/db/test_api.py +++ b/subunit2sql/tests/db/test_api.py @@ -776,3 +776,17 @@ class TestDatabaseAPI(base.TestCase): self.assertIn(run_a.id, [x.run_id for x in res]) self.assertIn(run_b.id, [x.run_id for x in res]) self.assertIn(run_c.id, [x.run_id for x in res]) + + def test_get_test_metadata(self): + test = api.create_test('fake_test') + test_meta = { + 'test_a': 'a', + 'test_b': 'b', + 'test_c': 'c', + } + api.add_test_metadata(test_meta, test.id) + test_metadata = api.get_test_metadata(test.id) + self.assertEqual(3, len(test_metadata)) + for meta in test_metadata: + self.assertIn(meta.key, test_meta.keys()) + self.assertIn(meta.value, test_meta.values())