Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add a separate json_list method on FakeChannel.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Jul 27, 2022
1 parent 700dfcf commit aca8cf6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 1 addition & 3 deletions tests/rest/client/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Callable,
Dict,
Iterable,
List,
MutableMapping,
Optional,
Tuple,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit aca8cf6

Please sign in to comment.