From e6f10522833cbd75441766e5b8656b3f5925d6d7 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Tue, 30 Mar 2021 18:12:58 +0300 Subject: initial commit for creating trait and datasets --- tests/integration/test_traits.py | 70 ++++++++++++++++++++++++++++++ tests/unit/computations/test_trait.py | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 tests/integration/test_traits.py create mode 100644 tests/unit/computations/test_trait.py (limited to 'tests') diff --git a/tests/integration/test_traits.py b/tests/integration/test_traits.py new file mode 100644 index 0000000..2f3433a --- /dev/null +++ b/tests/integration/test_traits.py @@ -0,0 +1,70 @@ +"""module contains integration tests for trait endpoints""" +from unittest import TestCase +from unittest import mock + +from gn3.app import create_app + + +class TraitIntegrationTest(TestCase): + """class contains integration tests for\ + traits""" + + def setUp(self): + self.app = create_app().test_client() + + def test_home(self): + """test for initial endpoint for trait""" + results = self.app.get("/api/trait", follow_redirects=True) + + self.assertEqual(200, results.status_code) + + @mock.patch("gn3.api.traits.fetch_trait") + def test_create_trait(self, mock_fetch_trait): + """test the endpoint for creating traits\ + endpoint requires trait name and dataset name""" + + trait_results = { + "dataset": None, + "trait_name": "1449593_at", + "trait_data": {} + + } + mock_fetch_trait.return_value = trait_results + + results = self.app.get( + "/api/trait/1449593_at/HC_M2_0606_P", follow_redirects=True) + + trait_data = results.get_json() + + self.assertEqual(results.status_code, 200) + self.assertEqual(trait_data, trait_results) + + @mock.patch("gn3.api.traits.get_trait_info_data") + def test_retrieve_trait_info(self, mock_get_trait_info): + """integration test for endpoints for retrieving\ + trait info expects the dataset of trait to have been + created""" + + trait_post_data = { + "trait": {"trait_name": ""}, + "trait_dataset": {"dataset_name": ""} + } + + expected_api_results = { + "description": "trait description", + "chr": "", + "locus": "", + "mb": "", + "abbreviation": "trait_abbreviation", + "trait_display_name": "trait_name" + + } + mock_get_trait_info.return_value = expected_api_results + + trait_info = self.app.post( + "/api/trait/trait_info/144_at", json=trait_post_data, follow_redirects=True) + + trait_info_results = trait_info.get_json() + + self.assertEqual(trait_info.status_code, 200) + self.assertEqual(trait_info_results, expected_api_results) diff --git a/tests/unit/computations/test_trait.py b/tests/unit/computations/test_trait.py new file mode 100644 index 0000000..20f0546 --- /dev/null +++ b/tests/unit/computations/test_trait.py @@ -0,0 +1,81 @@ +"""module contains tests for creating traits""" +from unittest import TestCase +from unittest import mock + +from gn3.computations.traits import compute_sum +from gn3.computations.traits import fetch_trait +from gn3.computations.traits import get_trait_sample_data +from gn3.computations.traits import get_trait_info_data + + +class TestTrait(TestCase): + """class contains tests for creating traits""" + + def test_sum(self): + """initial faling tests""" + results = compute_sum(2, 5) + self.assertEqual(results, 7) + + @mock.patch("gn3.computations.traits.get_trait_sample_data") + def test_fetch_trait(self, get_sample_data): + """test for creating/fetching trait""" + + expected_sample_data = { + "A/Y": 12.3, + "WQC": 11.1 + } + + get_sample_data.return_value = expected_sample_data + + expected_trait = { + "trait_name": "AXFDSF_AT", + "dataset": None, + "trait_data": expected_sample_data + } + results = fetch_trait(dataset=None, trait_name="AXFDSF_AT") + + self.assertEqual(results, expected_trait) + get_sample_data.assert_called_once_with(None, "AXFDSF_AT") + + def test_get_trait_sample_data(self): + """test for getting sample data from either\ + the trait's dataset or form redis""" + + trait_dataset = mock.Mock() + dataset_trait_sample_data = [ + ('129S1/SvImJ', 7.433, None, None, '129S1/SvImJ'), + ('A/J', 7.596, None, None, 'A/J'), + ('AKR/J', 7.774, None, None, 'AKR/J'), + ('B6D2F1', 7.707, None, None, 'B6D2F1')] + trait_dataset.retrieve_sample_data.return_value = dataset_trait_sample_data + + trait_name = "1426679_at" + + results = get_trait_sample_data( + trait_dataset, trait_name) + + expected_results = { + "129S1/SvImJ": 7.433, + "A/J": 7.596, + "AKR/J": 7.774, + "B6D2F1": 7.707 + } + + self.assertEqual(results, expected_results) + + def test_get_trait_info_data(self): + """test for getting info data related\ + to trait""" + + results = get_trait_info_data( + trait_name="AXSF_AT", trait_dataset=mock.Mock(), database_instance=None) + expected_trait_info = { + "description": "", + "trait_display_name": "", + "abbreviation": "", + "chr": "", + "mb": "", + "locus": "" + } + + self.assertEqual(results, expected_trait_info) -- cgit v1.2.3