From fa2b8b71fa09b6f0eaf14096225a177abf6dbec0 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 30 Nov 2021 14:34:19 +0100 Subject: [PATCH 1/3] Remove not needed `json.dumps` from `tests.rest.admin` --- tests/rest/admin/test_room.py | 61 ++++++++++++----------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/tests/rest/admin/test_room.py b/tests/rest/admin/test_room.py index 56b7a438b687..681f9173ef8a 100644 --- a/tests/rest/admin/test_room.py +++ b/tests/rest/admin/test_room.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import urllib.parse from http import HTTPStatus from typing import List, Optional @@ -118,12 +117,11 @@ def test_new_room_user_does_not_exist(self): """ Tests that the user ID must be from local server but it does not have to exist. """ - body = json.dumps({"new_room_user_id": "@unknown:test"}) channel = self.make_request( "DELETE", self.url, - content=body, + content={"new_room_user_id": "@unknown:test"}, access_token=self.admin_user_tok, ) @@ -137,12 +135,11 @@ def test_new_room_user_is_not_local(self): """ Check that only local users can create new room to move members. """ - body = json.dumps({"new_room_user_id": "@not:exist.bla"}) channel = self.make_request( "DELETE", self.url, - content=body, + content={"new_room_user_id": "@not:exist.bla"}, access_token=self.admin_user_tok, ) @@ -156,12 +153,11 @@ def test_block_is_not_bool(self): """ If parameter `block` is not boolean, return an error """ - body = json.dumps({"block": "NotBool"}) channel = self.make_request( "DELETE", self.url, - content=body, + content={"block": "NotBool"}, access_token=self.admin_user_tok, ) @@ -172,12 +168,11 @@ def test_purge_is_not_bool(self): """ If parameter `purge` is not boolean, return an error """ - body = json.dumps({"purge": "NotBool"}) channel = self.make_request( "DELETE", self.url, - content=body, + content={"purge": "NotBool"}, access_token=self.admin_user_tok, ) @@ -198,12 +193,10 @@ def test_purge_room_and_block(self): # Assert one user in room self._is_member(room_id=self.room_id, user_id=self.other_user) - body = json.dumps({"block": True, "purge": True}) - channel = self.make_request( "DELETE", self.url.encode("ascii"), - content=body, + content={"block": True, "purge": True}, access_token=self.admin_user_tok, ) @@ -231,12 +224,10 @@ def test_purge_room_and_not_block(self): # Assert one user in room self._is_member(room_id=self.room_id, user_id=self.other_user) - body = json.dumps({"block": False, "purge": True}) - channel = self.make_request( "DELETE", self.url.encode("ascii"), - content=body, + content={"block": False, "purge": True}, access_token=self.admin_user_tok, ) @@ -265,12 +256,10 @@ def test_block_room_and_not_purge(self): # Assert one user in room self._is_member(room_id=self.room_id, user_id=self.other_user) - body = json.dumps({"block": True, "purge": False}) - channel = self.make_request( "DELETE", self.url.encode("ascii"), - content=body, + content={"block": True, "purge": False}, access_token=self.admin_user_tok, ) @@ -342,7 +331,7 @@ def test_shutdown_room_consent(self): channel = self.make_request( "DELETE", self.url, - json.dumps({"new_room_user_id": self.admin_user}), + {"new_room_user_id": self.admin_user}, access_token=self.admin_user_tok, ) @@ -372,7 +361,7 @@ def test_shutdown_room_block_peek(self): channel = self.make_request( "PUT", url.encode("ascii"), - json.dumps({"history_visibility": "world_readable"}), + {"history_visibility": "world_readable"}, access_token=self.other_user_tok, ) self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body) @@ -388,7 +377,7 @@ def test_shutdown_room_block_peek(self): channel = self.make_request( "DELETE", self.url, - json.dumps({"new_room_user_id": self.admin_user}), + {"new_room_user_id": self.admin_user}, access_token=self.admin_user_tok, ) @@ -1782,12 +1771,11 @@ def test_requester_is_no_admin(self): """ If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned. """ - body = json.dumps({"user_id": self.second_user_id}) channel = self.make_request( "POST", self.url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.second_tok, ) @@ -1798,12 +1786,11 @@ def test_invalid_parameter(self): """ If a parameter is missing, return an error """ - body = json.dumps({"unknown_parameter": "@unknown:test"}) channel = self.make_request( "POST", self.url, - content=body, + content={"unknown_parameter": "@unknown:test"}, access_token=self.admin_user_tok, ) @@ -1814,12 +1801,11 @@ def test_local_user_does_not_exist(self): """ Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND """ - body = json.dumps({"user_id": "@unknown:test"}) channel = self.make_request( "POST", self.url, - content=body, + content={"user_id": "@unknown:test"}, access_token=self.admin_user_tok, ) @@ -1830,12 +1816,11 @@ def test_remote_user(self): """ Check that only local user can join rooms. """ - body = json.dumps({"user_id": "@not:exist.bla"}) channel = self.make_request( "POST", self.url, - content=body, + content={"user_id": "@not:exist.bla"}, access_token=self.admin_user_tok, ) @@ -1849,13 +1834,12 @@ def test_room_does_not_exist(self): """ Check that unknown rooms/server return error HTTPStatus.NOT_FOUND. """ - body = json.dumps({"user_id": self.second_user_id}) url = "/_synapse/admin/v1/join/!unknown:test" channel = self.make_request( "POST", url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.admin_user_tok, ) @@ -1866,13 +1850,12 @@ def test_room_is_not_valid(self): """ Check that invalid room names, return an error HTTPStatus.BAD_REQUEST. """ - body = json.dumps({"user_id": self.second_user_id}) url = "/_synapse/admin/v1/join/invalidroom" channel = self.make_request( "POST", url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.admin_user_tok, ) @@ -1886,12 +1869,11 @@ def test_join_public_room(self): """ Test joining a local user to a public room with "JoinRules.PUBLIC" """ - body = json.dumps({"user_id": self.second_user_id}) channel = self.make_request( "POST", self.url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.admin_user_tok, ) @@ -1917,12 +1899,11 @@ def test_join_private_room_if_not_member(self): self.creator, tok=self.creator_tok, is_public=False ) url = f"/_synapse/admin/v1/join/{private_room_id}" - body = json.dumps({"user_id": self.second_user_id}) channel = self.make_request( "POST", url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.admin_user_tok, ) @@ -1960,12 +1941,11 @@ def test_join_private_room_if_member(self): # Join user to room. url = f"/_synapse/admin/v1/join/{private_room_id}" - body = json.dumps({"user_id": self.second_user_id}) channel = self.make_request( "POST", url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.admin_user_tok, ) self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body) @@ -1990,12 +1970,11 @@ def test_join_private_room_if_owner(self): self.admin_user, tok=self.admin_user_tok, is_public=False ) url = f"/_synapse/admin/v1/join/{private_room_id}" - body = json.dumps({"user_id": self.second_user_id}) channel = self.make_request( "POST", url, - content=body, + content={"user_id": self.second_user_id}, access_token=self.admin_user_tok, ) From 3afaa094e59ebfe1d53709429fe2a67034b1997d Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 30 Nov 2021 14:37:25 +0100 Subject: [PATCH 2/3] newsfile --- changelog.d/11461.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/11461.misc diff --git a/changelog.d/11461.misc b/changelog.d/11461.misc new file mode 100644 index 000000000000..b6ce2a02328a --- /dev/null +++ b/changelog.d/11461.misc @@ -0,0 +1 @@ +Remove not needed `json.dumps` from `tests.rest.admin`. \ No newline at end of file From 3745a4e0f383097b1a5783adf9afe33ed25ba89b Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:20:34 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Patrick Cloke --- changelog.d/11461.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/11461.misc b/changelog.d/11461.misc index b6ce2a02328a..92133f9eaa24 100644 --- a/changelog.d/11461.misc +++ b/changelog.d/11461.misc @@ -1 +1 @@ -Remove not needed `json.dumps` from `tests.rest.admin`. \ No newline at end of file +Remove unnecessary `json.dumps` from `tests.rest.admin`. \ No newline at end of file