about summary refs log tree commit diff
path: root/test/python
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-08 13:37:57 +0000
committerPjotr <wrk@bosa.lan>2026-10-08 13:37:57 +0000
commit2edc685bb7c56d5f9f28da09378f300bfe81021d (patch)
tree1120d7589a1143ef29a4f5d2e2a47437e8699552 /test/python
parent208eeac395079f46fcbe07b4185524e017c554ef (diff)
downloadgenenetwork4-2edc685bb7c56d5f9f28da09378f300bfe81021d.tar.gz
* src/db.rs, src/routes: add mapping_method, tissue, /mapping-methods, /accessions.
Answers four more questions of aisearch's full_benchmark.csv from
tables the API did not expose.

* src/db.rs (Group, GroupDetail), src/routes/groups.rs: groups gain
`mapping_method`, the name of the MappingMethod row their
mapping_method_id points to (qtlreaper, Rqtl, ...), or null.
* src/db.rs (Dataset): datasets gain `tissue`, the Tissue their
ProbeFreeze points to (e.g. "Brain mRNA").
* src/routes/mapping_methods.rs: GET /mapping-methods lists the
MappingMethod table, including tools no group uses (PLINK, FastMap).
* src/routes/accessions.rs: GET /accessions/{accession} resolves a
GeneNetwork accession number (GN602, gn602 or 602) via InfoFiles to the
dataset's name, title, category (publish/probeset) and group.
* docs/genenetwork_datatypes.md: MappingMethodId is a key into the
MappingMethod table (the authoritative reading); GN2's code-based reading
is noted as superseded.

* tests/benchmark.rs, test/data/benchmark_search.json: add the 60 new
full-benchmark rows that pass (full rows 0..114; search rows run against
recorded production gn3, the rest need the database), and full rows 33
(mapping tools), 34 (Rqtl for outbred sets), 35 (GN602) and 44 (only
GTEx v8 has TPM datasets). The untested rows are listed in the file's
header comment with the reason for each.
* tests, test/python: tests for the new fields and endpoints; both
endpoints added to the OpenAPI and next-link crawl tests.
* README.md, RELEASE_NOTES.md: document the new fields and endpoints.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test/python')
-rw-r--r--test/python/test_accessions.py68
-rw-r--r--test/python/test_dataset_by_name.py13
-rw-r--r--test/python/test_envelope.py3
-rw-r--r--test/python/test_group_by_name.py10
-rw-r--r--test/python/test_groups.py22
-rw-r--r--test/python/test_mapping_methods.py46
6 files changed, 162 insertions, 0 deletions
diff --git a/test/python/test_accessions.py b/test/python/test_accessions.py
new file mode 100644
index 0000000..5877dcb
--- /dev/null
+++ b/test/python/test_accessions.py
@@ -0,0 +1,68 @@
+"""Mirrors tests/accessions.rs. Needs a live MariaDB (SQL_URI) and a
+valid token (every endpoint needs one now -- see docs/gn-auth.md);
+skips with a message rather than failing when either is missing, same
+as test_groups.py. GN602 is the BXD published phenotypes dataset; GN1 is
+Br_U_0803_M.
+"""
+
+import http.client
+import json
+import unittest
+
+from auth_helpers import TOKEN_ENV, auth_token
+from server_test_case import HOST, PORT, ServerTestCase, database_reachable, envelope_data
+
+
+class AccessionsTest(ServerTestCase):
+    EXTRA_ENV = TOKEN_ENV
+
+    def get(self, path):
+        token = auth_token()
+        if not token:
+            self.skipTest("no token (see docs/gn-auth.md)")
+        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=30)
+        try:
+            conn.request("GET", path, headers={"Authorization": f"Bearer {token}"})
+            response = conn.getresponse()
+            return response, response.read()
+        finally:
+            conn.close()
+
+    def test_accession_resolves_to_its_dataset(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        for path in ("/accessions/GN602", "/accessions/gn602", "/accessions/602"):
+            response, body = self.get(path)
+            self.assertEqual(response.status, 200, path)
+            found = envelope_data(body)
+            self.assertEqual(found["accession"], 602, path)
+            self.assertEqual(found["name"], "BXDPublish")
+            self.assertEqual(found["title"], "BXD Published Phenotypes")
+            self.assertEqual(found["category"], "publish")
+            self.assertEqual(found["group"], "BXD")
+
+        response, body = self.get("/accessions/GN1")
+        self.assertEqual(response.status, 200)
+        found = envelope_data(body)
+        self.assertEqual(found["name"], "Br_U_0803_M")
+        self.assertEqual(found["category"], "probeset")
+        self.assertEqual(found["group"], "BXD")
+
+    def test_accession_rejects_text_and_unknown_numbers(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/accessions/BXDPublish")
+        self.assertEqual(response.status, 400)
+        error = json.loads(body)
+        self.assertEqual(error["code"], "invalid_parameter")
+        self.assertEqual(error["operation_id"], "accession")
+
+        response, body = self.get("/accessions/GN99999999")
+        self.assertEqual(response.status, 404)
+        self.assertEqual(json.loads(body)["code"], "accession_not_found")
+
+
+if __name__ == "__main__":
+    unittest.main()
diff --git a/test/python/test_dataset_by_name.py b/test/python/test_dataset_by_name.py
index 58414a8..88aae8e 100644
--- a/test/python/test_dataset_by_name.py
+++ b/test/python/test_dataset_by_name.py
@@ -60,6 +60,19 @@ class DatasetByNameTest(ServerTestCase):
         self.assertEqual(error["code"], "dataset_not_found")
         self.assertEqual(error["operation_id"], "dataset_by_name")
 
+    def test_datasets_report_their_tissue(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/datasets/Br_U_0803_M")
+        self.assertEqual(response.status, 200)
+        self.assertEqual(envelope_data(body)["tissue"], "Brain mRNA")
+
+        response, body = self.get("/groups/BXD/datasets")
+        self.assertEqual(response.status, 200)
+        gut = next(d for d in envelope_data(body) if d["name"] == "UTHSC_GutGL_0414")
+        self.assertEqual(gut["tissue"], "Gastrointestinal mRNA")
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/test/python/test_envelope.py b/test/python/test_envelope.py
index 160a50c..aa9ced3 100644
--- a/test/python/test_envelope.py
+++ b/test/python/test_envelope.py
@@ -26,6 +26,9 @@ SEEDS = [
     "/groups/BXD/strains",
     "/groups/BXD/case-attributes",
     "/groups/BXD/datasets",
+    "/mapping-methods",
+    "/accessions/GN602",
+    "/accessions/GN1",
     "/groups/BXD/traits?abbreviation=5HT_MB_M",
     "/groups/BXD/traits/17985",
     "/groups/BXD/traits/17985/values",
diff --git a/test/python/test_group_by_name.py b/test/python/test_group_by_name.py
index f562cbe..6256a1f 100644
--- a/test/python/test_group_by_name.py
+++ b/test/python/test_group_by_name.py
@@ -70,6 +70,16 @@ class GroupByNameTest(ServerTestCase):
         self.assertEqual(error["next"], "/groups")
         self.assertEqual(error["request_id"], request_id)
 
+    def test_group_by_name_names_the_mapping_tool(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/groups/HSNIH-Palmer")
+        self.assertEqual(response.status, 200)
+        group = envelope_data(body)
+        self.assertEqual(group["mapping_method_id"], "2")
+        self.assertEqual(group["mapping_method"], "Rqtl")
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/test/python/test_groups.py b/test/python/test_groups.py
index a3dcb55..2cd09de 100644
--- a/test/python/test_groups.py
+++ b/test/python/test_groups.py
@@ -76,6 +76,28 @@ class GroupsTest(ServerTestCase):
         self.assertIn("HXBBXH", rat_reference)
         self.assertNotIn("BXD", rat_reference)
 
+    def test_groups_report_the_mapping_tool_offered_for_them(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+        token = auth_token()
+        if not token:
+            self.skipTest("no token (see docs/gn-auth.md)")
+
+        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10)
+        try:
+            conn.request("GET", "/groups", headers={"Authorization": f"Bearer {token}"})
+            response = conn.getresponse()
+            body = response.read()
+        finally:
+            conn.close()
+        self.assertEqual(response.status, 200)
+        tool = {g["name"]: g["mapping_method"] for g in envelope_data(body)}
+
+        self.assertEqual(tool["BXD"], "qtlreaper")
+        self.assertEqual(tool["HSNIH-Palmer"], "Rqtl")
+        self.assertEqual(tool["HSNIH-RGSMC"], "qtlreaper")  # not every outbred set uses Rqtl
+        self.assertIsNone(tool["Oregon-R_x_2b3"])
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/test/python/test_mapping_methods.py b/test/python/test_mapping_methods.py
new file mode 100644
index 0000000..b5f7cdb
--- /dev/null
+++ b/test/python/test_mapping_methods.py
@@ -0,0 +1,46 @@
+"""Mirrors tests/mapping_methods.rs. Needs a live MariaDB (SQL_URI) and a
+valid token (every endpoint needs one now -- see docs/gn-auth.md);
+skips with a message rather than failing when either is missing, same
+as test_groups.py.
+"""
+
+import http.client
+import json
+import unittest
+
+from auth_helpers import TOKEN_ENV, auth_token
+from server_test_case import HOST, PORT, ServerTestCase, database_reachable, envelope_data
+
+
+class MappingMethodsTest(ServerTestCase):
+    EXTRA_ENV = TOKEN_ENV
+
+    def get(self, path):
+        token = auth_token()
+        if not token:
+            self.skipTest("no token (see docs/gn-auth.md)")
+        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=30)
+        try:
+            conn.request("GET", path, headers={"Authorization": f"Bearer {token}"})
+            response = conn.getresponse()
+            return response, response.read()
+        finally:
+            conn.close()
+
+    def test_mapping_methods_lists_the_tools(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/mapping-methods")
+        self.assertEqual(response.status, 200)
+        methods = envelope_data(body)
+        # The MappingMethod table lists tools no group uses (PLINK, FastMap).
+        self.assertEqual(
+            [m["name"] for m in methods],
+            ["qtlreaper", "Rqtl", "HappyR", "PLINK", "FastMap"],
+        )
+        self.assertEqual(methods[0]["id"], 1)
+
+
+if __name__ == "__main__":
+    unittest.main()