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

Add type hints to tests/rest/client #12094

Merged
merged 5 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12094.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add type hints to `tests/rest/client`.
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ exclude = (?x)
|tests/push/test_presentable_names.py
|tests/push/test_push_rule_evaluator.py
|tests/rest/client/test_account.py
|tests/rest/client/test_events.py
|tests/rest/client/test_filter.py
|tests/rest/client/test_groups.py
|tests/rest/client/test_register.py
|tests/rest/client/test_report_event.py
|tests/rest/client/test_rooms.py
|tests/rest/client/test_third_party_rules.py
Expand Down
20 changes: 12 additions & 8 deletions tests/rest/client/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

from unittest.mock import Mock

from twisted.test.proto_helpers import MemoryReactor

import synapse.rest.admin
from synapse.rest.client import events, login, room
from synapse.server import HomeServer
from synapse.util import Clock

from tests import unittest

Expand All @@ -32,7 +36,7 @@ class EventStreamPermissionsTestCase(unittest.HomeserverTestCase):
login.register_servlets,
]

def make_homeserver(self, reactor, clock):
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:

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

hs = self.setup_test_homeserver(config=config)

hs.get_federation_handler = Mock()
hs.get_federation_handler = Mock() # type: ignore[assignment]

return hs

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

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

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

def test_stream_room_permissions(self):
def test_stream_room_permissions(self) -> None:
room_id = self.helper.create_room_as(self.other_user, tok=self.other_token)
self.helper.send(room_id, tok=self.other_token)

Expand Down Expand Up @@ -111,7 +115,7 @@ def test_stream_room_permissions(self):

# left to room (expect no content for room)

def TODO_test_stream_items(self):
def TODO_test_stream_items(self) -> None:
# new user, no content

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

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

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

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

def test_get_event_via_events(self):
def test_get_event_via_events(self) -> None:
resp = self.helper.send(self.room_id, tok=self.token)
event_id = resp["event_id"]

Expand Down
2 changes: 1 addition & 1 deletion tests/rest/client/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GroupsTestCase(unittest.HomeserverTestCase):
servlets = [room.register_servlets, groups.register_servlets]

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

# Alice creates a group
Expand Down
Loading