about summary refs log tree commit diff
path: root/test/python/test_group_case_attributes.py
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-07 21:01:40 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-07 21:01:40 +0300
commit85b63abcfdbae235d292a6de4bd47ffe6ba6dafd (patch)
tree8b39f26fad90eaa27751fd061ab1cbc91ae95b08 /test/python/test_group_case_attributes.py
parentb68531c40d91cadfd868e4b65ff92989ffd4fb27 (diff)
parente912c87deaf220fd5fce1299d669e8fa992b5338 (diff)
downloadgenenetwork4-85b63abcfdbae235d292a6de4bd47ffe6ba6dafd.tar.gz
Merge origin/main (e912c87: /search gains lod, locus, sort/order) into
native-search-engine.

Resolution: his route-level additions compose above the engine seam —
the handler now validates sort/order, asks the engine for
SORT_FETCH_LIMIT (1000) when ranking, maps SearchError via the seam's
engine_error, then computes lod, sorts, truncates to limit and fills
loci; lod/locus join SearchHit in src/search/mod.rs. His tests pass
through the seam.

KNOWN at this commit: the parity floor is BLOCKED (36 shapes) — the
route's new truncate(limit) exposes that route-level full-set grading
was a calibration-stub artifact (real gn3 caps at per_page; the stub
ignored it). Harness fix queued: set-equality moves to engine level,
status + top-10 stay route level. Landed together with that fix.
Diffstat (limited to 'test/python/test_group_case_attributes.py')
-rw-r--r--test/python/test_group_case_attributes.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/test/python/test_group_case_attributes.py b/test/python/test_group_case_attributes.py
new file mode 100644
index 0000000..71c933f
--- /dev/null
+++ b/test/python/test_group_case_attributes.py
@@ -0,0 +1,105 @@
+"""Mirrors tests/group_case_attributes.rs. Needs a live MariaDB
+(SQL_URI, see src/db.rs) and a valid token (every endpoint needs one
+now -- see docs/gn-auth.md); skips rather than fails when either is
+missing, same as test_group_by_name.py.
+"""
+
+import http.client
+import json
+import socket
+import unittest
+
+from auth_helpers import TOKEN_ENV, auth_token
+from server_test_case import HOST, PORT, ServerTestCase
+
+
+def database_reachable():
+    try:
+        with socket.create_connection(("127.0.0.1", 3306), timeout=0.5):
+            return True
+    except OSError:
+        return False
+
+
+class GroupCaseAttributesTest(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=10)
+        try:
+            conn.request("GET", path, headers={"Authorization": f"Bearer {token}"})
+            response = conn.getresponse()
+            return response, response.read()
+        finally:
+            conn.close()
+
+    def test_group_case_attributes_bxd_returns_names_and_values(self):
+        """BXD (InbredSetId 1) has exactly 4 case attributes -- Epoch,
+        RRID, SeqCvge, Status -- each strain in the response should have
+        exactly those 4 keys, not more (CaseAttributeId isn't unique
+        across groups -- see the comment in src/db.rs -- so getting the
+        join wrong would pull in unrelated groups' attributes too).
+        """
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/groups/BXD/case-attributes")
+        self.assertEqual(response.status, 200)
+
+        case_attributes = json.loads(body)
+        self.assertEqual(
+            case_attributes["names"], ["Epoch", "RRID", "SeqCvge", "Status"]
+        )
+
+        values = case_attributes["values"]
+        self.assertTrue(values)
+        bxd1 = next(v for v in values if v["strain"] == "BXD1")
+        self.assertEqual(
+            set(bxd1["case_attributes"].keys()), set(case_attributes["names"])
+        )
+
+    def test_group_case_attributes_group_with_none_returns_empty(self):
+        """LXS (InbredSetId 9) is a real group with no case attributes
+        defined at all -- an empty result, not a 404 (the group itself
+        exists)."""
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/groups/LXS/case-attributes")
+        self.assertEqual(response.status, 200)
+
+        case_attributes = json.loads(body)
+        self.assertEqual(case_attributes["names"], [])
+        self.assertEqual(case_attributes["values"], [])
+
+    def test_group_case_attributes_without_a_token_returns_401(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10)
+        try:
+            conn.request("GET", "/groups/BXD/case-attributes")
+            response = conn.getresponse()
+        finally:
+            conn.close()
+        self.assertEqual(response.status, 401)
+
+    def test_group_case_attributes_unknown_group_returns_404(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/groups/not-a-real-group/case-attributes")
+        self.assertEqual(response.status, 404)
+
+        error = json.loads(body)
+        self.assertEqual(error["status"], 404)
+        self.assertEqual(error["code"], "group_not_found")
+        self.assertEqual(error["operation_id"], "group_case_attributes")
+        self.assertEqual(error["next"], "/groups")
+
+
+if __name__ == "__main__":
+    unittest.main()