def assert_validation_error(resp, field_name: str): assert resp.status_code == 422 body = resp.json() assert body.get("success") is False assert body.get("error", {}).get("code") == "validation_error" # Ensure correlation id is present and echoed in header cid = body.get("correlation_id") assert isinstance(cid, str) and cid assert resp.headers.get("X-Correlation-ID") == cid # Ensure the field appears in details details = body.get("error", {}).get("details", []) assert any(field_name in ":".join(map(str, err.get("loc", []))) for err in details) def assert_http_error(resp, status_code: int, message_substr: str): assert resp.status_code == status_code body = resp.json() assert body.get("success") is False assert body.get("error", {}).get("code") == "http_error" assert message_substr in body.get("error", {}).get("message", "") cid = body.get("correlation_id") assert isinstance(cid, str) and cid assert resp.headers.get("X-Correlation-ID") == cid