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

Commit

Permalink
Prevent tests from raising exception whilst setting up the config
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Apr 27, 2022
1 parent 807048c commit 95fce8d
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions tests/config/test_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,36 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
from typing import Any, Mapping, Optional
from unittest.mock import Mock

from frozendict import frozendict

from synapse.config import ConfigError
from synapse.config.workers import WorkerConfig

from tests.unittest import TestCase

_EMPTY_FROZENDICT: Mapping[str, Any] = frozendict()


class WorkerDutyConfigTestCase(TestCase):
def _make_worker_config(
self, worker_app: str, worker_name: Optional[str]
self,
worker_app: str,
worker_name: Optional[str],
extras: Mapping[str, Any] = _EMPTY_FROZENDICT,
) -> WorkerConfig:
root_config = Mock()
root_config.worker_app = worker_app
root_config.worker_name = worker_name
worker_config = WorkerConfig(root_config)
worker_config.read_config(
{"worker_name": worker_name, "worker_app": worker_app}
)
worker_config_dict = {
"worker_name": worker_name,
"worker_app": worker_app,
**extras,
}
worker_config.read_config(worker_config_dict)
return worker_config

def test_old_configs_master(self) -> None:
Expand Down Expand Up @@ -77,7 +87,13 @@ def test_old_configs_appservice_worker(self) -> None:
Tests old (legacy) config options. This is for the worker's config.
"""
appservice_worker_config = self._make_worker_config(
worker_app="synapse.app.appservice", worker_name="worker1"
worker_app="synapse.app.appservice",
worker_name="worker1",
extras={
# Set notify_appservices to false for the initialiser's config,
# so that it doesn't raise an exception here.
"notify_appservices": False,
},
)

with self.assertRaises(ConfigError):
Expand Down Expand Up @@ -179,7 +195,13 @@ def test_transitional_configs_appservice_worker(self) -> None:
Tests transitional (legacy + new) config options. This is for the worker's config.
"""
appservice_worker_config = self._make_worker_config(
worker_app="synapse.app.appservice", worker_name="worker1"
worker_app="synapse.app.appservice",
worker_name="worker1",
extras={
# Set notify_appservices to false for the initialiser's config,
# so that it doesn't raise an exception here.
"notify_appservices": False,
},
)

self.assertTrue(
Expand Down

0 comments on commit 95fce8d

Please sign in to comment.