mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-26 18:00:27 -04:00
Update black, and run auto formatting over the codebase (#9381)
- Update black version to the latest
- Run black auto formatting over the codebase
- Run autoformatting according to [`docs/code_style.md
`](80d6dc9783/docs/code_style.md
)
- Update `code_style.md` docs around installing black to use the correct version
This commit is contained in:
parent
5636e597c3
commit
0a00b7ff14
271 changed files with 2802 additions and 1713 deletions
|
@ -127,8 +127,7 @@ class ShutdownRoomTestCase(unittest.HomeserverTestCase):
|
|||
self._assert_peek(room_id, expect_code=403)
|
||||
|
||||
def _assert_peek(self, room_id, expect_code):
|
||||
"""Assert that the admin user can (or cannot) peek into the room.
|
||||
"""
|
||||
"""Assert that the admin user can (or cannot) peek into the room."""
|
||||
|
||||
url = "rooms/%s/initialSync" % (room_id,)
|
||||
channel = self.make_request(
|
||||
|
@ -186,7 +185,10 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
"POST", self.url, json.dumps({}), access_token=self.other_user_tok,
|
||||
"POST",
|
||||
self.url,
|
||||
json.dumps({}),
|
||||
access_token=self.other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||
|
@ -199,7 +201,10 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
url = "/_synapse/admin/v1/rooms/!unknown:test/delete"
|
||||
|
||||
channel = self.make_request(
|
||||
"POST", url, json.dumps({}), access_token=self.admin_user_tok,
|
||||
"POST",
|
||||
url,
|
||||
json.dumps({}),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(404, int(channel.result["code"]), msg=channel.result["body"])
|
||||
|
@ -212,12 +217,16 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
url = "/_synapse/admin/v1/rooms/invalidroom/delete"
|
||||
|
||||
channel = self.make_request(
|
||||
"POST", url, json.dumps({}), access_token=self.admin_user_tok,
|
||||
"POST",
|
||||
url,
|
||||
json.dumps({}),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||
self.assertEqual(
|
||||
"invalidroom is not a legal room ID", channel.json_body["error"],
|
||||
"invalidroom is not a legal room ID",
|
||||
channel.json_body["error"],
|
||||
)
|
||||
|
||||
def test_new_room_user_does_not_exist(self):
|
||||
|
@ -254,7 +263,8 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||
self.assertEqual(
|
||||
"User must be our own: @not:exist.bla", channel.json_body["error"],
|
||||
"User must be our own: @not:exist.bla",
|
||||
channel.json_body["error"],
|
||||
)
|
||||
|
||||
def test_block_is_not_bool(self):
|
||||
|
@ -491,8 +501,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
self._assert_peek(self.room_id, expect_code=403)
|
||||
|
||||
def _is_blocked(self, room_id, expect=True):
|
||||
"""Assert that the room is blocked or not
|
||||
"""
|
||||
"""Assert that the room is blocked or not"""
|
||||
d = self.store.is_room_blocked(room_id)
|
||||
if expect:
|
||||
self.assertTrue(self.get_success(d))
|
||||
|
@ -500,20 +509,17 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
self.assertIsNone(self.get_success(d))
|
||||
|
||||
def _has_no_members(self, room_id):
|
||||
"""Assert there is now no longer anyone in the room
|
||||
"""
|
||||
"""Assert there is now no longer anyone in the room"""
|
||||
users_in_room = self.get_success(self.store.get_users_in_room(room_id))
|
||||
self.assertEqual([], users_in_room)
|
||||
|
||||
def _is_member(self, room_id, user_id):
|
||||
"""Test that user is member of the room
|
||||
"""
|
||||
"""Test that user is member of the room"""
|
||||
users_in_room = self.get_success(self.store.get_users_in_room(room_id))
|
||||
self.assertIn(user_id, users_in_room)
|
||||
|
||||
def _is_purged(self, room_id):
|
||||
"""Test that the following tables have been purged of all rows related to the room.
|
||||
"""
|
||||
"""Test that the following tables have been purged of all rows related to the room."""
|
||||
for table in PURGE_TABLES:
|
||||
count = self.get_success(
|
||||
self.store.db_pool.simple_select_one_onecol(
|
||||
|
@ -527,8 +533,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
self.assertEqual(count, 0, msg="Rows not purged in {}".format(table))
|
||||
|
||||
def _assert_peek(self, room_id, expect_code):
|
||||
"""Assert that the admin user can (or cannot) peek into the room.
|
||||
"""
|
||||
"""Assert that the admin user can (or cannot) peek into the room."""
|
||||
|
||||
url = "rooms/%s/initialSync" % (room_id,)
|
||||
channel = self.make_request(
|
||||
|
@ -548,8 +553,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
|
||||
class PurgeRoomTestCase(unittest.HomeserverTestCase):
|
||||
"""Test /purge_room admin API.
|
||||
"""
|
||||
"""Test /purge_room admin API."""
|
||||
|
||||
servlets = [
|
||||
synapse.rest.admin.register_servlets,
|
||||
|
@ -594,8 +598,7 @@ class PurgeRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
|
||||
class RoomTestCase(unittest.HomeserverTestCase):
|
||||
"""Test /room admin API.
|
||||
"""
|
||||
"""Test /room admin API."""
|
||||
|
||||
servlets = [
|
||||
synapse.rest.admin.register_servlets,
|
||||
|
@ -623,7 +626,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
# Request the list of rooms
|
||||
url = "/_synapse/admin/v1/rooms"
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
# Check request completed successfully
|
||||
|
@ -685,7 +690,10 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
# Set the name of the rooms so we get a consistent returned ordering
|
||||
for idx, room_id in enumerate(room_ids):
|
||||
self.helper.send_state(
|
||||
room_id, "m.room.name", {"name": str(idx)}, tok=self.admin_user_tok,
|
||||
room_id,
|
||||
"m.room.name",
|
||||
{"name": str(idx)},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
|
||||
# Request the list of rooms
|
||||
|
@ -704,7 +712,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
"name",
|
||||
)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
200, int(channel.result["code"]), msg=channel.result["body"]
|
||||
|
@ -744,7 +754,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
url = "/_synapse/admin/v1/rooms?from=%d&limit=%d" % (start, limit)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||
|
||||
|
@ -788,13 +800,18 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Set a name for the room
|
||||
self.helper.send_state(
|
||||
room_id, "m.room.name", {"name": test_room_name}, tok=self.admin_user_tok,
|
||||
room_id,
|
||||
"m.room.name",
|
||||
{"name": test_room_name},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
|
||||
# Request the list of rooms
|
||||
url = "/_synapse/admin/v1/rooms"
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||
|
||||
|
@ -860,7 +877,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
def _order_test(
|
||||
order_type: str, expected_room_list: List[str], reverse: bool = False,
|
||||
order_type: str,
|
||||
expected_room_list: List[str],
|
||||
reverse: bool = False,
|
||||
):
|
||||
"""Request the list of rooms in a certain order. Assert that order is what
|
||||
we expect
|
||||
|
@ -875,7 +894,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
if reverse:
|
||||
url += "&dir=b"
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
|
@ -907,13 +928,22 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Set room names in alphabetical order. room 1 -> A, 2 -> B, 3 -> C
|
||||
self.helper.send_state(
|
||||
room_id_1, "m.room.name", {"name": "A"}, tok=self.admin_user_tok,
|
||||
room_id_1,
|
||||
"m.room.name",
|
||||
{"name": "A"},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
self.helper.send_state(
|
||||
room_id_2, "m.room.name", {"name": "B"}, tok=self.admin_user_tok,
|
||||
room_id_2,
|
||||
"m.room.name",
|
||||
{"name": "B"},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
self.helper.send_state(
|
||||
room_id_3, "m.room.name", {"name": "C"}, tok=self.admin_user_tok,
|
||||
room_id_3,
|
||||
"m.room.name",
|
||||
{"name": "C"},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
|
||||
# Set room canonical room aliases
|
||||
|
@ -990,10 +1020,16 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Set the name for each room
|
||||
self.helper.send_state(
|
||||
room_id_1, "m.room.name", {"name": room_name_1}, tok=self.admin_user_tok,
|
||||
room_id_1,
|
||||
"m.room.name",
|
||||
{"name": room_name_1},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
self.helper.send_state(
|
||||
room_id_2, "m.room.name", {"name": room_name_2}, tok=self.admin_user_tok,
|
||||
room_id_2,
|
||||
"m.room.name",
|
||||
{"name": room_name_2},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
|
||||
def _search_test(
|
||||
|
@ -1011,7 +1047,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
"""
|
||||
url = "/_synapse/admin/v1/rooms?search_term=%s" % (search_term,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(expected_http_code, channel.code, msg=channel.json_body)
|
||||
|
||||
|
@ -1071,15 +1109,23 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Set the name for each room
|
||||
self.helper.send_state(
|
||||
room_id_1, "m.room.name", {"name": room_name_1}, tok=self.admin_user_tok,
|
||||
room_id_1,
|
||||
"m.room.name",
|
||||
{"name": room_name_1},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
self.helper.send_state(
|
||||
room_id_2, "m.room.name", {"name": room_name_2}, tok=self.admin_user_tok,
|
||||
room_id_2,
|
||||
"m.room.name",
|
||||
{"name": room_name_2},
|
||||
tok=self.admin_user_tok,
|
||||
)
|
||||
|
||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
|
@ -1109,7 +1155,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["joined_local_devices"])
|
||||
|
@ -1121,7 +1169,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(2, channel.json_body["joined_local_devices"])
|
||||
|
@ -1131,7 +1181,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
self.helper.leave(room_id_1, user_1, tok=user_tok_1)
|
||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["joined_local_devices"])
|
||||
|
@ -1160,7 +1212,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_1,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
|
@ -1171,7 +1225,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_2,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
|
@ -1187,7 +1243,9 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
url = "/_synapse/admin/v1/rooms/%s/state" % (room_id,)
|
||||
channel = self.make_request(
|
||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("state", channel.json_body)
|
||||
|
@ -1342,7 +1400,9 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
# Validate if user is a member of the room
|
||||
|
||||
channel = self.make_request(
|
||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
||||
"GET",
|
||||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.second_tok,
|
||||
)
|
||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||
self.assertEqual(self.public_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
@ -1389,7 +1449,9 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
# Validate if server admin is a member of the room
|
||||
|
||||
channel = self.make_request(
|
||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.admin_user_tok,
|
||||
"GET",
|
||||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
@ -1411,7 +1473,9 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
# Validate if user is a member of the room
|
||||
|
||||
channel = self.make_request(
|
||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
||||
"GET",
|
||||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.second_tok,
|
||||
)
|
||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
@ -1440,7 +1504,9 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
# Validate if user is a member of the room
|
||||
|
||||
channel = self.make_request(
|
||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
||||
"GET",
|
||||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.second_tok,
|
||||
)
|
||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
@ -1555,8 +1621,7 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
def test_public_room(self):
|
||||
"""Test that getting admin in a public room works.
|
||||
"""
|
||||
"""Test that getting admin in a public room works."""
|
||||
room_id = self.helper.create_room_as(
|
||||
self.creator, tok=self.creator_tok, is_public=True
|
||||
)
|
||||
|
@ -1581,10 +1646,11 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
def test_private_room(self):
|
||||
"""Test that getting admin in a private room works and we get invited.
|
||||
"""
|
||||
"""Test that getting admin in a private room works and we get invited."""
|
||||
room_id = self.helper.create_room_as(
|
||||
self.creator, tok=self.creator_tok, is_public=False,
|
||||
self.creator,
|
||||
tok=self.creator_tok,
|
||||
is_public=False,
|
||||
)
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -1608,8 +1674,7 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
def test_other_user(self):
|
||||
"""Test that giving admin in a public room works to a non-admin user works.
|
||||
"""
|
||||
"""Test that giving admin in a public room works to a non-admin user works."""
|
||||
room_id = self.helper.create_room_as(
|
||||
self.creator, tok=self.creator_tok, is_public=True
|
||||
)
|
||||
|
@ -1634,8 +1699,7 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
def test_not_enough_power(self):
|
||||
"""Test that we get a sensible error if there are no local room admins.
|
||||
"""
|
||||
"""Test that we get a sensible error if there are no local room admins."""
|
||||
room_id = self.helper.create_room_as(
|
||||
self.creator, tok=self.creator_tok, is_public=True
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue