From aca8cf6808cb22c7186f6ebc5011790033bcbec3 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 27 Jul 2022 07:29:20 -0400 Subject: [PATCH] Add a separate json_list method on FakeChannel. --- tests/rest/client/test_rooms.py | 4 +--- tests/server.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index f99756499e7c..2272d55d84ec 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -495,10 +495,8 @@ def test_get_state_cancellation(self) -> None: ) self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.result["body"]) - # json_body is defined as JsonDict, but it can be any valid JSON. - json_body: List[JsonDict] = channel.json_body # type: ignore[assignment] self.assertCountEqual( - [state_event["type"] for state_event in json_body], + [state_event["type"] for state_event in channel.json_list], { "m.room.create", "m.room.power_levels", diff --git a/tests/server.py b/tests/server.py index df3f1564c9ea..9689e6a0cdc5 100644 --- a/tests/server.py +++ b/tests/server.py @@ -25,6 +25,7 @@ Callable, Dict, Iterable, + List, MutableMapping, Optional, Tuple, @@ -121,7 +122,15 @@ def request(self, request: Request) -> None: @property def json_body(self) -> JsonDict: - return json.loads(self.text_body) + body = json.loads(self.text_body) + assert isinstance(body, dict) + return body + + @property + def json_list(self) -> List[JsonDict]: + body = json.loads(self.text_body) + assert isinstance(body, list) + return body @property def text_body(self) -> str: