about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorAlexander Kabui2021-03-31 22:29:37 +0300
committerAlexander Kabui2021-03-31 22:29:37 +0300
commitf6c6851504f14a1a163b6eeb5e3653a5ec3f5ceb (patch)
treef4a4bfc24055065357b7bb59e73ded19f5a97b35 /tests
parentb88d63ac06f157a97cc88bee0ea702949a5a0c64 (diff)
downloadgenenetwork3-f6c6851504f14a1a163b6eeb5e3653a5ec3f5ceb.tar.gz
add datasets functions and endpoints
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/computations/test_datasets.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/unit/computations/test_datasets.py b/tests/unit/computations/test_datasets.py
index 408f13b..7135041 100644
--- a/tests/unit/computations/test_datasets.py
+++ b/tests/unit/computations/test_datasets.py
@@ -1,10 +1,18 @@
 """module contains tests from datasets"""
+import json
+
 from unittest import TestCase
 from unittest import mock
 
+from collections import namedtuple
+
 from gn3.computations.datasets import retrieve_trait_sample_data
 from gn3.computations.datasets import get_query_for_dataset_sample
 from gn3.computations.datasets import fetch_from_db_sample_data
+from gn3.computations.datasets import create_dataset
+from gn3.computations.datasets import dataset_creator_store
+from gn3.computations.datasets import dataset_type_getter
+from gn3.computations.datasets import fetch_dataset_type_from_gn2_api
 
 
 class TestDatasets(TestCase):
@@ -74,3 +82,78 @@ class TestDatasets(TestCase):
         fetch_results = fetch_from_db_sample_data(mock_pheno_query, database)
 
         self.assertEqual(fetch_results, database_results)
+
+    @mock.patch("gn3.computations.datasets.dataset_creator_store")
+    @mock.patch("gn3.computations.datasets.dataset_type_getter")
+    def test_create_dataset(self, mock_dataset_type, mock_store):
+        """test function that creates/fetches required dataset\
+        can either be published phenotype,genotype,Microarray or\
+        user defined ->Temp"""
+        probe_name = "HC_M2_0606_P"
+        probe_type = "ProbeSet"
+
+        mock_dataset_creator = namedtuple(
+            'ProbeSet', ["dataset_name", "dataset_type"])
+
+        mock_store.return_value = mock_dataset_creator
+        mock_dataset_type.return_value = probe_type
+        dataset = create_dataset(
+            dataset_type=None, dataset_name=probe_name)
+
+        self.assertEqual(dataset.dataset_name, probe_name)
+        self.assertEqual(dataset.dataset_type, probe_type)
+
+    def test_dataset_creator_store(self):
+        """test  for functions that actual
+        function to create differerent \
+        datasets"""
+        results = dataset_creator_store("ProbeSet")
+
+        self.assertTrue(results)
+
+    def test_dataset_type_getter(self):
+        """test for fetching type of dataset given\
+        the dataset name"""
+
+        redis_instance = mock.Mock()
+        # found in redis
+        redis_instance.get.return_value = "ProbeSet"
+        results = dataset_type_getter("HC_M2_0_P", redis_instance)
+        self.assertEqual(results, "ProbeSet")
+
+    @mock.patch("gn3.computations.datasets.requests")
+    def test_fetch_dataset_type_from_gn2_api(self, mock_request):
+        """test for function that test fetching\
+        all datasets from gn2 api in order to store\
+        in redis"""
+
+        expected_json_results = {"datasets": {
+            "arabidopsis": {
+                "BayXSha": {
+                    "Genotypes": [
+                        [
+                            "None",
+                            "BayXShaGeno",
+                            "BayXSha Genotypes"
+                        ]
+                    ],
+                    "Phenotypes": [
+                        [
+                            "642",
+                            "BayXShaPublish",
+                            "BayXSha Published Phenotypes"
+                        ]
+                    ]
+                }
+            }
+        }}
+
+        request_results = json.dumps(expected_json_results)
+        mock_request.get.return_value.content = request_results
+        results = fetch_dataset_type_from_gn2_api("HC_M2_0_P")
+        expected_results = {
+            "BayXShaGeno": "Geno",
+            "642": "Publish"
+        }
+
+        self.assertEqual(expected_results, results)