about summary refs log tree commit diff
path: root/tests/integration
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/conftest.py15
-rw-r--r--tests/integration/test_gemma.py66
-rw-r--r--tests/integration/test_lmdb_sample_data.py31
-rw-r--r--tests/integration/test_partial_correlations.py2
4 files changed, 73 insertions, 41 deletions
diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py
index 8e39726..bdbab09 100644
--- a/tests/integration/conftest.py
+++ b/tests/integration/conftest.py
@@ -1,4 +1,5 @@
 """Module that holds fixtures for integration tests"""
+from pathlib import Path
 import pytest
 import MySQLdb
 
@@ -6,19 +7,25 @@ from gn3.app import create_app
 from gn3.chancy import random_string
 from gn3.db_utils import parse_db_url, database_connection
 
+
 @pytest.fixture(scope="session")
 def client():
     """Create a test client fixture for tests"""
     # Do some setup
-    app = create_app()
-    app.config.update({"TESTING": True})
-    app.testing = True
+    app = create_app({
+        "TESTING": True,
+        "LMDB_DATA_PATH": str(
+            Path(__file__).parent.parent /
+            Path("test_data/lmdb-test-data")
+        ),
+        "AUTH_SERVER_URL": "http://127.0.0.1:8081",
+    })
     yield app.test_client()
     # Do some teardown/cleanup
 
 
 @pytest.fixture(scope="session")
-def db_conn(client): # pylint: disable=[redefined-outer-name]
+def db_conn(client):  # pylint: disable=[redefined-outer-name]
     """Create a db connection fixture for tests"""
     # 01) Generate random string to append to all test db artifacts for the session
     live_db_uri = client.application.config["SQL_URI"]
diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py
index 53a1596..7bc1df9 100644
--- a/tests/integration/test_gemma.py
+++ b/tests/integration/test_gemma.py
@@ -63,10 +63,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_k_compute(self, mock_ipfs_cache,
-                       mock_redis,
-                       mock_path_exist, mock_json, mock_hash,
-                       mock_queue_cmd):
+    def test_k_compute(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/k-compute/<token>"""
         mock_ipfs_cache.return_value = ("/tmp/cache/"
                                         "QmQPeNsJPyVWPFDVHb"
@@ -106,9 +105,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_k_compute_loco(self, mock_ipfs_cache,
-                            mock_redis, mock_path_exist, mock_json,
-                            mock_hash, mock_queue_cmd):
+    def test_k_compute_loco(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/k-compute/loco/<chromosomes>/<token>"""
         mock_ipfs_cache.return_value = ("/tmp/cache/"
                                         "QmQPeNsJPyVWPFDVHb"
@@ -150,9 +149,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_gwa_compute(self, mock_ipfs_cache,
-                         mock_redis, mock_path_exist, mock_json,
-                         mock_hash, mock_queue_cmd):
+    def test_gwa_compute(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/gwa-compute/<k-inputfile>/<token>"""
         mock_ipfs_cache.return_value = ("/tmp/cache/"
                                         "QmQPeNsJPyVWPFDVHb"
@@ -201,9 +200,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_gwa_compute_with_covars(self, mock_ipfs_cache,
-                                     mock_redis, mock_path_exist,
-                                     mock_json, mock_hash, mock_queue_cmd):
+    def test_gwa_compute_with_covars(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/gwa-compute/covars/<k-inputfile>/<token>"""
         mock_ipfs_cache.return_value = ("/tmp/cache/"
                                         "QmQPeNsJPyVWPFDVHb"
@@ -255,9 +254,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_gwa_compute_with_loco_only(self, mock_ipfs_cache,
-                                        mock_redis, mock_path_exist,
-                                        mock_json, mock_hash, mock_queue_cmd):
+    def test_gwa_compute_with_loco_only(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/gwa-compute/<k-inputfile>/loco/maf/<maf>/<token>
 
         """
@@ -308,10 +307,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_gwa_compute_with_loco_covars(self, mock_ipfs_cache,
-                                          mock_redis, mock_path_exist,
-                                          mock_json, mock_hash,
-                                          mock_queue_cmd):
+    def test_gwa_compute_with_loco_covars(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/gwa-compute/<k-inputfile>/loco/covars/maf/<maf>/<token>
 
         """
@@ -363,10 +361,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_k_gwa_compute_without_loco_covars(self, mock_ipfs_cache,
-                                               mock_redis,
-                                               mock_path_exist, mock_json,
-                                               mock_hash, mock_queue_cmd):
+    def test_k_gwa_compute_without_loco_covars(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/k-gwa-compute/<token>
 
         """
@@ -419,10 +416,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_k_gwa_compute_with_covars_only(self, mock_ipfs_cache,
-                                            mock_redis, mock_path_exist,
-                                            mock_json, mock_hash,
-                                            mock_queue_cmd):
+    def test_k_gwa_compute_with_covars_only(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/k-gwa-compute/covars/<token>
 
         """
@@ -484,10 +480,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_k_gwa_compute_with_loco_only(self, mock_ipfs_cache,
-                                          mock_redis, mock_path_exist,
-                                          mock_json, mock_hash,
-                                          mock_queue_cmd):
+    def test_k_gwa_compute_with_loco_only(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /gemma/k-gwa-compute/loco/<chromosomes>/maf/<maf>/<token>
 
         """
@@ -550,10 +545,9 @@ class GemmaAPITest(unittest.TestCase):
     @mock.patch("gn3.api.gemma.assert_paths_exist")
     @mock.patch("gn3.api.gemma.redis.Redis")
     @mock.patch("gn3.api.gemma.cache_ipfs_file")
-    def test_k_gwa_compute_with_loco_and_covar(self, mock_ipfs_cache,
-                                               mock_redis,
-                                               mock_path_exist, mock_json,
-                                               mock_hash, mock_queue_cmd):
+    def test_k_gwa_compute_with_loco_and_covar(# pylint: disable=[too-many-positional-arguments]
+            self, mock_ipfs_cache, mock_redis, mock_path_exist, mock_json,
+            mock_hash, mock_queue_cmd):
         """Test /k-gwa-compute/covars/loco/<chromosomes>/maf/<maf>/<token>
 
         """
diff --git a/tests/integration/test_lmdb_sample_data.py b/tests/integration/test_lmdb_sample_data.py
new file mode 100644
index 0000000..30a23f4
--- /dev/null
+++ b/tests/integration/test_lmdb_sample_data.py
@@ -0,0 +1,31 @@
+"""Tests for the LMDB sample data API endpoint"""
+import pytest
+
+
+@pytest.mark.unit_test
+def test_nonexistent_data(client):
+    """Test endpoint returns 404 when data doesn't exist"""
+    response = client.get("/api/lmdb/sample-data/nonexistent/123")
+    assert response.status_code == 404
+    assert response.json["error"] == "No data found for given dataset and trait"
+
+
+@pytest.mark.unit_test
+def test_successful_retrieval(client):
+    """Test successful data retrieval using test LMDB data"""
+    # Use known test data hash: 7308efbd84b33ad3d69d14b5b1f19ccc
+    response = client.get("/api/lmdb/sample-data/BXDPublish/10007")
+    assert response.status_code == 200
+
+    data = response.json
+    assert len(data) == 31
+    # Verify some known values from the test database
+    assert data["BXD1"] == 18.700001
+    assert data["BXD11"] == 18.9
+
+
+@pytest.mark.unit_test
+def test_invalid_trait_id(client):
+    """Test endpoint handles invalid trait IDs appropriately"""
+    response = client.get("/api/lmdb/sample-data/BXDPublish/999999")
+    assert response.status_code == 404
diff --git a/tests/integration/test_partial_correlations.py b/tests/integration/test_partial_correlations.py
index fc9f64f..56af260 100644
--- a/tests/integration/test_partial_correlations.py
+++ b/tests/integration/test_partial_correlations.py
@@ -221,4 +221,4 @@ def test_part_corr_api_with_mix_of_existing_and_non_existing_control_traits(
     criteria = 10
     with pytest.warns(UserWarning):
         partial_correlations_with_target_db(
-            db_conn, primary, controls, method, criteria, target)
+            db_conn, primary, controls, method, criteria, target, "/tmp")