From 71948ff2e3799ca53c9ea48362169a8be0a9836b Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 22 Dec 2025 14:27:14 +0000 Subject: [PATCH] Add test helper for sending sticky events --- tests/rest/client/utils.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/rest/client/utils.py b/tests/rest/client/utils.py index b3808d75bb..81a95461cf 100644 --- a/tests/rest/client/utils.py +++ b/tests/rest/client/utils.py @@ -453,6 +453,40 @@ class RestHelper: return channel.json_body + def send_sticky_event( + self, + room_id: str, + type: str, + *, + duration_ms: int, + content: dict | None = None, + txn_id: str | None = None, + tok: str | None = None, + expect_code: int = HTTPStatus.OK, + custom_headers: Iterable[tuple[AnyStr, AnyStr]] | None = None, + ) -> JsonDict: + if txn_id is None: + txn_id = f"m{time.time()}" + + path = f"/_matrix/client/r0/rooms/{room_id}/send/{type}/{txn_id}?org.matrix.msc4354.sticky_duration_ms={duration_ms}" + if tok: + path = path + f"&access_token={tok}" + + channel = make_request( + self.reactor, + self.site, + "PUT", + path, + content or {}, + custom_headers=custom_headers, + ) + + assert channel.code == expect_code, ( + f"Expected: {expect_code}, got: {channel.code}, resp: {channel.result['body']!r}" + ) + + return channel.json_body + def get_event( self, room_id: str,