about summary refs log tree commit diff
path: root/tests/integration/test_correlation.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/test_correlation.py')
-rw-r--r--tests/integration/test_correlation.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/integration/test_correlation.py b/tests/integration/test_correlation.py
new file mode 100644
index 0000000..b94487a
--- /dev/null
+++ b/tests/integration/test_correlation.py
@@ -0,0 +1,57 @@
+"""Integration tests for correlation api"""
+
+import os
+import json
+import pickle
+import unittest
+from unittest import mock
+
+from gn3.app import create_app
+
+
+def file_path(relative_path):
+    """getting abs path for file """
+    dir_name = os.path.dirname(os.path.abspath(__file__))
+    split_path = relative_path.split("/")
+    new_path = os.path.join(dir_name, *split_path)
+    return new_path
+
+
+class CorrelationAPITest(unittest.TestCase):
+    # currently disable
+    """Test cases for the Correlation API"""
+
+    def setUp(self):
+        self.app = create_app().test_client()
+
+        with open(file_path("correlation_data.json")) as json_file:
+            self.correlation_data = json.load(json_file)
+
+        with open(file_path("expected_corr_results.json")) as results_file:
+            self.correlation_results = json.load(results_file)
+
+    def tearDown(self):
+        self.correlation_data = ""
+
+        self.correlation_results = ""
+
+    @mock.patch("gn3.api.correlation.compute_correlation")
+    def test_corr_compute(self, compute_corr):
+        """Test that the correct response in correlation"""
+
+        compute_corr.return_value = self.correlation_results
+        response = self.app.post(
+            "/api/correlation/corr_compute", json=self.correlation_data, follow_redirects=True)
+
+        self.assertEqual(response.status_code, 200)
+
+    @mock.patch("gn3.api.correlation.compute_correlation")
+    def test_corr_compute_failed_request(self,compute_corr):
+        """test taht cormpute requests fails """
+
+        compute_corr.return_value = self.correlation_results 
+
+        response  = self.app.post(
+            "/api/correlation/corr_compute", json=None, follow_redirects=True)
+
+        self.assertEqual(response.status_code,400)