From 580778386f054706086d7ab3d49f2c4f91f110e0 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 22 Sep 2021 00:48:37 +0300 Subject: init endpoint tests for wgcna --- tests/integration/test_wgcna.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/integration/test_wgcna.py (limited to 'tests/integration') diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py new file mode 100644 index 0000000..65763c1 --- /dev/null +++ b/tests/integration/test_wgcna.py @@ -0,0 +1,37 @@ +"""integration tests for wgcna""" + +from unittest import TestCase +from unittest import mock + +from gn3.app import create_app + + +class WgcnaIntegrationTest(TestCase): + """class contains wgcna integration tests""" + + def setUp(self): + self.app = create_app().test_client() + + @mock.patch("gn3.api.wgcna.call_wgcna_script") + def test_wgcna_endpoint(self, mock_wgcna_api): + """test /api/wgcna/run_wgcna endpoint""" + + wgcna_api_data = { + "eigengenes": ["1224_at", "121412_at", "32342342-at"], + "dendrogram_file_location": "/tmp/dend1.png" + + } + mock_wgcna_api.return_value = wgcna_api_data + + request_data = { + + "trait_sample_data": [], + + + } + + response = self.app.post("/api/wgcna/run_wgcna", + json=request_data, follow_redirects=True) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.get_json(), wgcna_api_data) -- cgit v1.2.3 From 7dbb0e6d27cdb0923e94685cf44d244dd8a2e105 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Sat, 25 Sep 2021 18:33:12 +0300 Subject: minor fixes for unittests --- tests/integration/test_wgcna.py | 2 +- tests/unit/computations/test_wgcna.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py index 65763c1..39dabb2 100644 --- a/tests/integration/test_wgcna.py +++ b/tests/integration/test_wgcna.py @@ -33,5 +33,5 @@ class WgcnaIntegrationTest(TestCase): response = self.app.post("/api/wgcna/run_wgcna", json=request_data, follow_redirects=True) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 401) self.assertEqual(response.get_json(), wgcna_api_data) diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index fd90732..64f6c14 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -25,9 +25,9 @@ class TestWgcna(TestCase): def test_compose_wgcna_cmd(self): """test for composing wgcna cmd""" wgcna_cmd = compose_wgcna_cmd( - "/wgcna.r", "/tmp/wgcna.json") + "wgcna.r", "/tmp/wgcna.json") self.assertEqual( - wgcna_cmd, "Rscript /wgcna.r /tmp/wgcna.json") + wgcna_cmd, "Rscript ./scripts/wgcna.r /tmp/wgcna.json") @skip("to update tests") def test_create_json_file(self): -- cgit v1.2.3 From a2da1f5dbc49b0137ef6b8ee9e234178521935f3 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Mon, 27 Sep 2021 19:15:23 +0300 Subject: modify integration tests --- tests/integration/test_wgcna.py | 60 ++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py index 39dabb2..078449d 100644 --- a/tests/integration/test_wgcna.py +++ b/tests/integration/test_wgcna.py @@ -13,25 +13,61 @@ class WgcnaIntegrationTest(TestCase): self.app = create_app().test_client() @mock.patch("gn3.api.wgcna.call_wgcna_script") - def test_wgcna_endpoint(self, mock_wgcna_api): + def test_wgcna_endpoint(self, mock_wgcna_script): """test /api/wgcna/run_wgcna endpoint""" - wgcna_api_data = { - "eigengenes": ["1224_at", "121412_at", "32342342-at"], - "dendrogram_file_location": "/tmp/dend1.png" - + wgcna_output_data = { + "code": 0, + "output": "run script successfully", + "data": { + "ModEigens": { + "MEturquoise": [ + 0.0646677768085351, + 0.137200224277058, + 0.63451113720732, + -0.544002665501479, + -0.489487590361863, + 0.197111117570427 + ] + }, + "net_colors": { + "X1": "turquoise", + "X2": "turquoise", + "X3": "turquoise", + "X4": "turquoise" + }, + "imageLoc": "/WGCNAoutput_1uujpTIpC.png" + } } - mock_wgcna_api.return_value = wgcna_api_data request_data = { - - "trait_sample_data": [], - - + "trait_names": [ + "1455537_at", + "1425637_at" + ], + "trait_sample_data": [ + { + "129S1/SvImJ": 6.142, + "A/J": 5.31, + "AKR/J": 3.49, + "B6D2F1": 2.899, + "BALB/cByJ": 1.172, + "BALB/cJ": 7.396 + }, + { + "129S1/SvImJ": 1.42, + "A/J": 2.31, + "AKR/J": 5.49, + "B6D2F1": 3.899, + "BALB/cByJ": 1.172, + "BALB/cJ": 7.396 + } + ] } + mock_wgcna_script.return_value = wgcna_output_data response = self.app.post("/api/wgcna/run_wgcna", json=request_data, follow_redirects=True) - self.assertEqual(response.status_code, 401) - self.assertEqual(response.get_json(), wgcna_api_data) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.get_json(), wgcna_output_data) -- cgit v1.2.3