Make default_config only return a dict representation
This does make mypy happy, and does reduce a bit of confusion, though it's a shame we have to duplicate the parsing code around everywhere now. Is there a better way to solve this?
This commit is contained in:
@@ -67,7 +67,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||
|
||||
self.mock_resolver = Mock()
|
||||
|
||||
config_dict = default_config("test", parse=False)
|
||||
config_dict = default_config("test")
|
||||
config_dict["federation_custom_ca_list"] = [get_test_ca_cert_file()]
|
||||
|
||||
self._config = config = HomeServerConfig()
|
||||
@@ -957,7 +957,9 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||
|
||||
config = default_config("test", parse=True)
|
||||
config_dict = default_config("test")
|
||||
config = HomeServerConfig()
|
||||
config.parse_config_dict(config_dict)
|
||||
|
||||
# Build a new agent and WellKnownResolver with a different tls factory
|
||||
tls_factory = FederationPolicyForHTTPS(config)
|
||||
|
||||
@@ -18,6 +18,7 @@ from unittest.mock import Mock
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.config.homeserver import HomeServerConfig
|
||||
from synapse.storage._base import SQLBaseStore
|
||||
from synapse.storage.database import DatabasePool
|
||||
from synapse.storage.engines import create_engine
|
||||
@@ -47,7 +48,10 @@ class SQLBaseStoreTestCase(unittest.TestCase):
|
||||
|
||||
self.db_pool.runWithConnection = runWithConnection
|
||||
|
||||
config = default_config(name="test", parse=True)
|
||||
config_dict = default_config(name="test")
|
||||
config = HomeServerConfig()
|
||||
config.parse_config_dict(config_dict)
|
||||
|
||||
hs = TestHomeServer("test", config=config)
|
||||
|
||||
sqlite_config = {"name": "sqlite3"}
|
||||
|
||||
@@ -19,6 +19,7 @@ from twisted.internet import defer
|
||||
from synapse.api.auth import Auth
|
||||
from synapse.api.constants import EventTypes, Membership
|
||||
from synapse.api.room_versions import RoomVersions
|
||||
from synapse.config.homeserver import HomeServerConfig
|
||||
from synapse.events import make_event_from_dict
|
||||
from synapse.events.snapshot import EventContext
|
||||
from synapse.state import StateHandler, StateResolutionHandler
|
||||
@@ -172,7 +173,11 @@ class StateTestCase(unittest.TestCase):
|
||||
"hostname",
|
||||
]
|
||||
)
|
||||
hs.config = default_config("tesths", True)
|
||||
|
||||
config_dict = default_config("tesths")
|
||||
hs.config = HomeServerConfig()
|
||||
hs.config.parse_config_dict(config_dict)
|
||||
|
||||
hs.get_datastore.return_value = self.store
|
||||
hs.get_state_handler.return_value = None
|
||||
hs.get_clock.return_value = MockClock()
|
||||
|
||||
@@ -104,9 +104,15 @@ def setupdb():
|
||||
atexit.register(_cleanup)
|
||||
|
||||
|
||||
def default_config(name, parse=False):
|
||||
def default_config(name: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Create a reasonable test config.
|
||||
|
||||
Args:
|
||||
name: The value of the 'server_name' option in the returned config.
|
||||
|
||||
Returns:
|
||||
A sensible, default homeserver config.
|
||||
"""
|
||||
config_dict = {
|
||||
"server_name": name,
|
||||
@@ -175,11 +181,6 @@ def default_config(name, parse=False):
|
||||
"listeners": [{"port": 0, "type": "http"}],
|
||||
}
|
||||
|
||||
if parse:
|
||||
config = HomeServerConfig()
|
||||
config.parse_config_dict(config_dict, "", "")
|
||||
return config
|
||||
|
||||
return config_dict
|
||||
|
||||
|
||||
@@ -212,9 +213,10 @@ def setup_test_homeserver(
|
||||
from twisted.internet import reactor
|
||||
|
||||
if config is None:
|
||||
config = default_config(name, parse=True)
|
||||
config_dict = default_config(name)
|
||||
|
||||
config.ldap_enabled = False
|
||||
config = HomeServerConfig()
|
||||
config.parse_config_dict(config_dict)
|
||||
|
||||
if "clock" not in kwargs:
|
||||
kwargs["clock"] = MockClock()
|
||||
|
||||
Reference in New Issue
Block a user