about summary refs log tree commit diff
path: root/test/python/test_traits.py
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-08 11:24:58 +0000
committerPjotr <wrk@bosa.lan>2026-10-08 11:55:30 +0000
commit22540223c43342473d7d428dffeeab9d94afb55c (patch)
treef81c6af04ea9157054a58d3fc20e99f55973a0ae /test/python/test_traits.py
parent5650076cdf45a26aed8c6166069d74281a7f4bd7 (diff)
downloadgenenetwork4-22540223c43342473d7d428dffeeab9d94afb55c.tar.gz
* src/response.rs: wrap every success response in one envelope.
Breaking: every success body is now {"data", "meta": {"state",
"took_ms", "request_id"}, "notes", "next"}; clients read `data`. Only
`/` (plain text) and `/openapi.json` are unwrapped.

* src/response.rs (Envelope, Meta, State, Ctx, RequestInfo): handlers
take Ctx first and build the response with ctx.envelope(data), so
timing and the request id are never filled in by hand. `state` is
`complete` or `partial`; notes are server-authored only; `next` are
concrete relative hrefs (path_segment percent-encodes names).
* src/routes/*.rs, src/lib.rs (version): every handler returns
Envelope<..> with next links; /search is `partial` when the locus
lookup fails or a sorted 1000-hit window may be truncated, and
/publications/{pubmed_id}/traits when datasets were left out for
authorization.
* src/error.rs (ApiError): add `took_ms`, an RFC 7807 extension member.
* src/auth.rs (AuthToken): the 401 now carries request_id and took_ms
(it never had a request_id); Ctx stores RequestInfo in the request
extensions for it.

* tests: common::data / envelope_data parse every success body through
the envelope; tests/envelope.rs and test/python/test_envelope.py check
the shape, errors, and that every `next` link resolves;
tests/envelope_partial.rs checks the `partial` search without a
database; tests/openapi.rs fails if a JSON success response is not an
Envelope_* schema.
* README.md, docs/SKILL.md, docs/gn-auth.md, RELEASE_NOTES.md: document
the envelope and took_ms on errors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test/python/test_traits.py')
-rw-r--r--test/python/test_traits.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/test/python/test_traits.py b/test/python/test_traits.py
index 6a44bd8..850aa8a 100644
--- a/test/python/test_traits.py
+++ b/test/python/test_traits.py
@@ -12,7 +12,7 @@ import socket
 import unittest
 
 from auth_helpers import TOKEN_ENV, auth_server_reachable, auth_token
-from server_test_case import HOST, PORT, ServerTestCase
+from server_test_case import HOST, PORT, ServerTestCase, envelope_data
 
 
 def database_reachable():
@@ -50,7 +50,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/Br_U_0803_M/100001_at")
         self.assertEqual(response.status, 200)
 
-        info = json.loads(body)
+        info = envelope_data(body)
         self.assertEqual(info["category"], "probeset")
         self.assertEqual(info["name"], "100001_at")
         self.assertEqual(info["symbol"], "Cd3g")
@@ -61,7 +61,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/BXD/10001")
         self.assertEqual(response.status, 200)
 
-        info = json.loads(body)
+        info = envelope_data(body)
         self.assertEqual(info["category"], "publish")
         self.assertEqual(info["id"], 10001)
 
@@ -71,7 +71,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/BXDPublish/10001")
         self.assertEqual(response.status, 200)
 
-        info = json.loads(body)
+        info = envelope_data(body)
         self.assertEqual(info["category"], "publish")
         self.assertEqual(info["id"], 10001)
 
@@ -81,7 +81,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/Br_U_0803_M/100001_at/values")
         self.assertEqual(response.status, 200)
 
-        values = json.loads(body)
+        values = envelope_data(body)
         self.assertTrue(values)
         self.assertIn("BXD1", {v["name"] for v in values})
 
@@ -91,7 +91,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/BXD/10001/values")
         self.assertEqual(response.status, 200)
 
-        values = json.loads(body)
+        values = envelope_data(body)
         self.assertTrue(values)
         self.assertIn("BXD1", {v["name"] for v in values})
 
@@ -101,7 +101,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/Br_U_0803_M")
         self.assertEqual(response.status, 200)
 
-        traits = json.loads(body)
+        traits = envelope_data(body)
         self.assertTrue(traits)
         self.assertTrue(all(t["category"] == "probeset" for t in traits))
         self.assertIn("100001_at", {t["name"] for t in traits})
@@ -112,7 +112,7 @@ class TraitsTest(ServerTestCase):
         response, body = self.get("/traits/BXD")
         self.assertEqual(response.status, 200)
 
-        traits = json.loads(body)
+        traits = envelope_data(body)
         self.assertTrue(traits)
         self.assertTrue(all(t["category"] == "publish" for t in traits))
         self.assertIn(10001, {t["id"] for t in traits})