1313# limitations under the License.
1414import email .message
1515import os
16- from typing import Dict , List , Sequence , Tuple
16+ from typing import Any , Dict , List , Sequence , Tuple
1717
1818import attr
1919import pkg_resources
2020
2121from twisted .internet .defer import Deferred
22+ from twisted .test .proto_helpers import MemoryReactor
2223
2324import synapse .rest .admin
2425from synapse .api .errors import Codes , SynapseError
2526from synapse .rest .client import login , room
27+ from synapse .server import HomeServer
28+ from synapse .util import Clock
2629
2730from tests .unittest import HomeserverTestCase
2831
2932
30- @attr .s
33+ @attr .s ( auto_attribs = True )
3134class _User :
3235 "Helper wrapper for user ID and access token"
33- id = attr . ib ()
34- token = attr . ib ()
36+ id : str
37+ token : str
3538
3639
3740class EmailPusherTests (HomeserverTestCase ):
@@ -41,10 +44,9 @@ class EmailPusherTests(HomeserverTestCase):
4144 room .register_servlets ,
4245 login .register_servlets ,
4346 ]
44- user_id = True
4547 hijack_auth = False
4648
47- def make_homeserver (self , reactor , clock ) :
49+ def make_homeserver (self , reactor : MemoryReactor , clock : Clock ) -> HomeServer :
4850
4951 config = self .default_config ()
5052 config ["email" ] = {
@@ -72,17 +74,17 @@ def make_homeserver(self, reactor, clock):
7274 # List[Tuple[Deferred, args, kwargs]]
7375 self .email_attempts : List [Tuple [Deferred , Sequence , Dict ]] = []
7476
75- def sendmail (* args , ** kwargs ) :
77+ def sendmail (* args : Any , ** kwargs : Any ) -> Deferred :
7678 # This mocks out synapse.reactor.send_email._sendmail.
77- d = Deferred ()
79+ d : Deferred = Deferred ()
7880 self .email_attempts .append ((d , args , kwargs ))
7981 return d
8082
81- hs .get_send_email_handler ()._sendmail = sendmail
83+ hs .get_send_email_handler ()._sendmail = sendmail # type: ignore[assignment]
8284
8385 return hs
8486
85- def prepare (self , reactor , clock , hs ) :
87+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
8688 # Register the user who gets notified
8789 self .user_id = self .register_user ("user" , "pass" )
8890 self .access_token = self .login ("user" , "pass" )
@@ -129,7 +131,7 @@ def prepare(self, reactor, clock, hs):
129131 self .auth_handler = hs .get_auth_handler ()
130132 self .store = hs .get_datastores ().main
131133
132- def test_need_validated_email (self ):
134+ def test_need_validated_email (self ) -> None :
133135 """Test that we can only add an email pusher if the user has validated
134136 their email.
135137 """
@@ -151,7 +153,7 @@ def test_need_validated_email(self):
151153 self .assertEqual (400 , cm .exception .code )
152154 self .assertEqual (Codes .THREEPID_NOT_FOUND , cm .exception .errcode )
153155
154- def test_simple_sends_email (self ):
156+ def test_simple_sends_email (self ) -> None :
155157 # Create a simple room with two users
156158 room = self .helper .create_room_as (self .user_id , tok = self .access_token )
157159 self .helper .invite (
@@ -171,7 +173,7 @@ def test_simple_sends_email(self):
171173
172174 self ._check_for_mail ()
173175
174- def test_invite_sends_email (self ):
176+ def test_invite_sends_email (self ) -> None :
175177 # Create a room and invite the user to it
176178 room = self .helper .create_room_as (self .others [0 ].id , tok = self .others [0 ].token )
177179 self .helper .invite (
@@ -184,7 +186,7 @@ def test_invite_sends_email(self):
184186 # We should get emailed about the invite
185187 self ._check_for_mail ()
186188
187- def test_invite_to_empty_room_sends_email (self ):
189+ def test_invite_to_empty_room_sends_email (self ) -> None :
188190 # Create a room and invite the user to it
189191 room = self .helper .create_room_as (self .others [0 ].id , tok = self .others [0 ].token )
190192 self .helper .invite (
@@ -200,7 +202,7 @@ def test_invite_to_empty_room_sends_email(self):
200202 # We should get emailed about the invite
201203 self ._check_for_mail ()
202204
203- def test_multiple_members_email (self ):
205+ def test_multiple_members_email (self ) -> None :
204206 # We want to test multiple notifications, so we pause processing of push
205207 # while we send messages.
206208 self .pusher ._pause_processing ()
@@ -227,7 +229,7 @@ def test_multiple_members_email(self):
227229 # We should get emailed about those messages
228230 self ._check_for_mail ()
229231
230- def test_multiple_rooms (self ):
232+ def test_multiple_rooms (self ) -> None :
231233 # We want to test multiple notifications from multiple rooms, so we pause
232234 # processing of push while we send messages.
233235 self .pusher ._pause_processing ()
@@ -257,7 +259,7 @@ def test_multiple_rooms(self):
257259 # We should get emailed about those messages
258260 self ._check_for_mail ()
259261
260- def test_room_notifications_include_avatar (self ):
262+ def test_room_notifications_include_avatar (self ) -> None :
261263 # Create a room and set its avatar.
262264 room = self .helper .create_room_as (self .user_id , tok = self .access_token )
263265 self .helper .send_state (
@@ -290,7 +292,7 @@ def test_room_notifications_include_avatar(self):
290292 )
291293 self .assertIn ("_matrix/media/v1/thumbnail/DUMMY_MEDIA_ID" , html )
292294
293- def test_empty_room (self ):
295+ def test_empty_room (self ) -> None :
294296 """All users leaving a room shouldn't cause the pusher to break."""
295297 # Create a simple room with two users
296298 room = self .helper .create_room_as (self .user_id , tok = self .access_token )
@@ -309,7 +311,7 @@ def test_empty_room(self):
309311 # We should get emailed about that message
310312 self ._check_for_mail ()
311313
312- def test_empty_room_multiple_messages (self ):
314+ def test_empty_room_multiple_messages (self ) -> None :
313315 """All users leaving a room shouldn't cause the pusher to break."""
314316 # Create a simple room with two users
315317 room = self .helper .create_room_as (self .user_id , tok = self .access_token )
@@ -329,7 +331,7 @@ def test_empty_room_multiple_messages(self):
329331 # We should get emailed about that message
330332 self ._check_for_mail ()
331333
332- def test_encrypted_message (self ):
334+ def test_encrypted_message (self ) -> None :
333335 room = self .helper .create_room_as (self .user_id , tok = self .access_token )
334336 self .helper .invite (
335337 room = room , src = self .user_id , tok = self .access_token , targ = self .others [0 ].id
@@ -342,7 +344,7 @@ def test_encrypted_message(self):
342344 # We should get emailed about that message
343345 self ._check_for_mail ()
344346
345- def test_no_email_sent_after_removed (self ):
347+ def test_no_email_sent_after_removed (self ) -> None :
346348 # Create a simple room with two users
347349 room = self .helper .create_room_as (self .user_id , tok = self .access_token )
348350 self .helper .invite (
@@ -379,7 +381,7 @@ def test_no_email_sent_after_removed(self):
379381 pushers = list (pushers )
380382 self .assertEqual (len (pushers ), 0 )
381383
382- def test_remove_unlinked_pushers_background_job (self ):
384+ def test_remove_unlinked_pushers_background_job (self ) -> None :
383385 """Checks that all existing pushers associated with unlinked email addresses are removed
384386 upon running the remove_deleted_email_pushers background update.
385387 """
0 commit comments