loomio tests: unwrap AMS collection-shaped root
continuous-integration/drone/push Build is failing

This commit is contained in:
notplants
2026-11-26 02:54:53 +00:00
parent f6cf16a220
commit cd30c0ec0d
+12 -3
View File
@@ -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