aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorAlexanderlacuna2020-11-16 13:47:40 +0300
committerBonfaceKilz2021-01-06 01:26:38 +0300
commitdf2c3f9ee43dd055f7766eedee32d76090ad80b2 (patch)
treecb0e2b1a3e58b25ec54345d23badc2b5c012d21a /wqflask/tests
parent2bd74f8f4e4e72a11c77d4f3e8532c303503ca11 (diff)
downloadgenenetwork2-df2c3f9ee43dd055f7766eedee32d76090ad80b2.tar.gz
add unit testsfor api/correlation.py
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/unit/wqflask/api/test_correlation.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py
new file mode 100644
index 00000000..482dec67
--- /dev/null
+++ b/wqflask/tests/unit/wqflask/api/test_correlation.py
@@ -0,0 +1,83 @@
+import unittest
+from unittest import mock
+from wqflask import app
+from wqflask.api.correlation import init_corr_params
+from wqflask.api.correlation import convert_to_mouse_gene_id
+from wqflask.api.correlation import do_literature_correlation_for_all_traits
+
+
+class AttributeSetter:
+ def __init__(self, obj):
+ for k, v in obj.items():
+ setattr(self, k, v)
+
+
+class TestCorrelations(unittest.TestCase):
+ def setUp(self):
+ self.app_context = app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ self.app_context.pop()
+
+ def test_init_corr_params(self):
+ start_vars = {
+ "return_count": "3",
+ "type": "T1",
+ "method": "spearman"
+ }
+
+ corr_params_results = init_corr_params(start_vars=start_vars)
+ expected_results = {
+ "return_count": 3,
+ "type": "T1",
+ "method": "spearman"
+ }
+
+ self.assertEqual(corr_params_results, expected_results)
+
+ @mock.patch("wqflask.api.correlation.g")
+ def test_convert_to_mouse_gene_id(self, mock_db):
+
+ results = convert_to_mouse_gene_id(species="Other", gene_id="")
+ self.assertEqual(results, None)
+
+ rat_species_results = convert_to_mouse_gene_id(
+ species="rat", gene_id="GH1")
+
+ mock_db.db.execute.return_value.fetchone.side_effect = [AttributeSetter({"mouse": "MG-1"}),AttributeSetter({"mouse":"MG-2"})]
+
+ self.assertEqual(convert_to_mouse_gene_id(
+ species="mouse", gene_id="MG-4"), "MG-4")
+ self.assertEqual(convert_to_mouse_gene_id(
+ species="rat", gene_id="R1"), "MG-1")
+ self.assertEqual(convert_to_mouse_gene_id(
+ species="human", gene_id="H1"), "MG-2")
+
+
+
+ @mock.patch("wqflask.api.correlation.g")
+ @mock.patch("wqflask.api.correlation.convert_to_mouse_gene_id")
+ def test_do_literature_correlation_for_all_traits(self,mock_convert_to_mouse_geneid,mock_db):
+ mock_convert_to_mouse_geneid.side_effect=["MG-1","MG-2;","MG-3","MG-4"]
+
+
+ trait_geneid_dict={
+ "TT-1":"GH-1",
+ "TT-2":"GH-2",
+ "TT-3":"GH-3"
+
+ }
+ mock_db.db.execute.return_value.fetchone.side_effect=[AttributeSetter({"value":"V1"}),AttributeSetter({"value":"V2"}),AttributeSetter({"value":"V3"})]
+
+
+ this_trait=AttributeSetter({"geneid":"GH-1"})
+
+ target_dataset=AttributeSetter({"group":AttributeSetter({"species":"rat"})})
+ results=do_literature_correlation_for_all_traits(this_trait=this_trait,target_dataset=target_dataset,trait_geneid_dict=trait_geneid_dict,corr_params={})
+
+ expected_results={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 'V1'], 'TT-3': ['GH-3', 'V2']}
+ self.assertEqual(results,expected_results)
+
+
+