diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-03 14:49:11 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-03 14:49:11 +0000 |
| commit | 5ecc6b70e8a6ce2ba91f7808295a7d7672481d58 (patch) | |
| tree | 2e7a704d7692098588fbf5fde5b9aa4fc018e8e0 /test/python | |
| parent | 9e5655e21a3ec486b1d52d342156de0edc06df76 (diff) | |
| download | genenetwork4-5ecc6b70e8a6ce2ba91f7808295a7d7672481d58.tar.gz | |
Add GET /groups/{group}/strains, mirroring gn-guile's strain-id-names.
* src/db.rs (Strain): New struct.
(get_group_strains): New function. Joins Strain and StrainXRef by
group Id, optionally filtered to strains used for mapping, matching
gn-guile's gn.data.strains:strain-id-names (same InbredSetId and
used-for-mapping? arguments), returning strain names as well as ids.
* src/lib.rs (GroupStrainsParams): New struct, the used_for_mapping
query parameter.
(group_strains): New handler for GET /groups/{group}/strains. Looks
the group up the same way group_by_name does, for the same 404 shape
on an unknown group.
(app): Register it.
* tests/group_strains.rs, test/python/test_group_strains.py: New
files.
* tests/openapi.rs, test/python/test_openapi.py: Check the new path
is in the generated spec.
* README.md (GET /groups/{group}/strains): Document it, including the
used_for_mapping filter excluding BXD's parent strains.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
Diffstat (limited to 'test/python')
| -rw-r--r-- | test/python/test_group_strains.py | 81 | ||||
| -rw-r--r-- | test/python/test_openapi.py | 1 |
2 files changed, 82 insertions, 0 deletions
diff --git a/test/python/test_group_strains.py b/test/python/test_group_strains.py new file mode 100644 index 0000000..12b4aa4 --- /dev/null +++ b/test/python/test_group_strains.py @@ -0,0 +1,81 @@ +"""Mirrors tests/group_strains.rs. Needs a live MariaDB (SQL_URI); skips +with a message rather than failing when none is reachable, same as +test_group_by_name.py. +""" + +import http.client +import json +import socket +import unittest + +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 GroupStrainsTest(ServerTestCase): + def test_group_strains_bxd_returns_strains(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/strains") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + strains = json.loads(body) + self.assertTrue(strains) + bxd1 = next(s for s in strains if s["name"] == "BXD1") + self.assertTrue(bxd1["used_for_mapping"]) + + def test_group_strains_used_for_mapping_filters_out_parents(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/strains?used_for_mapping=true") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + strains = json.loads(body) + self.assertTrue(strains) + self.assertTrue(all(s["used_for_mapping"] for s in strains)) + names = {s["name"] for s in strains} + self.assertNotIn("B6D2F1", names) + + def test_group_strains_unknown_group_returns_404(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/not-a-real-group/strains") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + 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_strains") + self.assertEqual(error["next"], "/groups") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_openapi.py b/test/python/test_openapi.py index f4813c3..3b43f18 100644 --- a/test/python/test_openapi.py +++ b/test/python/test_openapi.py @@ -27,6 +27,7 @@ class OpenApiTest(ServerTestCase): "/species/{species}", "/groups", "/groups/{group}", + "/groups/{group}/strains", ): self.assertIn(path, doc["paths"]) |
