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

Register homeserver modules when creating test homeserver #13558

Merged
merged 2 commits into from
Aug 19, 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/13558.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make `HomeServerTestCase` load any configured homeserver modules automatically.
4 changes: 0 additions & 4 deletions tests/events/test_presence_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ def make_homeserver(self, reactor, clock):
hs = self.setup_test_homeserver(
federation_transport_client=fed_transport_client,
)
# Load the modules into the homeserver
module_api = hs.get_module_api()
for module, config in hs.config.modules.loaded_modules:
module(config=config, api=module_api)

load_legacy_presence_router(hs)

Expand Down
11 changes: 0 additions & 11 deletions tests/handlers/test_password_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import synapse
from synapse.api.constants import LoginType
from synapse.api.errors import Codes
from synapse.handlers.auth import load_legacy_password_auth_providers
from synapse.module_api import ModuleApi
from synapse.rest.client import account, devices, login, logout, register
from synapse.types import JsonDict, UserID
Expand Down Expand Up @@ -167,16 +166,6 @@ def setUp(self):
mock_password_provider.reset_mock()
super().setUp()

def make_homeserver(self, reactor, clock):
hs = self.setup_test_homeserver()
# Load the modules into the homeserver
module_api = hs.get_module_api()
for module, config in hs.config.modules.loaded_modules:
module(config=config, api=module_api)
load_legacy_password_auth_providers(hs)

return hs

@override_config(legacy_providers_config(LegacyPasswordOnlyAuthProvider))
def test_password_only_auth_progiver_login_legacy(self):
self.password_only_auth_provider_login_test_body()
Expand Down
7 changes: 0 additions & 7 deletions tests/handlers/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
ResourceLimitError,
SynapseError,
)
from synapse.events.spamcheck import load_legacy_spam_checkers
from synapse.spam_checker_api import RegistrationBehaviour
from synapse.types import RoomAlias, RoomID, UserID, create_requester

Expand Down Expand Up @@ -144,12 +143,6 @@ def make_homeserver(self, reactor, clock):
config=hs_config, federation_client=self.mock_federation_client
)

load_legacy_spam_checkers(hs)

module_api = hs.get_module_api()
for module, config in hs.config.modules.loaded_modules:
module(config=config, api=module_api)

return hs

def prepare(self, reactor, clock, hs):
Expand Down
14 changes: 14 additions & 0 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
from twisted.web.server import Request, Site

from synapse.config.database import DatabaseConnectionConfig
from synapse.events.presence_router import load_legacy_presence_router
from synapse.events.spamcheck import load_legacy_spam_checkers
from synapse.events.third_party_rules import load_legacy_third_party_event_rules
from synapse.handlers.auth import load_legacy_password_auth_providers
from synapse.http.site import SynapseRequest
from synapse.logging.context import ContextResourceUsage
from synapse.server import HomeServer
Expand Down Expand Up @@ -913,4 +917,14 @@ async def validate_hash(p, h):
# Make the threadpool and database transactions synchronous for testing.
_make_test_homeserver_synchronous(hs)

# Load any configured modules into the homeserver
module_api = hs.get_module_api()
for module, config in hs.config.modules.loaded_modules:
module(config=config, api=module_api)

load_legacy_spam_checkers(hs)
load_legacy_third_party_event_rules(hs)
load_legacy_presence_router(hs)
load_legacy_password_auth_providers(hs)

return hs