diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2021-02-16 16:32:34 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-16 22:32:34 +0000 |
commit | 0a00b7ff14890987f09112a2ae696c61001e6cf1 (patch) | |
tree | e662b6da7679b47276d8a865e3dc9b531d1cd9bd /tests/handlers | |
parent | Fix OIDC gitiea redirect URL. (#9404) (diff) | |
download | synapse-0a00b7ff14890987f09112a2ae696c61001e6cf1.tar.xz |
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 `](https://github.com/matrix-org/synapse/blob/80d6dc9783aa80886a133756028984dbf8920168/docs/code_style.md) - Update `code_style.md` docs around installing black to use the correct version
Diffstat (limited to 'tests/handlers')
-rw-r--r-- | tests/handlers/test_admin.py | 9 | ||||
-rw-r--r-- | tests/handlers/test_device.py | 4 | ||||
-rw-r--r-- | tests/handlers/test_directory.py | 20 | ||||
-rw-r--r-- | tests/handlers/test_e2e_keys.py | 10 | ||||
-rw-r--r-- | tests/handlers/test_e2e_room_keys.py | 42 | ||||
-rw-r--r-- | tests/handlers/test_federation.py | 12 | ||||
-rw-r--r-- | tests/handlers/test_message.py | 13 | ||||
-rw-r--r-- | tests/handlers/test_oidc.py | 26 | ||||
-rw-r--r-- | tests/handlers/test_password_providers.py | 11 | ||||
-rw-r--r-- | tests/handlers/test_presence.py | 3 | ||||
-rw-r--r-- | tests/handlers/test_profile.py | 4 | ||||
-rw-r--r-- | tests/handlers/test_typing.py | 12 | ||||
-rw-r--r-- | tests/handlers/test_user_directory.py | 12 |
13 files changed, 101 insertions, 77 deletions
diff --git a/tests/handlers/test_admin.py b/tests/handlers/test_admin.py index 5c2b4de1a6..a01fdd0839 100644 --- a/tests/handlers/test_admin.py +++ b/tests/handlers/test_admin.py @@ -44,8 +44,7 @@ class ExfiltrateData(unittest.HomeserverTestCase): self.token2 = self.login("user2", "password") def test_single_public_joined_room(self): - """Test that we write *all* events for a public room - """ + """Test that we write *all* events for a public room""" room_id = self.helper.create_room_as( self.user1, tok=self.token1, is_public=True ) @@ -116,8 +115,7 @@ class ExfiltrateData(unittest.HomeserverTestCase): self.assertEqual(counter[(EventTypes.Member, self.user2)], 1) def test_single_left_room(self): - """Tests that we don't see events in the room after we leave. - """ + """Tests that we don't see events in the room after we leave.""" room_id = self.helper.create_room_as(self.user1, tok=self.token1) self.helper.send(room_id, body="Hello!", tok=self.token1) self.helper.join(room_id, self.user2, tok=self.token2) @@ -190,8 +188,7 @@ class ExfiltrateData(unittest.HomeserverTestCase): self.assertEqual(counter[(EventTypes.Member, self.user2)], 3) def test_invite(self): - """Tests that pending invites get handled correctly. - """ + """Tests that pending invites get handled correctly.""" room_id = self.helper.create_room_as(self.user1, tok=self.token1) self.helper.send(room_id, body="Hello!", tok=self.token1) self.helper.invite(room_id, self.user1, self.user2, tok=self.token1) diff --git a/tests/handlers/test_device.py b/tests/handlers/test_device.py index 5dfeccfeb6..821629bc38 100644 --- a/tests/handlers/test_device.py +++ b/tests/handlers/test_device.py @@ -260,7 +260,9 @@ class DehydrationTestCase(unittest.HomeserverTestCase): # Create a new login for the user and dehydrated the device device_id, access_token = self.get_success( self.registration.register_device( - user_id=user_id, device_id=None, initial_display_name="new device", + user_id=user_id, + device_id=None, + initial_display_name="new device", ) ) diff --git a/tests/handlers/test_directory.py b/tests/handlers/test_directory.py index a39f898608..863d8737b2 100644 --- a/tests/handlers/test_directory.py +++ b/tests/handlers/test_directory.py @@ -131,7 +131,9 @@ class TestCreateAlias(unittest.HomeserverTestCase): """A user can create an alias for a room they're in.""" self.get_success( self.handler.create_association( - create_requester(self.test_user), self.room_alias, self.room_id, + create_requester(self.test_user), + self.room_alias, + self.room_id, ) ) @@ -143,7 +145,9 @@ class TestCreateAlias(unittest.HomeserverTestCase): self.get_failure( self.handler.create_association( - create_requester(self.test_user), self.room_alias, other_room_id, + create_requester(self.test_user), + self.room_alias, + other_room_id, ), synapse.api.errors.SynapseError, ) @@ -156,7 +160,9 @@ class TestCreateAlias(unittest.HomeserverTestCase): self.get_success( self.handler.create_association( - create_requester(self.admin_user), self.room_alias, other_room_id, + create_requester(self.admin_user), + self.room_alias, + other_room_id, ) ) @@ -275,8 +281,7 @@ class TestDeleteAlias(unittest.HomeserverTestCase): class CanonicalAliasTestCase(unittest.HomeserverTestCase): - """Test modifications of the canonical alias when delete aliases. - """ + """Test modifications of the canonical alias when delete aliases.""" servlets = [ synapse.rest.admin.register_servlets, @@ -317,7 +322,10 @@ class CanonicalAliasTestCase(unittest.HomeserverTestCase): def _set_canonical_alias(self, content): """Configure the canonical alias state on the room.""" self.helper.send_state( - self.room_id, "m.room.canonical_alias", content, tok=self.admin_user_tok, + self.room_id, + "m.room.canonical_alias", + content, + tok=self.admin_user_tok, ) def _get_canonical_alias(self): diff --git a/tests/handlers/test_e2e_keys.py b/tests/handlers/test_e2e_keys.py index c1a13aeb71..5e86c5e56b 100644 --- a/tests/handlers/test_e2e_keys.py +++ b/tests/handlers/test_e2e_keys.py @@ -33,8 +33,7 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase): self.store = self.hs.get_datastore() def test_query_local_devices_no_devices(self): - """If the user has no devices, we expect an empty list. - """ + """If the user has no devices, we expect an empty list.""" local_user = "@boris:" + self.hs.hostname res = self.get_success(self.handler.query_local_devices({local_user: None})) self.assertDictEqual(res, {local_user: {}}) @@ -102,7 +101,9 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase): # Error when replacing string key with dict self.get_failure( self.handler.upload_keys_for_user( - local_user, device_id, {"one_time_keys": {"alg1:k1": {"key": "key"}}}, + local_user, + device_id, + {"one_time_keys": {"alg1:k1": {"key": "key"}}}, ), SynapseError, ) @@ -215,7 +216,8 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase): ) ) self.assertEqual( - res, {"failures": {}, "one_time_keys": {local_user: {device_id: otk}}}, + res, + {"failures": {}, "one_time_keys": {local_user: {device_id: otk}}}, ) res = self.get_success( diff --git a/tests/handlers/test_e2e_room_keys.py b/tests/handlers/test_e2e_room_keys.py index 58773a0c38..d7498aa51a 100644 --- a/tests/handlers/test_e2e_room_keys.py +++ b/tests/handlers/test_e2e_room_keys.py @@ -70,8 +70,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 404) def test_create_version(self): - """Check that we can create and then retrieve versions. - """ + """Check that we can create and then retrieve versions.""" res = self.get_success( self.handler.create_version( self.local_user, @@ -138,8 +137,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): ) def test_update_version(self): - """Check that we can update versions. - """ + """Check that we can update versions.""" version = self.get_success( self.handler.create_version( self.local_user, @@ -178,8 +176,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): ) def test_update_missing_version(self): - """Check that we get a 404 on updating nonexistent versions - """ + """Check that we get a 404 on updating nonexistent versions""" e = self.get_failure( self.handler.update_version( self.local_user, @@ -196,8 +193,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 404) def test_update_omitted_version(self): - """Check that the update succeeds if the version is missing from the body - """ + """Check that the update succeeds if the version is missing from the body""" version = self.get_success( self.handler.create_version( self.local_user, @@ -234,8 +230,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): ) def test_update_bad_version(self): - """Check that we get a 400 if the version in the body doesn't match - """ + """Check that we get a 400 if the version in the body doesn't match""" version = self.get_success( self.handler.create_version( self.local_user, @@ -263,8 +258,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 400) def test_delete_missing_version(self): - """Check that we get a 404 on deleting nonexistent versions - """ + """Check that we get a 404 on deleting nonexistent versions""" e = self.get_failure( self.handler.delete_version(self.local_user, "1"), SynapseError ) @@ -272,15 +266,13 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 404) def test_delete_missing_current_version(self): - """Check that we get a 404 on deleting nonexistent current version - """ + """Check that we get a 404 on deleting nonexistent current version""" e = self.get_failure(self.handler.delete_version(self.local_user), SynapseError) res = e.value.code self.assertEqual(res, 404) def test_delete_version(self): - """Check that we can create and then delete versions. - """ + """Check that we can create and then delete versions.""" res = self.get_success( self.handler.create_version( self.local_user, @@ -303,8 +295,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 404) def test_get_missing_backup(self): - """Check that we get a 404 on querying missing backup - """ + """Check that we get a 404 on querying missing backup""" e = self.get_failure( self.handler.get_room_keys(self.local_user, "bogus_version"), SynapseError ) @@ -312,8 +303,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 404) def test_get_missing_room_keys(self): - """Check we get an empty response from an empty backup - """ + """Check we get an empty response from an empty backup""" version = self.get_success( self.handler.create_version( self.local_user, @@ -332,8 +322,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): # although this is probably best done in sytest def test_upload_room_keys_no_versions(self): - """Check that we get a 404 on uploading keys when no versions are defined - """ + """Check that we get a 404 on uploading keys when no versions are defined""" e = self.get_failure( self.handler.upload_room_keys(self.local_user, "no_version", room_keys), SynapseError, @@ -364,8 +353,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 404) def test_upload_room_keys_wrong_version(self): - """Check that we get a 403 on uploading keys for an old version - """ + """Check that we get a 403 on uploading keys for an old version""" version = self.get_success( self.handler.create_version( self.local_user, @@ -395,8 +383,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): self.assertEqual(res, 403) def test_upload_room_keys_insert(self): - """Check that we can insert and retrieve keys for a session - """ + """Check that we can insert and retrieve keys for a session""" version = self.get_success( self.handler.create_version( self.local_user, @@ -510,8 +497,7 @@ class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase): # TODO: check edge cases as well as the common variations here def test_delete_room_keys(self): - """Check that we can insert and delete keys for a session - """ + """Check that we can insert and delete keys for a session""" version = self.get_success( self.handler.create_version( self.local_user, diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py index 983e368592..3af361195b 100644 --- a/tests/handlers/test_federation.py +++ b/tests/handlers/test_federation.py @@ -226,12 +226,20 @@ class FederationTestCase(unittest.HomeserverTestCase): for i in range(3): event = create_invite() self.get_success( - self.handler.on_invite_request(other_server, event, event.room_version,) + self.handler.on_invite_request( + other_server, + event, + event.room_version, + ) ) event = create_invite() self.get_failure( - self.handler.on_invite_request(other_server, event, event.room_version,), + self.handler.on_invite_request( + other_server, + event, + event.room_version, + ), exc=LimitExceededError, ) diff --git a/tests/handlers/test_message.py b/tests/handlers/test_message.py index f955dfa490..a0d1ebdbe3 100644 --- a/tests/handlers/test_message.py +++ b/tests/handlers/test_message.py @@ -44,7 +44,9 @@ class EventCreationTestCase(unittest.HomeserverTestCase): self.room_id = self.helper.create_room_as(self.user_id, tok=self.access_token) self.info = self.get_success( - self.hs.get_datastore().get_user_by_access_token(self.access_token,) + self.hs.get_datastore().get_user_by_access_token( + self.access_token, + ) ) self.token_id = self.info.token_id @@ -169,8 +171,7 @@ class ServerAclValidationTestCase(unittest.HomeserverTestCase): self.room_id = self.helper.create_room_as(self.user_id, tok=self.access_token) def test_allow_server_acl(self): - """Test that sending an ACL that blocks everyone but ourselves works. - """ + """Test that sending an ACL that blocks everyone but ourselves works.""" self.helper.send_state( self.room_id, @@ -181,8 +182,7 @@ class ServerAclValidationTestCase(unittest.HomeserverTestCase): ) def test_deny_server_acl_block_outselves(self): - """Test that sending an ACL that blocks ourselves does not work. - """ + """Test that sending an ACL that blocks ourselves does not work.""" self.helper.send_state( self.room_id, EventTypes.ServerACL, @@ -192,8 +192,7 @@ class ServerAclValidationTestCase(unittest.HomeserverTestCase): ) def test_deny_redact_server_acl(self): - """Test that attempting to redact an ACL is blocked. - """ + """Test that attempting to redact an ACL is blocked.""" body = self.helper.send_state( self.room_id, diff --git a/tests/handlers/test_oidc.py b/tests/handlers/test_oidc.py index 27bb50e3b5..bdd2e02eae 100644 --- a/tests/handlers/test_oidc.py +++ b/tests/handlers/test_oidc.py @@ -512,7 +512,9 @@ class OidcHandlerTestCase(HomeserverTestCase): # Mismatching session session = self._generate_oidc_session_token( - state="state", nonce="nonce", client_redirect_url="http://client/redirect", + state="state", + nonce="nonce", + client_redirect_url="http://client/redirect", ) request.args = {} request.args[b"state"] = [b"mismatching state"] @@ -567,7 +569,9 @@ class OidcHandlerTestCase(HomeserverTestCase): # Internal server error with no JSON body self.http_client.request = simple_async_mock( return_value=FakeResponse( - code=500, phrase=b"Internal Server Error", body=b"Not JSON", + code=500, + phrase=b"Internal Server Error", + body=b"Not JSON", ) ) exc = self.get_failure(self.provider._exchange_code(code), OidcError) @@ -587,7 +591,11 @@ class OidcHandlerTestCase(HomeserverTestCase): # 4xx error without "error" field self.http_client.request = simple_async_mock( - return_value=FakeResponse(code=400, phrase=b"Bad request", body=b"{}",) + return_value=FakeResponse( + code=400, + phrase=b"Bad request", + body=b"{}", + ) ) exc = self.get_failure(self.provider._exchange_code(code), OidcError) self.assertEqual(exc.value.error, "server_error") @@ -595,7 +603,9 @@ class OidcHandlerTestCase(HomeserverTestCase): # 2xx error with "error" field self.http_client.request = simple_async_mock( return_value=FakeResponse( - code=200, phrase=b"OK", body=b'{"error": "some_error"}', + code=200, + phrase=b"OK", + body=b'{"error": "some_error"}', ) ) exc = self.get_failure(self.provider._exchange_code(code), OidcError) @@ -632,7 +642,9 @@ class OidcHandlerTestCase(HomeserverTestCase): state = "state" client_redirect_url = "http://client/redirect" session = self._generate_oidc_session_token( - state=state, nonce="nonce", client_redirect_url=client_redirect_url, + state=state, + nonce="nonce", + client_redirect_url=client_redirect_url, ) request = _build_callback_request("code", state, session) @@ -895,7 +907,9 @@ async def _make_callback_with_userinfo( session = handler._token_generator.generate_oidc_session_token( state=state, session_data=OidcSessionData( - idp_id="oidc", nonce="nonce", client_redirect_url=client_redirect_url, + idp_id="oidc", + nonce="nonce", + client_redirect_url=client_redirect_url, ), ) request = _build_callback_request("code", state, session) diff --git a/tests/handlers/test_password_providers.py b/tests/handlers/test_password_providers.py index f816594ee4..a98a65ae67 100644 --- a/tests/handlers/test_password_providers.py +++ b/tests/handlers/test_password_providers.py @@ -231,8 +231,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase): } ) def test_no_local_user_fallback_login(self): - """localdb_enabled can block login with the local password - """ + """localdb_enabled can block login with the local password""" self.register_user("localuser", "localpass") # check_password must return an awaitable @@ -251,8 +250,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase): } ) def test_no_local_user_fallback_ui_auth(self): - """localdb_enabled can block ui auth with the local password - """ + """localdb_enabled can block ui auth with the local password""" self.register_user("localuser", "localpass") # allow login via the auth provider @@ -594,7 +592,10 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase): ) def _delete_device( - self, access_token: str, device: str, body: Union[JsonDict, bytes] = b"", + self, + access_token: str, + device: str, + body: Union[JsonDict, bytes] = b"", ) -> FakeChannel: """Delete an individual device.""" channel = self.make_request( diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index 0794b32c9c..be2ee26f07 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -589,8 +589,7 @@ class PresenceJoinTestCase(unittest.HomeserverTestCase): ) def _add_new_user(self, room_id, user_id): - """Add new user to the room by creating an event and poking the federation API. - """ + """Add new user to the room by creating an event and poking the federation API.""" hostname = get_domain_from_id(user_id) diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py index 787fab7875..18ca8b84f5 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py @@ -208,7 +208,9 @@ class ProfileTestCase(unittest.HomeserverTestCase): # Set avatar to an empty string self.get_success( self.handler.set_avatar_url( - self.frank, synapse.types.create_requester(self.frank), "", + self.frank, + synapse.types.create_requester(self.frank), + "", ) ) diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py index 96e5bdac4a..24e7138196 100644 --- a/tests/handlers/test_typing.py +++ b/tests/handlers/test_typing.py @@ -143,14 +143,14 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase): self.datastore.get_current_state_deltas = Mock(return_value=(0, None)) self.datastore.get_to_device_stream_token = lambda: 0 - self.datastore.get_new_device_msgs_for_remote = lambda *args, **kargs: make_awaitable( - ([], 0) + self.datastore.get_new_device_msgs_for_remote = ( + lambda *args, **kargs: make_awaitable(([], 0)) ) - self.datastore.delete_device_msgs_for_remote = lambda *args, **kargs: make_awaitable( - None + self.datastore.delete_device_msgs_for_remote = ( + lambda *args, **kargs: make_awaitable(None) ) - self.datastore.set_received_txn_response = lambda *args, **kwargs: make_awaitable( - None + self.datastore.set_received_txn_response = ( + lambda *args, **kwargs: make_awaitable(None) ) def test_started_typing_local(self): diff --git a/tests/handlers/test_user_directory.py b/tests/handlers/test_user_directory.py index 9c886d671a..3572e54c5d 100644 --- a/tests/handlers/test_user_directory.py +++ b/tests/handlers/test_user_directory.py @@ -200,7 +200,9 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase): # Check that the room has an encryption state event event_content = self.helper.get_state( - room_id=room_id, event_type=EventTypes.RoomEncryption, tok=user_token, + room_id=room_id, + event_type=EventTypes.RoomEncryption, + tok=user_token, ) self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT}) @@ -209,7 +211,9 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase): # Check that the room has an encryption state event event_content = self.helper.get_state( - room_id=room_id, event_type=EventTypes.RoomEncryption, tok=user_token, + room_id=room_id, + event_type=EventTypes.RoomEncryption, + tok=user_token, ) self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT}) @@ -227,7 +231,9 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase): # Check that the room has an encryption state event event_content = self.helper.get_state( - room_id=room_id, event_type=EventTypes.RoomEncryption, tok=user_token, + room_id=room_id, + event_type=EventTypes.RoomEncryption, + tok=user_token, ) self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT}) |