diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-03 13:49:36 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-03 13:49:36 +0000 |
| commit | 7c1bdb98a569d8b6389b222af746155c53aa3761 (patch) | |
| tree | dae203b9214ab0c8d9e1e7a061387d7ddef79e82 /test/python | |
| parent | 50385262fa8c26a1c7f5b170b0ccb1196ba2f676 (diff) | |
| download | genenetwork4-7c1bdb98a569d8b6389b222af746155c53aa3761.tar.gz | |
Add /groups and /groups/{group} endpoints.
* src/db.rs (Group): New struct. Summary of one InbredSet row,
matching the shape of GeneNetwork2's GET /api/v_pre1/groups response.
(get_all_groups): New function. Mirrors GeneNetwork2's
wqflask.api.router.get_groups_list (no species filter yet).
(GroupDetail): New struct, deriving FromRow instead of being built
from a tuple like SpeciesDetail, since InbredSet has 14 columns, more
than mysql_common's FromRow is implemented for tuples (up to 12).
FromRow matches by column name (PascalCase of the field name via
#[mysql(rename_all = "PascalCase")]), except public, which is
lowercase in the schema and needs its own #[mysql(rename = "public")].
(get_group_by_name): New function. Mirrors GeneNetwork2's
wqflask.api.router.get_group_info, but returns every column instead of
a fixed subset.
* src/lib.rs (app): Add /groups and /groups/{group} routes.
(groups, group_by_name): New handlers, following the same
ApiError/request-id/spawn_blocking pattern as species/species_by_name.
(group_by_name): On no match, set ApiError's next to /groups.
* tests/groups.rs: New file. Checks BXD is present (used throughout
the GeneNetwork2 and GeneNetwork3 test suites as a fixture group,
always present in the database); skips rather than fails when no
database is reachable, same as species.rs.
* test/python/test_groups.py: New file. Likewise.
* tests/group_by_name.rs: New file. Checks BXD's full row and an
unknown-group 404 case, same pattern as species_by_name.rs.
* test/python/test_group_by_name.py: New file. Likewise.
* tests/openapi.rs (openapi_json_describes_all_endpoints): Check for
/groups and /groups/{group} among the documented paths.
* test/python/test_openapi.py
(test_openapi_json_describes_all_endpoints): Likewise.
* README.md: Document /groups and /groups/{group}.
Diffstat (limited to 'test/python')
| -rw-r--r-- | test/python/test_group_by_name.py | 65 | ||||
| -rw-r--r-- | test/python/test_groups.py | 42 | ||||
| -rw-r--r-- | test/python/test_openapi.py | 9 |
3 files changed, 115 insertions, 1 deletions
diff --git a/test/python/test_group_by_name.py b/test/python/test_group_by_name.py new file mode 100644 index 0000000..440ee8b --- /dev/null +++ b/test/python/test_group_by_name.py @@ -0,0 +1,65 @@ +"""Mirrors tests/group_by_name.rs. Needs a live MariaDB (SQL_URI); skips +with a message rather than failing when none is reachable, same as +test_species_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 GroupByNameTest(ServerTestCase): + def test_group_by_name_bxd_returns_group_row(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") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + group = json.loads(body) + self.assertEqual(group["name"], "BXD") + self.assertEqual(group["inbred_set_name"], "BXD") + self.assertEqual(group["genetic_type"], "riset") + + def test_group_by_name_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") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + request_id = response.getheader("x-request-id") + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "group_not_found") + self.assertEqual(error["operation_id"], "group_by_name") + self.assertEqual(error["spec_url"], "/openapi.json") + self.assertEqual(error["next"], "/groups") + self.assertEqual(error["request_id"], request_id) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_groups.py b/test/python/test_groups.py new file mode 100644 index 0000000..da7b5fa --- /dev/null +++ b/test/python/test_groups.py @@ -0,0 +1,42 @@ +"""Mirrors tests/groups.rs. Needs a live MariaDB (SQL_URI); skips with a +message rather than failing when none is reachable, same as test_species.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 GroupsTest(ServerTestCase): + def test_groups_returns_ok_with_bxd(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") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + groups = json.loads(body) + self.assertTrue(groups) + names = {record["name"] for record in groups} + self.assertIn("BXD", names) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_openapi.py b/test/python/test_openapi.py index 0815d34..f4813c3 100644 --- a/test/python/test_openapi.py +++ b/test/python/test_openapi.py @@ -20,7 +20,14 @@ class OpenApiTest(ServerTestCase): doc = json.loads(body) self.assertEqual(doc["info"]["title"], "GeneNetwork4 API") - for path in ("/", "/version", "/species", "/species/{species}"): + for path in ( + "/", + "/version", + "/species", + "/species/{species}", + "/groups", + "/groups/{group}", + ): self.assertIn(path, doc["paths"]) |
