Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 952efd0

Browse files
authored
Add type hints to tests/rest/client (#12094)
* Add type hints to `tests/rest/client` * update `mypy.ini` * newsfile * add `test_register.py`
1 parent 7754af2 commit 952efd0

File tree

5 files changed

+72
-64
lines changed

5 files changed

+72
-64
lines changed

changelog.d/12094.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add type hints to `tests/rest/client`.

mypy.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ exclude = (?x)
7575
|tests/push/test_presentable_names.py
7676
|tests/push/test_push_rule_evaluator.py
7777
|tests/rest/client/test_account.py
78-
|tests/rest/client/test_events.py
7978
|tests/rest/client/test_filter.py
80-
|tests/rest/client/test_groups.py
81-
|tests/rest/client/test_register.py
8279
|tests/rest/client/test_report_event.py
8380
|tests/rest/client/test_rooms.py
8481
|tests/rest/client/test_third_party_rules.py

tests/rest/client/test_events.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616

1717
from unittest.mock import Mock
1818

19+
from twisted.test.proto_helpers import MemoryReactor
20+
1921
import synapse.rest.admin
2022
from synapse.rest.client import events, login, room
23+
from synapse.server import HomeServer
24+
from synapse.util import Clock
2125

2226
from tests import unittest
2327

@@ -32,7 +36,7 @@ class EventStreamPermissionsTestCase(unittest.HomeserverTestCase):
3236
login.register_servlets,
3337
]
3438

35-
def make_homeserver(self, reactor, clock):
39+
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
3640

3741
config = self.default_config()
3842
config["enable_registration_captcha"] = False
@@ -41,11 +45,11 @@ def make_homeserver(self, reactor, clock):
4145

4246
hs = self.setup_test_homeserver(config=config)
4347

44-
hs.get_federation_handler = Mock()
48+
hs.get_federation_handler = Mock() # type: ignore[assignment]
4549

4650
return hs
4751

48-
def prepare(self, reactor, clock, hs):
52+
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
4953

5054
# register an account
5155
self.user_id = self.register_user("sid1", "pass")
@@ -55,7 +59,7 @@ def prepare(self, reactor, clock, hs):
5559
self.other_user = self.register_user("other2", "pass")
5660
self.other_token = self.login(self.other_user, "pass")
5761

58-
def test_stream_basic_permissions(self):
62+
def test_stream_basic_permissions(self) -> None:
5963
# invalid token, expect 401
6064
# note: this is in violation of the original v1 spec, which expected
6165
# 403. However, since the v1 spec no longer exists and the v1
@@ -76,7 +80,7 @@ def test_stream_basic_permissions(self):
7680
self.assertTrue("start" in channel.json_body)
7781
self.assertTrue("end" in channel.json_body)
7882

79-
def test_stream_room_permissions(self):
83+
def test_stream_room_permissions(self) -> None:
8084
room_id = self.helper.create_room_as(self.other_user, tok=self.other_token)
8185
self.helper.send(room_id, tok=self.other_token)
8286

@@ -111,7 +115,7 @@ def test_stream_room_permissions(self):
111115

112116
# left to room (expect no content for room)
113117

114-
def TODO_test_stream_items(self):
118+
def TODO_test_stream_items(self) -> None:
115119
# new user, no content
116120

117121
# join room, expect 1 item (join)
@@ -136,15 +140,15 @@ class GetEventsTestCase(unittest.HomeserverTestCase):
136140
login.register_servlets,
137141
]
138142

139-
def prepare(self, hs, reactor, clock):
143+
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
140144

141145
# register an account
142146
self.user_id = self.register_user("sid1", "pass")
143147
self.token = self.login(self.user_id, "pass")
144148

145149
self.room_id = self.helper.create_room_as(self.user_id, tok=self.token)
146150

147-
def test_get_event_via_events(self):
151+
def test_get_event_via_events(self) -> None:
148152
resp = self.helper.send(self.room_id, tok=self.token)
149153
event_id = resp["event_id"]
150154

tests/rest/client/test_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GroupsTestCase(unittest.HomeserverTestCase):
2525
servlets = [room.register_servlets, groups.register_servlets]
2626

2727
@override_config({"enable_group_creation": True})
28-
def test_rooms_limited_by_visibility(self):
28+
def test_rooms_limited_by_visibility(self) -> None:
2929
group_id = "+spqr:test"
3030

3131
# Alice creates a group

0 commit comments

Comments
 (0)