aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/correlation.py36
-rw-r--r--tests/integration/test_correlation.py18
2 files changed, 15 insertions, 39 deletions
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py
index 4e3e07e..217b7ce 100644
--- a/gn3/api/correlation.py
+++ b/gn3/api/correlation.py
@@ -1,23 +1,17 @@
"""Endpoints for computing correlation"""
-import pickle
import time
from flask import Blueprint
from flask import jsonify
from flask import request
from flask import g
-from flask import after_this_request
-from default_settings import SQL_URI
-
-# import pymysql
-
from sqlalchemy import create_engine
-from gn3.correlation.correlation_computations import compute_correlation
+from default_settings import SQL_URI
+from gn3.correlation.correlation_computations import compute_correlation
correlation = Blueprint("correlation", __name__)
-
# xtodo implement neat db setup
@correlation.before_request
def connect_db():
@@ -31,38 +25,20 @@ def connect_db():
g.initial_time = time.time()
-@correlation.after_request
-def after_request_func(response):
- final_time = time.time() - g.initial_time
- print(f"This request for Correlation took {final_time} Seconds")
-
- g.initial_time = None
-
- return response
-
-
-
-
@correlation.route("/corr_compute", methods=["POST"])
def corr_compute_page():
"""api for doing correlation"""
- # todo accepts both form and json data
-
correlation_input = request.json
if correlation_input is None:
- return jsonify({"error": str("Bad request")}),400
-
+ return jsonify({"error": str("Bad request")}), 400
-
try:
- corr_results = compute_correlation(correlation_input_data=correlation_input)
+ corr_results = compute_correlation(
+ correlation_input_data=correlation_input)
-
except Exception as error: # pylint: disable=broad-except
return jsonify({"error": str(error)})
- return {
- "correlation_results":corr_results
- } \ No newline at end of file
+ return {"correlation_results": corr_results}
diff --git a/tests/integration/test_correlation.py b/tests/integration/test_correlation.py
index b94487a..33e0de9 100644
--- a/tests/integration/test_correlation.py
+++ b/tests/integration/test_correlation.py
@@ -2,7 +2,6 @@
import os
import json
-import pickle
import unittest
from unittest import mock
@@ -20,7 +19,6 @@ def file_path(relative_path):
class CorrelationAPITest(unittest.TestCase):
# currently disable
"""Test cases for the Correlation API"""
-
def setUp(self):
self.app = create_app().test_client()
@@ -40,18 +38,20 @@ class CorrelationAPITest(unittest.TestCase):
"""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)
+ 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):
+ def test_corr_compute_failed_request(self, compute_corr):
"""test taht cormpute requests fails """
- compute_corr.return_value = self.correlation_results
+ compute_corr.return_value = self.correlation_results
- response = self.app.post(
- "/api/correlation/corr_compute", json=None, follow_redirects=True)
+ response = self.app.post("/api/correlation/corr_compute",
+ json=None,
+ follow_redirects=True)
- self.assertEqual(response.status_code,400)
+ self.assertEqual(response.status_code, 400)