From cd30c0ec0d1ac30f3e05e8f5a6470099a32e72ff Mon Sep 17 00:00:00 2001 From: notplants <@notplants> Date: Thu, 26 Nov 2026 02:54:53 +0000 Subject: [PATCH] loomio tests: unwrap AMS collection-shaped root --- tests/loomio/custom/_loomio.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/loomio/custom/_loomio.py b/tests/loomio/custom/_loomio.py index 6b067f8..1d45fc9 100644 --- a/tests/loomio/custom/_loomio.py +++ b/tests/loomio/custom/_loomio.py @@ -119,8 +119,17 @@ def ensure_discussion(domain: str) -> tuple[str, str]: def unwrap(body: object, root: str) -> dict: - """AMS wraps responses with a root key (`{"groups": {...}}`); accept a bare object too.""" - if isinstance(body, dict) and isinstance(body.get(root), dict): - return body[root] + """Unwrap an AMS response. + + `respond_with_collection` serializes even a single resource as an array under the root key, so + the shapes seen are `{"groups": [{...}]}`, `{"discussions": [{...}]}`, or (bare) `{...}`. + """ + if isinstance(body, dict) and root in body: + value = body[root] + if isinstance(value, list): + assert value, f"empty {root!r} collection in API response: {body!r}" + value = value[0] + if isinstance(value, dict): + return value assert isinstance(body, dict), f"expected a JSON object, got {type(body).__name__}: {body!r}" return body