From 81b82ede3004ee870f8dfe55d5fe23ee86e98137 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Fri, 12 Jan 2024 17:01:21 +0300 Subject: Correctly patch the db connection when fetching accession_id. Signed-off-by: Munyoki Kilyungi Co-authored-by: Alexander Kabui --- gn2/tests/unit/base/test_data_set.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'gn2/tests/unit') diff --git a/gn2/tests/unit/base/test_data_set.py b/gn2/tests/unit/base/test_data_set.py index 9f9fb132..d3d11022 100644 --- a/gn2/tests/unit/base/test_data_set.py +++ b/gn2/tests/unit/base/test_data_set.py @@ -204,13 +204,14 @@ class TestDataSetTypes(unittest.TestCase): class TestDatasetAccessionId(unittest.TestCase): """Tests for the DataSetType class""" - @mock.patch("gn2.base.data_set.dataset.query_sql") + @mock.patch("gn2.base.data_set.dataset.database_connection") @mock.patch("gn2.base.data_set.dataset.DatasetGroup") - def test_get_accession_id(self, mock_dataset_group, mock_query_sql): + def test_get_accession_id(self, mock_dataset_group, conn): def mock_fn(): yield MonadicDict({"accession_id": 7}) mock_dataset_group.return_value = MockGroup() - mock_query_sql.return_value = mock_fn() + conn = mock.MagicMock() + conn.return_value.__enter__ = mock_fn sample_dataset = MockPhenotypeDataset( name="BXD-LongevityPublish", get_samplelist=False, @@ -221,12 +222,13 @@ class TestDatasetAccessionId(unittest.TestCase): .accession_id\ .bind(lambda x: self.assertEqual(7, x)) - @mock.patch("gn2.base.data_set.dataset.query_sql") + @mock.patch("gn2.base.data_set.dataset.database_connection") @mock.patch("gn2.base.data_set.dataset.DatasetGroup") def test_get_accession_id_empty_return(self, mock_dataset_group, - mock_query_sql): + conn): mock_dataset_group.return_value = MockGroup() - mock_query_sql.return_value = None + conn = mock.MagicMock() + conn.return_value.__enter__ = None sample_dataset = MockPhenotypeDataset( name="BXD-LongevityPublish", get_samplelist=False, -- cgit v1.2.3