3131from synapse .handlers .appservice import ApplicationServicesHandler
3232from synapse .rest .client import login , receipts , register , room , sendtodevice
3333from synapse .server import HomeServer
34- from synapse .types import RoomStreamToken
34+ from synapse .types import JsonDict , RoomStreamToken
3535from synapse .util import Clock
3636from synapse .util .stringutils import random_string
3737
4444class AppServiceHandlerTestCase (unittest .TestCase ):
4545 """Tests the ApplicationServicesHandler."""
4646
47- def setUp (self ):
47+ def setUp (self ) -> None :
4848 self .mock_store = Mock ()
4949 self .mock_as_api = Mock ()
5050 self .mock_scheduler = Mock ()
@@ -61,7 +61,7 @@ def setUp(self):
6161 self .handler = ApplicationServicesHandler (hs )
6262 self .event_source = hs .get_event_sources ()
6363
64- def test_notify_interested_services (self ):
64+ def test_notify_interested_services (self ) -> None :
6565 interested_service = self ._mkservice (is_interested_in_event = True )
6666 services = [
6767 self ._mkservice (is_interested_in_event = False ),
@@ -90,7 +90,7 @@ def test_notify_interested_services(self):
9090 interested_service , events = [event ]
9191 )
9292
93- def test_query_user_exists_unknown_user (self ):
93+ def test_query_user_exists_unknown_user (self ) -> None :
9494 user_id = "@someone:anywhere"
9595 services = [self ._mkservice (is_interested_in_event = True )]
9696 services [0 ].is_interested_in_user .return_value = True
@@ -107,7 +107,7 @@ def test_query_user_exists_unknown_user(self):
107107
108108 self .mock_as_api .query_user .assert_called_once_with (services [0 ], user_id )
109109
110- def test_query_user_exists_known_user (self ):
110+ def test_query_user_exists_known_user (self ) -> None :
111111 user_id = "@someone:anywhere"
112112 services = [self ._mkservice (is_interested_in_event = True )]
113113 services [0 ].is_interested_in_user .return_value = True
@@ -127,7 +127,7 @@ def test_query_user_exists_known_user(self):
127127 "query_user called when it shouldn't have been." ,
128128 )
129129
130- def test_query_room_alias_exists (self ):
130+ def test_query_room_alias_exists (self ) -> None :
131131 room_alias_str = "#foo:bar"
132132 room_alias = Mock ()
133133 room_alias .to_string .return_value = room_alias_str
@@ -157,15 +157,15 @@ def test_query_room_alias_exists(self):
157157 self .assertEqual (result .room_id , room_id )
158158 self .assertEqual (result .servers , servers )
159159
160- def test_get_3pe_protocols_no_appservices (self ):
160+ def test_get_3pe_protocols_no_appservices (self ) -> None :
161161 self .mock_store .get_app_services .return_value = []
162162 response = self .successResultOf (
163163 defer .ensureDeferred (self .handler .get_3pe_protocols ("my-protocol" ))
164164 )
165165 self .mock_as_api .get_3pe_protocol .assert_not_called ()
166166 self .assertEqual (response , {})
167167
168- def test_get_3pe_protocols_no_protocols (self ):
168+ def test_get_3pe_protocols_no_protocols (self ) -> None :
169169 service = self ._mkservice (False , [])
170170 self .mock_store .get_app_services .return_value = [service ]
171171 response = self .successResultOf (
@@ -174,7 +174,7 @@ def test_get_3pe_protocols_no_protocols(self):
174174 self .mock_as_api .get_3pe_protocol .assert_not_called ()
175175 self .assertEqual (response , {})
176176
177- def test_get_3pe_protocols_protocol_no_response (self ):
177+ def test_get_3pe_protocols_protocol_no_response (self ) -> None :
178178 service = self ._mkservice (False , ["my-protocol" ])
179179 self .mock_store .get_app_services .return_value = [service ]
180180 self .mock_as_api .get_3pe_protocol .return_value = make_awaitable (None )
@@ -186,7 +186,7 @@ def test_get_3pe_protocols_protocol_no_response(self):
186186 )
187187 self .assertEqual (response , {})
188188
189- def test_get_3pe_protocols_select_one_protocol (self ):
189+ def test_get_3pe_protocols_select_one_protocol (self ) -> None :
190190 service = self ._mkservice (False , ["my-protocol" ])
191191 self .mock_store .get_app_services .return_value = [service ]
192192 self .mock_as_api .get_3pe_protocol .return_value = make_awaitable (
@@ -202,7 +202,7 @@ def test_get_3pe_protocols_select_one_protocol(self):
202202 response , {"my-protocol" : {"x-protocol-data" : 42 , "instances" : []}}
203203 )
204204
205- def test_get_3pe_protocols_one_protocol (self ):
205+ def test_get_3pe_protocols_one_protocol (self ) -> None :
206206 service = self ._mkservice (False , ["my-protocol" ])
207207 self .mock_store .get_app_services .return_value = [service ]
208208 self .mock_as_api .get_3pe_protocol .return_value = make_awaitable (
@@ -218,7 +218,7 @@ def test_get_3pe_protocols_one_protocol(self):
218218 response , {"my-protocol" : {"x-protocol-data" : 42 , "instances" : []}}
219219 )
220220
221- def test_get_3pe_protocols_multiple_protocol (self ):
221+ def test_get_3pe_protocols_multiple_protocol (self ) -> None :
222222 service_one = self ._mkservice (False , ["my-protocol" ])
223223 service_two = self ._mkservice (False , ["other-protocol" ])
224224 self .mock_store .get_app_services .return_value = [service_one , service_two ]
@@ -237,11 +237,13 @@ def test_get_3pe_protocols_multiple_protocol(self):
237237 },
238238 )
239239
240- def test_get_3pe_protocols_multiple_info (self ):
240+ def test_get_3pe_protocols_multiple_info (self ) -> None :
241241 service_one = self ._mkservice (False , ["my-protocol" ])
242242 service_two = self ._mkservice (False , ["my-protocol" ])
243243
244- async def get_3pe_protocol (service , unusedProtocol ):
244+ async def get_3pe_protocol (
245+ service : ApplicationService , protocol : str
246+ ) -> Optional [JsonDict ]:
245247 if service == service_one :
246248 return {
247249 "x-protocol-data" : 42 ,
@@ -276,7 +278,7 @@ async def get_3pe_protocol(service, unusedProtocol):
276278 },
277279 )
278280
279- def test_notify_interested_services_ephemeral (self ):
281+ def test_notify_interested_services_ephemeral (self ) -> None :
280282 """
281283 Test sending ephemeral events to the appservice handler are scheduled
282284 to be pushed out to interested appservices, and that the stream ID is
@@ -306,7 +308,7 @@ def test_notify_interested_services_ephemeral(self):
306308 580 ,
307309 )
308310
309- def test_notify_interested_services_ephemeral_out_of_order (self ):
311+ def test_notify_interested_services_ephemeral_out_of_order (self ) -> None :
310312 """
311313 Test sending out of order ephemeral events to the appservice handler
312314 are ignored.
@@ -390,7 +392,7 @@ class ApplicationServicesHandlerSendEventsTestCase(unittest.HomeserverTestCase):
390392 receipts .register_servlets ,
391393 ]
392394
393- def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ):
395+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
394396 self .hs = hs
395397 # Mock the ApplicationServiceScheduler's _TransactionController's send method so that
396398 # we can track any outgoing ephemeral events
@@ -417,7 +419,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer):
417419 "exclusive_as_user" , "password" , self .exclusive_as_user_device_id
418420 )
419421
420- def _notify_interested_services (self ):
422+ def _notify_interested_services (self ) -> None :
421423 # This is normally set in `notify_interested_services` but we need to call the
422424 # internal async version so the reactor gets pushed to completion.
423425 self .hs .get_application_service_handler ().current_max += 1
@@ -443,7 +445,7 @@ def _notify_interested_services(self):
443445 )
444446 def test_match_interesting_room_members (
445447 self , interesting_user : str , should_notify : bool
446- ):
448+ ) -> None :
447449 """
448450 Test to make sure that a interesting user (local or remote) in the room is
449451 notified as expected when someone else in the room sends a message.
@@ -512,7 +514,9 @@ def test_match_interesting_room_members(
512514 else :
513515 self .send_mock .assert_not_called ()
514516
515- def test_application_services_receive_events_sent_by_interesting_local_user (self ):
517+ def test_application_services_receive_events_sent_by_interesting_local_user (
518+ self ,
519+ ) -> None :
516520 """
517521 Test to make sure that a messages sent from a local user can be interesting and
518522 picked up by the appservice.
@@ -568,7 +572,7 @@ def test_application_services_receive_events_sent_by_interesting_local_user(self
568572 self .assertEqual (events [0 ]["type" ], "m.room.message" )
569573 self .assertEqual (events [0 ]["sender" ], alice )
570574
571- def test_sending_read_receipt_batches_to_application_services (self ):
575+ def test_sending_read_receipt_batches_to_application_services (self ) -> None :
572576 """Tests that a large batch of read receipts are sent correctly to
573577 interested application services.
574578 """
@@ -644,7 +648,7 @@ def test_sending_read_receipt_batches_to_application_services(self):
644648 @unittest .override_config (
645649 {"experimental_features" : {"msc2409_to_device_messages_enabled" : True }}
646650 )
647- def test_application_services_receive_local_to_device (self ):
651+ def test_application_services_receive_local_to_device (self ) -> None :
648652 """
649653 Test that when a user sends a to-device message to another user
650654 that is an application service's user namespace, the
@@ -722,7 +726,7 @@ def test_application_services_receive_local_to_device(self):
722726 @unittest .override_config (
723727 {"experimental_features" : {"msc2409_to_device_messages_enabled" : True }}
724728 )
725- def test_application_services_receive_bursts_of_to_device (self ):
729+ def test_application_services_receive_bursts_of_to_device (self ) -> None :
726730 """
727731 Test that when a user sends >100 to-device messages at once, any
728732 interested AS's will receive them in separate transactions.
@@ -913,7 +917,7 @@ def test_application_service_receives_device_list_updates(
913917 experimental_feature_enabled : bool ,
914918 as_supports_txn_extensions : bool ,
915919 as_should_receive_device_list_updates : bool ,
916- ):
920+ ) -> None :
917921 """
918922 Tests that an application service receives notice of changed device
919923 lists for a user, when a user changes their device lists.
@@ -1070,7 +1074,7 @@ def _set_up_devices_and_a_room(self) -> str:
10701074 and a room for the users to talk in.
10711075 """
10721076
1073- async def preparation ():
1077+ async def preparation () -> None :
10741078 await self ._add_otks_for_device (self ._sender_user , self ._sender_device , 42 )
10751079 await self ._add_fallback_key_for_device (
10761080 self ._sender_user , self ._sender_device , used = True
0 commit comments