Proper types for tests.test_terms_auth (#15007)

* Proper types for tests.test_terms_auth

* Changelog
This commit is contained in:
David Robertson 2023-02-07 12:03:39 +00:00 committed by GitHub
parent 5b55c32d61
commit 4dd2b6165c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

1
changelog.d/15007.misc Normal file
View file

@ -0,0 +1 @@
Improve type hints.

View file

@ -35,7 +35,6 @@ exclude = (?x)
|tests/module_api/test_api.py |tests/module_api/test_api.py
|tests/rest/media/v1/test_media_storage.py |tests/rest/media/v1/test_media_storage.py
|tests/server.py |tests/server.py
|tests/test_terms_auth.py
)$ )$
[mypy-synapse.federation.transport.client] [mypy-synapse.federation.transport.client]
@ -119,6 +118,9 @@ disallow_untyped_defs = True
[mypy-tests.test_state] [mypy-tests.test_state]
disallow_untyped_defs = True disallow_untyped_defs = True
[mypy-tests.test_terms_auth]
disallow_untyped_defs = True
[mypy-tests.types.*] [mypy-tests.types.*]
disallow_untyped_defs = True disallow_untyped_defs = True

View file

@ -14,9 +14,12 @@
from unittest.mock import Mock 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.rest.client.register import register_servlets
from synapse.server import HomeServer
from synapse.types import JsonDict
from synapse.util import Clock from synapse.util import Clock
from tests import unittest from tests import unittest
@ -25,7 +28,7 @@ from tests import unittest
class TermsTestCase(unittest.HomeserverTestCase): class TermsTestCase(unittest.HomeserverTestCase):
servlets = [register_servlets] servlets = [register_servlets]
def default_config(self): def default_config(self) -> JsonDict:
config = super().default_config() config = super().default_config()
config.update( config.update(
{ {
@ -40,17 +43,21 @@ class TermsTestCase(unittest.HomeserverTestCase):
) )
return config return config
def prepare(self, reactor, clock, hs): def prepare(
self.clock = MemoryReactorClock() 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.hs_clock = Clock(self.clock)
self.url = "/_matrix/client/r0/register" self.url = "/_matrix/client/r0/register"
self.registration_handler = Mock() self.registration_handler = Mock()
self.auth_handler = Mock() self.auth_handler = Mock()
self.device_handler = Mock() self.device_handler = Mock()
def test_ui_auth(self): def test_ui_auth(self) -> None:
# Do a UI auth request # 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) channel = self.make_request(b"POST", self.url, request_data)
self.assertEqual(channel.code, 401, channel.result) self.assertEqual(channel.code, 401, channel.result)