summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-11-16 00:03:46 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2021-11-17 00:47:56 +0000
commitca2cfa58d8fa5b4e53da38b6a75484ededea7ad8 (patch)
treebdac7cb350f612a2232ad2b4dc74c13cedc955f1
parentAdd type annotation to Databases.databases (diff)
downloadsynapse-ca2cfa58d8fa5b4e53da38b6a75484ededea7ad8.tar.xz
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?
-rw-r--r--tests/http/federation/test_matrix_federation_agent.py6
-rw-r--r--tests/storage/test_base.py6
-rw-r--r--tests/test_state.py7
-rw-r--r--tests/utils.py18
4 files changed, 25 insertions, 12 deletions
diff --git a/tests/http/federation/test_matrix_federation_agent.py b/tests/http/federation/test_matrix_federation_agent.py

index 992d8f94fd..9f11b526ba 100644 --- a/tests/http/federation/test_matrix_federation_agent.py +++ b/tests/http/federation/test_matrix_federation_agent.py
@@ -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) diff --git a/tests/storage/test_base.py b/tests/storage/test_base.py
index ddad44bd6c..b36fa66f00 100644 --- a/tests/storage/test_base.py +++ b/tests/storage/test_base.py
@@ -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"} diff --git a/tests/test_state.py b/tests/test_state.py
index 76e0e8ca7f..385d347ff3 100644 --- a/tests/test_state.py +++ b/tests/test_state.py
@@ -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() diff --git a/tests/utils.py b/tests/utils.py
index cf8ba5c5db..4ca678711a 100644 --- a/tests/utils.py +++ b/tests/utils.py
@@ -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()