about summary refs log tree commit diff
path: root/test/python
diff options
context:
space:
mode:
Diffstat (limited to 'test/python')
-rw-r--r--test/python/test_dataset_probeset_info.py1
-rw-r--r--test/python/test_group_trait_info.py15
-rw-r--r--test/python/test_search.py93
3 files changed, 107 insertions, 2 deletions
diff --git a/test/python/test_dataset_probeset_info.py b/test/python/test_dataset_probeset_info.py
index c073f3a..04241ba 100644
--- a/test/python/test_dataset_probeset_info.py
+++ b/test/python/test_dataset_probeset_info.py
@@ -56,6 +56,7 @@ class DatasetProbesetInfoTest(ServerTestCase):
         self.assertEqual(info["name"], "100001_at")
         self.assertEqual(info["symbol"], "Cd3g")
         self.assertIsInstance(info["mean"], float)
+        self.assertAlmostEqual(info["lod"], info["lrs"] / 4.61)
 
     def test_dataset_probeset_info_without_a_token_returns_401(self):
         if not database_reachable():
diff --git a/test/python/test_group_trait_info.py b/test/python/test_group_trait_info.py
index d5a0761..1e4fab8 100644
--- a/test/python/test_group_trait_info.py
+++ b/test/python/test_group_trait_info.py
@@ -36,6 +36,21 @@ class GroupTraitInfoTest(ServerTestCase):
         finally:
             conn.close()
 
+    def test_group_trait_info_reports_lod_and_locus(self):
+        # The "highest LOD ... serotonin in BXD male midbrain" trait: see
+        # test_search.py. `lod` is `lrs` / 4.61.
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/groups/BXD/traits/17985")
+        self.assertEqual(response.status, 200)
+
+        info = json.loads(body)
+        self.assertEqual(info["locus"], "rsm10000012461")
+        self.assertAlmostEqual(info["lod"], info["lrs"] / 4.61)
+        self.assertAlmostEqual(info["lod"], 2.603, places=3)
+        self.assertAlmostEqual(info["additive"], -1.3041, places=4)
+
     def test_group_trait_info_bxd_returns_phenotype_and_publication(self):
         if not database_reachable():
             self.skipTest("no database on 127.0.0.1:3306")
diff --git a/test/python/test_search.py b/test/python/test_search.py
index 18cc54c..bfd1d38 100644
--- a/test/python/test_search.py
+++ b/test/python/test_search.py
@@ -18,11 +18,20 @@ import unittest
 import urllib.parse
 
 from auth_helpers import TOKEN_ENV, auth_server_reachable, auth_token
-from server_test_case import HOST, PORT, ServerTestCase, wait_for_port
+from server_test_case import (
+    HOST,
+    PORT,
+    ServerTestCase,
+    database_reachable,
+    wait_for_port,
+)
 
 FIXTURE = os.path.join(
     os.path.dirname(__file__), "..", "data", "search_alcohol_phenotype.json"
 )
+SEROTONIN_FIXTURE = os.path.join(
+    os.path.dirname(__file__), "..", "data", "search_serotonin_midbrain_bxd.json"
+)
 
 
 class Gn3StubHandler(http.server.BaseHTTPRequestHandler):
@@ -30,7 +39,17 @@ class Gn3StubHandler(http.server.BaseHTTPRequestHandler):
 
     def do_GET(self):
         query = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query)
-        if "boom" in query.get("query", [""])[0]:
+        if "serotonin" in query.get("query", [""])[0]:
+            # gn3 has no sort of its own: a sorted /search must ask for a
+            # wide page (1000), not just `limit`, to rank across it.
+            if query.get("per_page") != ["1000"]:
+                body = b"per_page must be 1000"
+                self.send_response(http.client.INTERNAL_SERVER_ERROR)
+            else:
+                with open(SEROTONIN_FIXTURE, "rb") as fixture:
+                    body = fixture.read()
+                self.send_response(http.client.OK)
+        elif "boom" in query.get("query", [""])[0]:
             body = b'{"error": "gn3 exploded"}'
             self.send_response(http.client.INTERNAL_SERVER_ERROR)
         elif "&&" in query.get("query", [""])[0]:
@@ -129,6 +148,76 @@ class SearchTest(ServerTestCase):
         self.assertEqual(status, http.client.BAD_REQUEST)
         self.assertIn("phenotype", body["detail"])
 
+    def test_search_validates_sort_and_order(self):
+        self.require_auth()
+
+        status, body = self.get("/search?q=alcohol&sort=mean")
+        self.assertEqual(status, http.client.BAD_REQUEST)
+        self.assertIn("lrs", body["detail"])
+
+        status, body = self.get("/search?q=alcohol&sort=lod&order=sideways")
+        self.assertEqual(status, http.client.BAD_REQUEST)
+        self.assertIn("asc", body["detail"])
+
+    def test_highest_lod_for_serotonin_in_bxd_male_midbrain(self):
+        # "What is the highest LOD score, locus marker, and additive
+        # effect for serotonin in BXD male midbrain?" -- mirrors scenario 7
+        # of tests/search.rs. Males only: " males [" matches "adult males ["
+        # but not "adult females [" or "adult males and females [".
+        self.require_auth()
+
+        status, body = self.get(
+            "/search?q=serotonin%20AND%20midbrain%20AND%20group:BXD"
+            "&sort=lod&limit=100"
+        )
+        self.assertEqual(status, http.client.OK)
+        hits = body["data"]
+        self.assertEqual(len(hits), 100)
+        lods = [hit["lod"] for hit in hits]
+        self.assertEqual(lods, sorted(lods, reverse=True))
+        for hit in hits:
+            self.assertAlmostEqual(hit["lod"], hit["lrs"] / 4.61)
+
+        male_midbrain = [
+            hit
+            for hit in hits
+            if "Midbrain" in hit["description"] and " males [" in hit["description"]
+        ]
+        serotonin = next(
+            hit
+            for hit in male_midbrain
+            if "5-hydroxytryptamine (5-HT, serotonin) level" in hit["description"]
+        )
+        self.assertEqual(serotonin["name"], "17985")
+        self.assertAlmostEqual(serotonin["lod"], 2.603, places=3)
+        self.assertAlmostEqual(serotonin["additive"], -1.3041, places=4)
+        self.assertEqual(serotonin["geno_chr"], "16")
+
+        # The serotonin transporter (SERT) in the same tissue and sex
+        # has the higher LOD: "serotonin" is ambiguous between the two.
+        top = male_midbrain[0]
+        self.assertEqual(top["name"], "17994")
+        self.assertAlmostEqual(top["lod"], 3.577, places=3)
+        self.assertAlmostEqual(top["additive"], 233.99, places=2)
+
+        # The peak marker's name comes from PublishXRef (needs a live
+        # MariaDB); without one `locus` is null and the above still holds.
+        if database_reachable():
+            self.assertEqual(serotonin["locus"], "rsm10000012461")
+            self.assertEqual(top["locus"], "rsm10000013922")
+
+    def test_search_orders_ascending(self):
+        self.require_auth()
+
+        with open(SEROTONIN_FIXTURE) as fixture:
+            min_lrs = min(hit["lrs"] for hit in json.load(fixture))
+        status, body = self.get("/search?q=serotonin&sort=lrs&order=asc&limit=3")
+        self.assertEqual(status, http.client.OK)
+        lrs = [hit["lrs"] for hit in body["data"]]
+        self.assertEqual(len(lrs), 3)
+        self.assertEqual(lrs[0], min_lrs)
+        self.assertEqual(lrs, sorted(lrs))
+
     def test_search_forwards_gn3_parse_errors(self):
         self.require_auth()