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

Remove not needed json.dumps from tests.rest.admin #11461

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11461.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unnecessary `json.dumps` from `tests.rest.admin`.
61 changes: 20 additions & 41 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
)

Expand Down