From 168f31e4d4160f59e72811c947f419adb78a04c0 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 20 Dec 2021 16:03:18 +0000 Subject: [PATCH] Clean up the URL generation code --- tests/rest/client/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/rest/client/utils.py b/tests/rest/client/utils.py index af85c0dc80d5..cf37a7829a71 100644 --- a/tests/rest/client/utils.py +++ b/tests/rest/client/utils.py @@ -31,6 +31,7 @@ overload, ) from unittest.mock import patch +from urllib.parse import urlencode import attr from typing_extensions import Literal @@ -235,15 +236,16 @@ def change_membership( temp_id = self.auth_user_id self.auth_user_id = src - path = "/_matrix/client/r0/rooms/%s/state/m.room.member/%s" % (room, targ) - next_arg_char = "?" + path = f"/_matrix/client/r0/rooms/{room}/state/m.room.member/{targ}" + url_params: Dict[str, str] = {} if tok: - path += "?access_token=%s" % tok - next_arg_char = "&" + url_params["access_token"] = tok if appservice_user_id: - path += f"{next_arg_char}user_id={appservice_user_id}" + url_params["user_id"] = appservice_user_id + + path += "?" + urlencode(url_params) data = {"membership": membership} data.update(extra_data or {})