diff --git a/tests/rest/client/test_register.py b/tests/rest/client/test_register.py index 859051cdda7..46911cb1a0c 100644 --- a/tests/rest/client/test_register.py +++ b/tests/rest/client/test_register.py @@ -22,6 +22,7 @@ import datetime import os from typing import Any, Dict, List, Tuple +from unittest.mock import AsyncMock import pkg_resources @@ -35,6 +36,7 @@ ) from synapse.api.errors import Codes from synapse.appservice import ApplicationService +from synapse.http.server import HttpServer from synapse.rest.client import account, account_validity, login, logout, register, sync from synapse.server import HomeServer from synapse.storage._base import db_to_json @@ -45,11 +47,20 @@ from tests.unittest import override_config +# Let's override the email register servlet to mock send_email, since the smtp server doesn't really exists +def override_email_register_servlet(hs: "HomeServer", http_server: HttpServer) -> None: + if hs.config.worker.worker_app is None and hs.config.email.can_verify_email: + email_register_servlet = register.EmailRegisterRequestTokenRestServlet(hs) + email_register_servlet.already_in_use_mailer.send_email = AsyncMock() # type: ignore[method-assign] + email_register_servlet.register(http_server) + + class RegisterRestServletTestCase(unittest.HomeserverTestCase): servlets = [ login.register_servlets, register.register_servlets, synapse.rest.admin.register_servlets, + override_email_register_servlet, ] url = b"/_matrix/client/r0/register"