From 8ce82f5b6cccc015c38a728864c63c026fe6a3a0 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Tue, 6 Apr 2021 23:11:22 +0300 Subject: add mock db for tests --- tests/integration/test_datasets.py | 6 ++++-- tests/integration/test_traits.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_datasets.py b/tests/integration/test_datasets.py index 34b7669..f97d970 100644 --- a/tests/integration/test_datasets.py +++ b/tests/integration/test_datasets.py @@ -28,12 +28,14 @@ class DatasetIntegrationTests(TestCase): self.assertEqual(response.status_code, 200) @mock.patch("gn3.api.datasets.get_traits_data") - def test_fetch_traits_data(self, mock_get_trait_data): + @mock.patch("gn3.api.datasets.database_connector") + def test_fetch_traits_data(self, mock_db, mock_get_trait_data): """Test api/dataset/fetch_traits_data/d_name/d_type""" mock_get_trait_data.return_value = {} + mock_db.return_value = (mock.Mock(), mock.Mock()) response = self.app.get( - "/api/dataset/fetch_traits_data/Aging-Brain-UCIPublish/Publish") + "/api/dataset/fetch_traits_data/Aging-Brain-UCIPublish/Publish", follow_redirects=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.get_json(), {"results": {}}) diff --git a/tests/integration/test_traits.py b/tests/integration/test_traits.py index 426bdd7..410ba22 100644 --- a/tests/integration/test_traits.py +++ b/tests/integration/test_traits.py @@ -13,10 +13,11 @@ class TraitIntegrationTest(TestCase): self.app = create_app().test_client() @mock.patch("gn3.api.traits.fetch_trait") - def test_create_trait(self, mock_fetch_trait): + @mock.patch("gn3.api.traits.database_connector") + def test_create_trait(self, mock_database, mock_fetch_trait): """test the endpoint for creating traits\ endpoint requires trait name and dataset name""" - + mock_database.return_value = (mock.Mock(), mock.Mock()) trait_results = { "dataset": None, "trait_name": "1449593_at", @@ -36,6 +37,7 @@ class TraitIntegrationTest(TestCase): trait_data = results.get_json() + self.assertEqual(mock_database.call_count, 1) self.assertEqual(results.status_code, 200) self.assertEqual(trait_data, trait_results) -- cgit v1.2.3