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

Proper types for tests.test_terms_auth #15007

Merged
merged 2 commits into from
Feb 7, 2023
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/15007.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type hints.
4 changes: 3 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ exclude = (?x)
|tests/module_api/test_api.py
|tests/rest/media/v1/test_media_storage.py
|tests/server.py
|tests/test_terms_auth.py
)$

[mypy-synapse.federation.transport.client]
Expand Down Expand Up @@ -119,6 +118,9 @@ disallow_untyped_defs = True
[mypy-tests.test_state]
disallow_untyped_defs = True

[mypy-tests.test_terms_auth]
disallow_untyped_defs = True

[mypy-tests.types.*]
disallow_untyped_defs = True

Expand Down
19 changes: 13 additions & 6 deletions tests/test_terms_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

from unittest.mock import Mock

from twisted.test.proto_helpers import MemoryReactorClock
from twisted.internet.interfaces import IReactorTime
from twisted.test.proto_helpers import MemoryReactor, MemoryReactorClock

from synapse.rest.client.register import register_servlets
from synapse.server import HomeServer
from synapse.types import JsonDict
from synapse.util import Clock

from tests import unittest
Expand All @@ -25,7 +28,7 @@
class TermsTestCase(unittest.HomeserverTestCase):
servlets = [register_servlets]

def default_config(self):
def default_config(self) -> JsonDict:
config = super().default_config()
config.update(
{
Expand All @@ -40,17 +43,21 @@ def default_config(self):
)
return config

def prepare(self, reactor, clock, hs):
self.clock = MemoryReactorClock()
def prepare(
self, reactor: MemoryReactor, clock: Clock, homeserver: HomeServer
) -> None:
# type-ignore: mypy-zope doesn't seem to recognise that MemoryReactorClock
# implements IReactorTime, via inheritance from twisted.internet.testing.Clock
self.clock: IReactorTime = MemoryReactorClock() # type: ignore[assignment]
self.hs_clock = Clock(self.clock)
self.url = "/_matrix/client/r0/register"
self.registration_handler = Mock()
self.auth_handler = Mock()
self.device_handler = Mock()

def test_ui_auth(self):
def test_ui_auth(self) -> None:
# Do a UI auth request
request_data = {"username": "kermit", "password": "monkey"}
request_data: JsonDict = {"username": "kermit", "password": "monkey"}
channel = self.make_request(b"POST", self.url, request_data)

self.assertEqual(channel.code, 401, channel.result)
Expand Down