Add missing type hints to tests.handlers. (#14680)

And do not allow untyped defs in tests.handlers.
This commit is contained in:
Patrick Cloke 2022-12-16 06:53:01 -05:00 committed by GitHub
parent 54c012c5a8
commit 652d1669c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 527 additions and 378 deletions

View file

@ -13,7 +13,7 @@
# limitations under the License.
from typing import List, Tuple
from typing import Callable, List, Tuple
from zope.interface import implementer
@ -28,20 +28,27 @@ from tests.unittest import HomeserverTestCase, override_config
@implementer(interfaces.IMessageDelivery)
class _DummyMessageDelivery:
def __init__(self):
def __init__(self) -> None:
# (recipient, message) tuples
self.messages: List[Tuple[smtp.Address, bytes]] = []
def receivedHeader(self, helo, origin, recipients):
def receivedHeader(
self,
helo: Tuple[bytes, bytes],
origin: smtp.Address,
recipients: List[smtp.User],
) -> None:
return None
def validateFrom(self, helo, origin):
def validateFrom(
self, helo: Tuple[bytes, bytes], origin: smtp.Address
) -> smtp.Address:
return origin
def record_message(self, recipient: smtp.Address, message: bytes):
def record_message(self, recipient: smtp.Address, message: bytes) -> None:
self.messages.append((recipient, message))
def validateTo(self, user: smtp.User):
def validateTo(self, user: smtp.User) -> Callable[[], interfaces.IMessageSMTP]:
return lambda: _DummyMessage(self, user)
@ -56,20 +63,20 @@ class _DummyMessage:
self._user = user
self._buffer: List[bytes] = []
def lineReceived(self, line):
def lineReceived(self, line: bytes) -> None:
self._buffer.append(line)
def eomReceived(self):
def eomReceived(self) -> "defer.Deferred[bytes]":
message = b"\n".join(self._buffer) + b"\n"
self._delivery.record_message(self._user.dest, message)
return defer.succeed(b"saved")
def connectionLost(self):
def connectionLost(self) -> None:
pass
class SendEmailHandlerTestCase(HomeserverTestCase):
def test_send_email(self):
def test_send_email(self) -> None:
"""Happy-path test that we can send email to a non-TLS server."""
h = self.hs.get_send_email_handler()
d = ensureDeferred(
@ -119,7 +126,7 @@ class SendEmailHandlerTestCase(HomeserverTestCase):
},
}
)
def test_send_email_force_tls(self):
def test_send_email_force_tls(self) -> None:
"""Happy-path test that we can send email to an Implicit TLS server."""
h = self.hs.get_send_email_handler()
d = ensureDeferred(