13
13
# limitations under the License.
14
14
import email .message
15
15
import os
16
- from typing import Dict , List , Sequence , Tuple
16
+ from typing import Any , Dict , List , Sequence , Tuple
17
17
18
18
import attr
19
19
import pkg_resources
20
20
21
21
from twisted .internet .defer import Deferred
22
+ from twisted .test .proto_helpers import MemoryReactor
22
23
23
24
import synapse .rest .admin
24
25
from synapse .api .errors import Codes , SynapseError
25
26
from synapse .rest .client import login , room
27
+ from synapse .server import HomeServer
28
+ from synapse .util import Clock
26
29
27
30
from tests .unittest import HomeserverTestCase
28
31
29
32
30
- @attr .s
33
+ @attr .s ( auto_attribs = True )
31
34
class _User :
32
35
"Helper wrapper for user ID and access token"
33
- id = attr . ib ()
34
- token = attr . ib ()
36
+ id : str
37
+ token : str
35
38
36
39
37
40
class EmailPusherTests (HomeserverTestCase ):
@@ -41,10 +44,9 @@ class EmailPusherTests(HomeserverTestCase):
41
44
room .register_servlets ,
42
45
login .register_servlets ,
43
46
]
44
- user_id = True
45
47
hijack_auth = False
46
48
47
- def make_homeserver (self , reactor , clock ) :
49
+ def make_homeserver (self , reactor : MemoryReactor , clock : Clock ) -> HomeServer :
48
50
49
51
config = self .default_config ()
50
52
config ["email" ] = {
@@ -72,17 +74,17 @@ def make_homeserver(self, reactor, clock):
72
74
# List[Tuple[Deferred, args, kwargs]]
73
75
self .email_attempts : List [Tuple [Deferred , Sequence , Dict ]] = []
74
76
75
- def sendmail (* args , ** kwargs ) :
77
+ def sendmail (* args : Any , ** kwargs : Any ) -> Deferred :
76
78
# This mocks out synapse.reactor.send_email._sendmail.
77
- d = Deferred ()
79
+ d : Deferred = Deferred ()
78
80
self .email_attempts .append ((d , args , kwargs ))
79
81
return d
80
82
81
- hs .get_send_email_handler ()._sendmail = sendmail
83
+ hs .get_send_email_handler ()._sendmail = sendmail # type: ignore[assignment]
82
84
83
85
return hs
84
86
85
- def prepare (self , reactor , clock , hs ) :
87
+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
86
88
# Register the user who gets notified
87
89
self .user_id = self .register_user ("user" , "pass" )
88
90
self .access_token = self .login ("user" , "pass" )
@@ -129,7 +131,7 @@ def prepare(self, reactor, clock, hs):
129
131
self .auth_handler = hs .get_auth_handler ()
130
132
self .store = hs .get_datastores ().main
131
133
132
- def test_need_validated_email (self ):
134
+ def test_need_validated_email (self ) -> None :
133
135
"""Test that we can only add an email pusher if the user has validated
134
136
their email.
135
137
"""
@@ -151,7 +153,7 @@ def test_need_validated_email(self):
151
153
self .assertEqual (400 , cm .exception .code )
152
154
self .assertEqual (Codes .THREEPID_NOT_FOUND , cm .exception .errcode )
153
155
154
- def test_simple_sends_email (self ):
156
+ def test_simple_sends_email (self ) -> None :
155
157
# Create a simple room with two users
156
158
room = self .helper .create_room_as (self .user_id , tok = self .access_token )
157
159
self .helper .invite (
@@ -171,7 +173,7 @@ def test_simple_sends_email(self):
171
173
172
174
self ._check_for_mail ()
173
175
174
- def test_invite_sends_email (self ):
176
+ def test_invite_sends_email (self ) -> None :
175
177
# Create a room and invite the user to it
176
178
room = self .helper .create_room_as (self .others [0 ].id , tok = self .others [0 ].token )
177
179
self .helper .invite (
@@ -184,7 +186,7 @@ def test_invite_sends_email(self):
184
186
# We should get emailed about the invite
185
187
self ._check_for_mail ()
186
188
187
- def test_invite_to_empty_room_sends_email (self ):
189
+ def test_invite_to_empty_room_sends_email (self ) -> None :
188
190
# Create a room and invite the user to it
189
191
room = self .helper .create_room_as (self .others [0 ].id , tok = self .others [0 ].token )
190
192
self .helper .invite (
@@ -200,7 +202,7 @@ def test_invite_to_empty_room_sends_email(self):
200
202
# We should get emailed about the invite
201
203
self ._check_for_mail ()
202
204
203
- def test_multiple_members_email (self ):
205
+ def test_multiple_members_email (self ) -> None :
204
206
# We want to test multiple notifications, so we pause processing of push
205
207
# while we send messages.
206
208
self .pusher ._pause_processing ()
@@ -227,7 +229,7 @@ def test_multiple_members_email(self):
227
229
# We should get emailed about those messages
228
230
self ._check_for_mail ()
229
231
230
- def test_multiple_rooms (self ):
232
+ def test_multiple_rooms (self ) -> None :
231
233
# We want to test multiple notifications from multiple rooms, so we pause
232
234
# processing of push while we send messages.
233
235
self .pusher ._pause_processing ()
@@ -257,7 +259,7 @@ def test_multiple_rooms(self):
257
259
# We should get emailed about those messages
258
260
self ._check_for_mail ()
259
261
260
- def test_room_notifications_include_avatar (self ):
262
+ def test_room_notifications_include_avatar (self ) -> None :
261
263
# Create a room and set its avatar.
262
264
room = self .helper .create_room_as (self .user_id , tok = self .access_token )
263
265
self .helper .send_state (
@@ -290,7 +292,7 @@ def test_room_notifications_include_avatar(self):
290
292
)
291
293
self .assertIn ("_matrix/media/v1/thumbnail/DUMMY_MEDIA_ID" , html )
292
294
293
- def test_empty_room (self ):
295
+ def test_empty_room (self ) -> None :
294
296
"""All users leaving a room shouldn't cause the pusher to break."""
295
297
# Create a simple room with two users
296
298
room = self .helper .create_room_as (self .user_id , tok = self .access_token )
@@ -309,7 +311,7 @@ def test_empty_room(self):
309
311
# We should get emailed about that message
310
312
self ._check_for_mail ()
311
313
312
- def test_empty_room_multiple_messages (self ):
314
+ def test_empty_room_multiple_messages (self ) -> None :
313
315
"""All users leaving a room shouldn't cause the pusher to break."""
314
316
# Create a simple room with two users
315
317
room = self .helper .create_room_as (self .user_id , tok = self .access_token )
@@ -329,7 +331,7 @@ def test_empty_room_multiple_messages(self):
329
331
# We should get emailed about that message
330
332
self ._check_for_mail ()
331
333
332
- def test_encrypted_message (self ):
334
+ def test_encrypted_message (self ) -> None :
333
335
room = self .helper .create_room_as (self .user_id , tok = self .access_token )
334
336
self .helper .invite (
335
337
room = room , src = self .user_id , tok = self .access_token , targ = self .others [0 ].id
@@ -342,7 +344,7 @@ def test_encrypted_message(self):
342
344
# We should get emailed about that message
343
345
self ._check_for_mail ()
344
346
345
- def test_no_email_sent_after_removed (self ):
347
+ def test_no_email_sent_after_removed (self ) -> None :
346
348
# Create a simple room with two users
347
349
room = self .helper .create_room_as (self .user_id , tok = self .access_token )
348
350
self .helper .invite (
@@ -379,7 +381,7 @@ def test_no_email_sent_after_removed(self):
379
381
pushers = list (pushers )
380
382
self .assertEqual (len (pushers ), 0 )
381
383
382
- def test_remove_unlinked_pushers_background_job (self ):
384
+ def test_remove_unlinked_pushers_background_job (self ) -> None :
383
385
"""Checks that all existing pushers associated with unlinked email addresses are removed
384
386
upon running the remove_deleted_email_pushers background update.
385
387
"""
0 commit comments