about summary refs log tree commit diff
path: root/test/python/test_search.py
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-08 10:45:58 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-08 10:45:58 +0300
commita0c2c7d4bd9d7524103377afe2b18d38c9b8041d (patch)
tree26463c170562ffe4b7f026d3edb0e66fe548b11e /test/python/test_search.py
parent7a61c8d956cf4ef6ee69a5e0a06c74451079cc28 (diff)
parent54f138802bed2040531b3da3df0b30895d881bc8 (diff)
downloadgenenetwork4-a0c2c7d4bd9d7524103377afe2b18d38c9b8041d.tar.gz
Merge origin/main (54f1388): page, publish annotations, publications route.
Composes the new main above the search engine seam:

* src/routes/search.rs (page): parsed and threaded through the seam;
  the gn3 forwarder passes page to gn3 unsorted (sorted fetches the
  wide first page), the native engine takes the mset window. Ranked
  pages slice the sorted list, as before.
* src/routes/search.rs (add_publish_annotations): enrichment now
  fills locus and abbreviation in one PublishXRef/Phenotype lookup.
* src/search/mod.rs (Engine::search): page parameter; SearchHit
  gains abbreviation and pubmed_id (gn3's future fields flow via
  extra, as before).
* src/db.rs (LRS_PER_LOD): 4.604 — lod shifts accordingly everywhere.

All 34 test binaries green; parity replay and shape gates pass
against the dev index with the new lod constant (grading compares
identifier sets, not lod); page disjointness, abbreviation and locus
verified live (native engine, dev index, SQL_URI set).
Diffstat (limited to 'test/python/test_search.py')
-rw-r--r--test/python/test_search.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/test/python/test_search.py b/test/python/test_search.py
index bfd1d38..aea1e20 100644
--- a/test/python/test_search.py
+++ b/test/python/test_search.py
@@ -49,6 +49,10 @@ class Gn3StubHandler(http.server.BaseHTTPRequestHandler):
                 with open(SEROTONIN_FIXTURE, "rb") as fixture:
                     body = fixture.read()
                 self.send_response(http.client.OK)
+        elif "alcohol" in query.get("query", [""])[0] and query.get("page") == ["2"]:
+            # Past the end: an unsorted /search forwards `page` to gn3.
+            body = b"[]"
+            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)
@@ -176,7 +180,7 @@ class SearchTest(ServerTestCase):
         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)
+            self.assertAlmostEqual(hit["lod"], hit["lrs"] / 4.604)
 
         male_midbrain = [
             hit
@@ -189,7 +193,7 @@ class SearchTest(ServerTestCase):
             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["lod"], 2.6063, places=4)
         self.assertAlmostEqual(serotonin["additive"], -1.3041, places=4)
         self.assertEqual(serotonin["geno_chr"], "16")
 
@@ -197,14 +201,16 @@ class SearchTest(ServerTestCase):
         # 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["lod"], 3.5819, places=4)
         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.
+        self.assertEqual(serotonin["pubmed_id"], 24102824)
         if database_reachable():
             self.assertEqual(serotonin["locus"], "rsm10000012461")
             self.assertEqual(top["locus"], "rsm10000013922")
+            self.assertEqual(serotonin["abbreviation"], "5HT_MB_M")
 
     def test_search_orders_ascending(self):
         self.require_auth()
@@ -218,6 +224,32 @@ class SearchTest(ServerTestCase):
         self.assertEqual(lrs[0], min_lrs)
         self.assertEqual(lrs, sorted(lrs))
 
+    def test_search_pages(self):
+        # Unsorted, `page` is forwarded to gn3 (the stub's page 2 is
+        # empty); sorted, pages come from the ranked list (the recorded
+        # 119 serotonin hits: 100, then 19, then none).
+        self.require_auth()
+
+        status, body = self.get("/search?q=alcohol&page=2")
+        self.assertEqual(status, http.client.OK)
+        self.assertEqual(body["data"], [])
+
+        sorted_uri = (
+            "/search?q=serotonin%20AND%20midbrain%20AND%20group:BXD"
+            "&sort=lod&limit=100"
+        )
+        _, page1 = self.get(sorted_uri)
+        _, page2 = self.get(sorted_uri + "&page=2")
+        _, page3 = self.get(sorted_uri + "&page=3")
+        self.assertEqual(len(page1["data"]), 100)
+        self.assertEqual(len(page2["data"]), 19)
+        self.assertEqual(page3["data"], [])
+        self.assertGreaterEqual(page1["data"][-1]["lod"], page2["data"][0]["lod"])
+
+        status, body = self.get("/search?q=alcohol&page=0")
+        self.assertEqual(status, http.client.BAD_REQUEST)
+        self.assertIn("page", body["detail"])
+
     def test_search_forwards_gn3_parse_errors(self):
         self.require_auth()