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

Commit 2dd44f6

Browse files
committed
Prevent tests from raising exception whilst setting up the config
1 parent 2fddb21 commit 2dd44f6

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

tests/config/test_workers.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,36 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Optional
14+
from typing import Any, Mapping, Optional
1515
from unittest.mock import Mock
1616

17+
from frozendict import frozendict
18+
1719
from synapse.config import ConfigError
1820
from synapse.config.workers import WorkerConfig
1921

2022
from tests.unittest import TestCase
2123

24+
_EMPTY_FROZENDICT: Mapping[str, Any] = frozendict()
25+
2226

2327
class WorkerDutyConfigTestCase(TestCase):
2428
def _make_worker_config(
25-
self, worker_app: str, worker_name: Optional[str]
29+
self,
30+
worker_app: str,
31+
worker_name: Optional[str],
32+
extras: Mapping[str, Any] = _EMPTY_FROZENDICT,
2633
) -> WorkerConfig:
2734
root_config = Mock()
2835
root_config.worker_app = worker_app
2936
root_config.worker_name = worker_name
3037
worker_config = WorkerConfig(root_config)
31-
worker_config.read_config(
32-
{"worker_name": worker_name, "worker_app": worker_app}
33-
)
38+
worker_config_dict = {
39+
"worker_name": worker_name,
40+
"worker_app": worker_app,
41+
**extras,
42+
}
43+
worker_config.read_config(worker_config_dict)
3444
return worker_config
3545

3646
def test_old_configs_master(self) -> None:
@@ -77,7 +87,13 @@ def test_old_configs_appservice_worker(self) -> None:
7787
Tests old (legacy) config options. This is for the worker's config.
7888
"""
7989
appservice_worker_config = self._make_worker_config(
80-
worker_app="synapse.app.appservice", worker_name="worker1"
90+
worker_app="synapse.app.appservice",
91+
worker_name="worker1",
92+
extras={
93+
# Set notify_appservices to false for the initialiser's config,
94+
# so that it doesn't raise an exception here.
95+
"notify_appservices": False,
96+
},
8197
)
8298

8399
with self.assertRaises(ConfigError):
@@ -179,7 +195,13 @@ def test_transitional_configs_appservice_worker(self) -> None:
179195
Tests transitional (legacy + new) config options. This is for the worker's config.
180196
"""
181197
appservice_worker_config = self._make_worker_config(
182-
worker_app="synapse.app.appservice", worker_name="worker1"
198+
worker_app="synapse.app.appservice",
199+
worker_name="worker1",
200+
extras={
201+
# Set notify_appservices to false for the initialiser's config,
202+
# so that it doesn't raise an exception here.
203+
"notify_appservices": False,
204+
},
183205
)
184206

185207
self.assertTrue(

0 commit comments

Comments
 (0)