11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
-
15
14
import urllib .parse
16
15
from http import HTTPStatus
17
16
18
17
from parameterized import parameterized
19
18
19
+ from twisted .test .proto_helpers import MemoryReactor
20
+
20
21
import synapse .rest .admin
21
22
from synapse .api .errors import Codes
22
23
from synapse .rest .client import login
24
+ from synapse .server import HomeServer
25
+ from synapse .util import Clock
23
26
24
27
from tests import unittest
25
28
@@ -31,7 +34,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
31
34
login .register_servlets ,
32
35
]
33
36
34
- def prepare (self , reactor , clock , hs ) :
37
+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
35
38
self .handler = hs .get_device_handler ()
36
39
37
40
self .admin_user = self .register_user ("admin" , "pass" , admin = True )
@@ -48,7 +51,7 @@ def prepare(self, reactor, clock, hs):
48
51
)
49
52
50
53
@parameterized .expand (["GET" , "PUT" , "DELETE" ])
51
- def test_no_auth (self , method : str ):
54
+ def test_no_auth (self , method : str ) -> None :
52
55
"""
53
56
Try to get a device of an user without authentication.
54
57
"""
@@ -62,7 +65,7 @@ def test_no_auth(self, method: str):
62
65
self .assertEqual (Codes .MISSING_TOKEN , channel .json_body ["errcode" ])
63
66
64
67
@parameterized .expand (["GET" , "PUT" , "DELETE" ])
65
- def test_requester_is_no_admin (self , method : str ):
68
+ def test_requester_is_no_admin (self , method : str ) -> None :
66
69
"""
67
70
If the user is not a server admin, an error is returned.
68
71
"""
@@ -80,7 +83,7 @@ def test_requester_is_no_admin(self, method: str):
80
83
self .assertEqual (Codes .FORBIDDEN , channel .json_body ["errcode" ])
81
84
82
85
@parameterized .expand (["GET" , "PUT" , "DELETE" ])
83
- def test_user_does_not_exist (self , method : str ):
86
+ def test_user_does_not_exist (self , method : str ) -> None :
84
87
"""
85
88
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
86
89
"""
@@ -99,7 +102,7 @@ def test_user_does_not_exist(self, method: str):
99
102
self .assertEqual (Codes .NOT_FOUND , channel .json_body ["errcode" ])
100
103
101
104
@parameterized .expand (["GET" , "PUT" , "DELETE" ])
102
- def test_user_is_not_local (self , method : str ):
105
+ def test_user_is_not_local (self , method : str ) -> None :
103
106
"""
104
107
Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
105
108
"""
@@ -117,7 +120,7 @@ def test_user_is_not_local(self, method: str):
117
120
self .assertEqual (HTTPStatus .BAD_REQUEST , channel .code , msg = channel .json_body )
118
121
self .assertEqual ("Can only lookup local users" , channel .json_body ["error" ])
119
122
120
- def test_unknown_device (self ):
123
+ def test_unknown_device (self ) -> None :
121
124
"""
122
125
Tests that a lookup for a device that does not exist returns either HTTPStatus.NOT_FOUND or HTTPStatus.OK.
123
126
"""
@@ -151,7 +154,7 @@ def test_unknown_device(self):
151
154
# Delete unknown device returns status HTTPStatus.OK
152
155
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
153
156
154
- def test_update_device_too_long_display_name (self ):
157
+ def test_update_device_too_long_display_name (self ) -> None :
155
158
"""
156
159
Update a device with a display name that is invalid (too long).
157
160
"""
@@ -189,7 +192,7 @@ def test_update_device_too_long_display_name(self):
189
192
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
190
193
self .assertEqual ("new display" , channel .json_body ["display_name" ])
191
194
192
- def test_update_no_display_name (self ):
195
+ def test_update_no_display_name (self ) -> None :
193
196
"""
194
197
Tests that a update for a device without JSON returns a HTTPStatus.OK
195
198
"""
@@ -219,7 +222,7 @@ def test_update_no_display_name(self):
219
222
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
220
223
self .assertEqual ("new display" , channel .json_body ["display_name" ])
221
224
222
- def test_update_display_name (self ):
225
+ def test_update_display_name (self ) -> None :
223
226
"""
224
227
Tests a normal successful update of display name
225
228
"""
@@ -243,7 +246,7 @@ def test_update_display_name(self):
243
246
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
244
247
self .assertEqual ("new displayname" , channel .json_body ["display_name" ])
245
248
246
- def test_get_device (self ):
249
+ def test_get_device (self ) -> None :
247
250
"""
248
251
Tests that a normal lookup for a device is successfully
249
252
"""
@@ -262,7 +265,7 @@ def test_get_device(self):
262
265
self .assertIn ("last_seen_ip" , channel .json_body )
263
266
self .assertIn ("last_seen_ts" , channel .json_body )
264
267
265
- def test_delete_device (self ):
268
+ def test_delete_device (self ) -> None :
266
269
"""
267
270
Tests that a remove of a device is successfully
268
271
"""
@@ -292,7 +295,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
292
295
login .register_servlets ,
293
296
]
294
297
295
- def prepare (self , reactor , clock , hs ) :
298
+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
296
299
self .admin_user = self .register_user ("admin" , "pass" , admin = True )
297
300
self .admin_user_tok = self .login ("admin" , "pass" )
298
301
@@ -302,7 +305,7 @@ def prepare(self, reactor, clock, hs):
302
305
self .other_user
303
306
)
304
307
305
- def test_no_auth (self ):
308
+ def test_no_auth (self ) -> None :
306
309
"""
307
310
Try to list devices of an user without authentication.
308
311
"""
@@ -315,7 +318,7 @@ def test_no_auth(self):
315
318
)
316
319
self .assertEqual (Codes .MISSING_TOKEN , channel .json_body ["errcode" ])
317
320
318
- def test_requester_is_no_admin (self ):
321
+ def test_requester_is_no_admin (self ) -> None :
319
322
"""
320
323
If the user is not a server admin, an error is returned.
321
324
"""
@@ -334,7 +337,7 @@ def test_requester_is_no_admin(self):
334
337
)
335
338
self .assertEqual (Codes .FORBIDDEN , channel .json_body ["errcode" ])
336
339
337
- def test_user_does_not_exist (self ):
340
+ def test_user_does_not_exist (self ) -> None :
338
341
"""
339
342
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
340
343
"""
@@ -348,7 +351,7 @@ def test_user_does_not_exist(self):
348
351
self .assertEqual (HTTPStatus .NOT_FOUND , channel .code , msg = channel .json_body )
349
352
self .assertEqual (Codes .NOT_FOUND , channel .json_body ["errcode" ])
350
353
351
- def test_user_is_not_local (self ):
354
+ def test_user_is_not_local (self ) -> None :
352
355
"""
353
356
Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
354
357
"""
@@ -363,7 +366,7 @@ def test_user_is_not_local(self):
363
366
self .assertEqual (HTTPStatus .BAD_REQUEST , channel .code , msg = channel .json_body )
364
367
self .assertEqual ("Can only lookup local users" , channel .json_body ["error" ])
365
368
366
- def test_user_has_no_devices (self ):
369
+ def test_user_has_no_devices (self ) -> None :
367
370
"""
368
371
Tests that a normal lookup for devices is successfully
369
372
if user has no devices
@@ -380,7 +383,7 @@ def test_user_has_no_devices(self):
380
383
self .assertEqual (0 , channel .json_body ["total" ])
381
384
self .assertEqual (0 , len (channel .json_body ["devices" ]))
382
385
383
- def test_get_devices (self ):
386
+ def test_get_devices (self ) -> None :
384
387
"""
385
388
Tests that a normal lookup for devices is successfully
386
389
"""
@@ -416,7 +419,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
416
419
login .register_servlets ,
417
420
]
418
421
419
- def prepare (self , reactor , clock , hs ) :
422
+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
420
423
self .handler = hs .get_device_handler ()
421
424
422
425
self .admin_user = self .register_user ("admin" , "pass" , admin = True )
@@ -428,7 +431,7 @@ def prepare(self, reactor, clock, hs):
428
431
self .other_user
429
432
)
430
433
431
- def test_no_auth (self ):
434
+ def test_no_auth (self ) -> None :
432
435
"""
433
436
Try to delete devices of an user without authentication.
434
437
"""
@@ -441,7 +444,7 @@ def test_no_auth(self):
441
444
)
442
445
self .assertEqual (Codes .MISSING_TOKEN , channel .json_body ["errcode" ])
443
446
444
- def test_requester_is_no_admin (self ):
447
+ def test_requester_is_no_admin (self ) -> None :
445
448
"""
446
449
If the user is not a server admin, an error is returned.
447
450
"""
@@ -460,7 +463,7 @@ def test_requester_is_no_admin(self):
460
463
)
461
464
self .assertEqual (Codes .FORBIDDEN , channel .json_body ["errcode" ])
462
465
463
- def test_user_does_not_exist (self ):
466
+ def test_user_does_not_exist (self ) -> None :
464
467
"""
465
468
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
466
469
"""
@@ -474,7 +477,7 @@ def test_user_does_not_exist(self):
474
477
self .assertEqual (HTTPStatus .NOT_FOUND , channel .code , msg = channel .json_body )
475
478
self .assertEqual (Codes .NOT_FOUND , channel .json_body ["errcode" ])
476
479
477
- def test_user_is_not_local (self ):
480
+ def test_user_is_not_local (self ) -> None :
478
481
"""
479
482
Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
480
483
"""
@@ -489,7 +492,7 @@ def test_user_is_not_local(self):
489
492
self .assertEqual (HTTPStatus .BAD_REQUEST , channel .code , msg = channel .json_body )
490
493
self .assertEqual ("Can only lookup local users" , channel .json_body ["error" ])
491
494
492
- def test_unknown_devices (self ):
495
+ def test_unknown_devices (self ) -> None :
493
496
"""
494
497
Tests that a remove of a device that does not exist returns HTTPStatus.OK.
495
498
"""
@@ -503,7 +506,7 @@ def test_unknown_devices(self):
503
506
# Delete unknown devices returns status HTTPStatus.OK
504
507
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
505
508
506
- def test_delete_devices (self ):
509
+ def test_delete_devices (self ) -> None :
507
510
"""
508
511
Tests that a remove of devices is successfully
509
512
"""
0 commit comments