1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14-
1514import urllib .parse
1615from http import HTTPStatus
1716
1817from parameterized import parameterized
1918
19+ from twisted .test .proto_helpers import MemoryReactor
20+
2021import synapse .rest .admin
2122from synapse .api .errors import Codes
2223from synapse .rest .client import login
24+ from synapse .server import HomeServer
25+ from synapse .util import Clock
2326
2427from tests import unittest
2528
@@ -31,7 +34,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
3134 login .register_servlets ,
3235 ]
3336
34- def prepare (self , reactor , clock , hs ) :
37+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
3538 self .handler = hs .get_device_handler ()
3639
3740 self .admin_user = self .register_user ("admin" , "pass" , admin = True )
@@ -48,7 +51,7 @@ def prepare(self, reactor, clock, hs):
4851 )
4952
5053 @parameterized .expand (["GET" , "PUT" , "DELETE" ])
51- def test_no_auth (self , method : str ):
54+ def test_no_auth (self , method : str ) -> None :
5255 """
5356 Try to get a device of an user without authentication.
5457 """
@@ -62,7 +65,7 @@ def test_no_auth(self, method: str):
6265 self .assertEqual (Codes .MISSING_TOKEN , channel .json_body ["errcode" ])
6366
6467 @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 :
6669 """
6770 If the user is not a server admin, an error is returned.
6871 """
@@ -80,7 +83,7 @@ def test_requester_is_no_admin(self, method: str):
8083 self .assertEqual (Codes .FORBIDDEN , channel .json_body ["errcode" ])
8184
8285 @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 :
8487 """
8588 Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
8689 """
@@ -99,7 +102,7 @@ def test_user_does_not_exist(self, method: str):
99102 self .assertEqual (Codes .NOT_FOUND , channel .json_body ["errcode" ])
100103
101104 @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 :
103106 """
104107 Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
105108 """
@@ -117,7 +120,7 @@ def test_user_is_not_local(self, method: str):
117120 self .assertEqual (HTTPStatus .BAD_REQUEST , channel .code , msg = channel .json_body )
118121 self .assertEqual ("Can only lookup local users" , channel .json_body ["error" ])
119122
120- def test_unknown_device (self ):
123+ def test_unknown_device (self ) -> None :
121124 """
122125 Tests that a lookup for a device that does not exist returns either HTTPStatus.NOT_FOUND or HTTPStatus.OK.
123126 """
@@ -151,7 +154,7 @@ def test_unknown_device(self):
151154 # Delete unknown device returns status HTTPStatus.OK
152155 self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
153156
154- def test_update_device_too_long_display_name (self ):
157+ def test_update_device_too_long_display_name (self ) -> None :
155158 """
156159 Update a device with a display name that is invalid (too long).
157160 """
@@ -189,7 +192,7 @@ def test_update_device_too_long_display_name(self):
189192 self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
190193 self .assertEqual ("new display" , channel .json_body ["display_name" ])
191194
192- def test_update_no_display_name (self ):
195+ def test_update_no_display_name (self ) -> None :
193196 """
194197 Tests that a update for a device without JSON returns a HTTPStatus.OK
195198 """
@@ -219,7 +222,7 @@ def test_update_no_display_name(self):
219222 self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
220223 self .assertEqual ("new display" , channel .json_body ["display_name" ])
221224
222- def test_update_display_name (self ):
225+ def test_update_display_name (self ) -> None :
223226 """
224227 Tests a normal successful update of display name
225228 """
@@ -243,7 +246,7 @@ def test_update_display_name(self):
243246 self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
244247 self .assertEqual ("new displayname" , channel .json_body ["display_name" ])
245248
246- def test_get_device (self ):
249+ def test_get_device (self ) -> None :
247250 """
248251 Tests that a normal lookup for a device is successfully
249252 """
@@ -262,7 +265,7 @@ def test_get_device(self):
262265 self .assertIn ("last_seen_ip" , channel .json_body )
263266 self .assertIn ("last_seen_ts" , channel .json_body )
264267
265- def test_delete_device (self ):
268+ def test_delete_device (self ) -> None :
266269 """
267270 Tests that a remove of a device is successfully
268271 """
@@ -292,7 +295,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
292295 login .register_servlets ,
293296 ]
294297
295- def prepare (self , reactor , clock , hs ) :
298+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
296299 self .admin_user = self .register_user ("admin" , "pass" , admin = True )
297300 self .admin_user_tok = self .login ("admin" , "pass" )
298301
@@ -302,7 +305,7 @@ def prepare(self, reactor, clock, hs):
302305 self .other_user
303306 )
304307
305- def test_no_auth (self ):
308+ def test_no_auth (self ) -> None :
306309 """
307310 Try to list devices of an user without authentication.
308311 """
@@ -315,7 +318,7 @@ def test_no_auth(self):
315318 )
316319 self .assertEqual (Codes .MISSING_TOKEN , channel .json_body ["errcode" ])
317320
318- def test_requester_is_no_admin (self ):
321+ def test_requester_is_no_admin (self ) -> None :
319322 """
320323 If the user is not a server admin, an error is returned.
321324 """
@@ -334,7 +337,7 @@ def test_requester_is_no_admin(self):
334337 )
335338 self .assertEqual (Codes .FORBIDDEN , channel .json_body ["errcode" ])
336339
337- def test_user_does_not_exist (self ):
340+ def test_user_does_not_exist (self ) -> None :
338341 """
339342 Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
340343 """
@@ -348,7 +351,7 @@ def test_user_does_not_exist(self):
348351 self .assertEqual (HTTPStatus .NOT_FOUND , channel .code , msg = channel .json_body )
349352 self .assertEqual (Codes .NOT_FOUND , channel .json_body ["errcode" ])
350353
351- def test_user_is_not_local (self ):
354+ def test_user_is_not_local (self ) -> None :
352355 """
353356 Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
354357 """
@@ -363,7 +366,7 @@ def test_user_is_not_local(self):
363366 self .assertEqual (HTTPStatus .BAD_REQUEST , channel .code , msg = channel .json_body )
364367 self .assertEqual ("Can only lookup local users" , channel .json_body ["error" ])
365368
366- def test_user_has_no_devices (self ):
369+ def test_user_has_no_devices (self ) -> None :
367370 """
368371 Tests that a normal lookup for devices is successfully
369372 if user has no devices
@@ -380,7 +383,7 @@ def test_user_has_no_devices(self):
380383 self .assertEqual (0 , channel .json_body ["total" ])
381384 self .assertEqual (0 , len (channel .json_body ["devices" ]))
382385
383- def test_get_devices (self ):
386+ def test_get_devices (self ) -> None :
384387 """
385388 Tests that a normal lookup for devices is successfully
386389 """
@@ -416,7 +419,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
416419 login .register_servlets ,
417420 ]
418421
419- def prepare (self , reactor , clock , hs ) :
422+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
420423 self .handler = hs .get_device_handler ()
421424
422425 self .admin_user = self .register_user ("admin" , "pass" , admin = True )
@@ -428,7 +431,7 @@ def prepare(self, reactor, clock, hs):
428431 self .other_user
429432 )
430433
431- def test_no_auth (self ):
434+ def test_no_auth (self ) -> None :
432435 """
433436 Try to delete devices of an user without authentication.
434437 """
@@ -441,7 +444,7 @@ def test_no_auth(self):
441444 )
442445 self .assertEqual (Codes .MISSING_TOKEN , channel .json_body ["errcode" ])
443446
444- def test_requester_is_no_admin (self ):
447+ def test_requester_is_no_admin (self ) -> None :
445448 """
446449 If the user is not a server admin, an error is returned.
447450 """
@@ -460,7 +463,7 @@ def test_requester_is_no_admin(self):
460463 )
461464 self .assertEqual (Codes .FORBIDDEN , channel .json_body ["errcode" ])
462465
463- def test_user_does_not_exist (self ):
466+ def test_user_does_not_exist (self ) -> None :
464467 """
465468 Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
466469 """
@@ -474,7 +477,7 @@ def test_user_does_not_exist(self):
474477 self .assertEqual (HTTPStatus .NOT_FOUND , channel .code , msg = channel .json_body )
475478 self .assertEqual (Codes .NOT_FOUND , channel .json_body ["errcode" ])
476479
477- def test_user_is_not_local (self ):
480+ def test_user_is_not_local (self ) -> None :
478481 """
479482 Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
480483 """
@@ -489,7 +492,7 @@ def test_user_is_not_local(self):
489492 self .assertEqual (HTTPStatus .BAD_REQUEST , channel .code , msg = channel .json_body )
490493 self .assertEqual ("Can only lookup local users" , channel .json_body ["error" ])
491494
492- def test_unknown_devices (self ):
495+ def test_unknown_devices (self ) -> None :
493496 """
494497 Tests that a remove of a device that does not exist returns HTTPStatus.OK.
495498 """
@@ -503,7 +506,7 @@ def test_unknown_devices(self):
503506 # Delete unknown devices returns status HTTPStatus.OK
504507 self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
505508
506- def test_delete_devices (self ):
509+ def test_delete_devices (self ) -> None :
507510 """
508511 Tests that a remove of devices is successfully
509512 """
0 commit comments