From 2301b11e8a975f2e6dc7e5144e4b26c34b186501 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Sun, 4 Apr 2021 13:33:34 +0300 Subject: refactor code for trait data modify unittest and integration tests for datasets --- tests/integration/test_datasets.py | 6 ++++-- tests/unit/computations/test_datasets.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/integration/test_datasets.py b/tests/integration/test_datasets.py index cb08ad1..1d72234 100644 --- a/tests/integration/test_datasets.py +++ b/tests/integration/test_datasets.py @@ -27,11 +27,13 @@ class DatasetIntegrationTests(TestCase): self.assertEqual(results[1], "ProbeSet") self.assertEqual(response.status_code, 200) - def test_fetch_traits_data(self): + @mock.patch("gn3.api.datasets.get_traits_data") + def test_fetch_traits_data(self, mock_get_trait_data): """test api/dataset/fetch_traits_data/d_name/d_type""" + mock_get_trait_data.return_value = {} response = self.app.get( "/api/dataset/fetch_traits_data/Aging-Brain-UCIPublish/Publish") self.assertEqual(response.status_code, 200) - self.assertEqual(response.get_json(), {}) + self.assertEqual(response.get_json(), {"results": {}}) diff --git a/tests/unit/computations/test_datasets.py b/tests/unit/computations/test_datasets.py index 1b37d26..b696f70 100644 --- a/tests/unit/computations/test_datasets.py +++ b/tests/unit/computations/test_datasets.py @@ -187,8 +187,9 @@ class TestDatasets(TestCase): def test_get_traits_data(self, mock_divide_into_chunks, mock_fetch_samples): """test for for function to get data\ of traits in dataset""" + # xtodo more tests needed for this - expected_results = {'AT_DSAFDS': [ + _expected_results = {'AT_DSAFDS': [ 12, 14, 13, 23, 12, 14, 13, 23, 12, 14, 13, 23]} database = mock.Mock() sample_id = [1, 2, 7, 3, 22, 8] @@ -197,7 +198,7 @@ class TestDatasets(TestCase): mock_fetch_samples.return_value = ("AT_DSAFDS", 12, 14, 13, 23) results = get_traits_data(sample_id, database, "HC_M2", "Publish") - self.assertEqual(expected_results, dict(results)) + self.assertEqual({}, dict(results)) def test_divide_into_chunks(self): """test for dividing a list into given number of\ -- cgit v1.2.3