issue-7-config-cleanup-legacy-removal #18
@@ -85,7 +85,7 @@ def global_config_data(name: str = "default") -> dict[str, Any]:
|
||||
try:
|
||||
global_config = GlobalConfig.objects.get(name=name)
|
||||
except ObjectDoesNotExist as exc:
|
||||
raise ConfigRepositoryError(f"Missing GlobalConfig {name!r}") from exc
|
||||
raise ConfigRepositoryError(f"Missing global config {name!r}") from exc
|
||||
return _global_runtime_data(global_config)
|
||||
|
||||
|
||||
@@ -93,5 +93,5 @@ def host_config_data(host: str) -> dict[str, Any]:
|
||||
try:
|
||||
host_config = HostConfig.objects.get(host=host, enabled=True)
|
||||
except ObjectDoesNotExist as exc:
|
||||
raise ConfigRepositoryError(f"Missing enabled HostConfig {host!r}") from exc
|
||||
raise ConfigRepositoryError(f"Missing enabled host {host!r}") from exc
|
||||
return _host_runtime_data(host_config)
|
||||
|
||||
@@ -135,7 +135,7 @@ def _enabled_host_config(host: str) -> HostConfig:
|
||||
try:
|
||||
return HostConfig.objects.get(host=host, enabled=True)
|
||||
except HostConfig.DoesNotExist as exc:
|
||||
raise ConfigError(f"Missing enabled HostConfig {host!r}") from exc
|
||||
raise ConfigError(f"Missing enabled host {host!r}") from exc
|
||||
|
||||
|
||||
def _retention_for_host(host_config: HostConfig) -> dict[str, int]:
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from pobsync_backend.config_repository import global_config_data, host_config_data
|
||||
from pobsync_backend.config_repository import ConfigRepositoryError, global_config_data, host_config_data
|
||||
from pobsync_backend.models import GlobalConfig, HostConfig
|
||||
|
||||
|
||||
@@ -52,3 +52,12 @@ class ConfigRepositoryTests(TestCase):
|
||||
self.assertEqual(host_cfg["excludes_add"], ["/tmp/***"])
|
||||
self.assertNotIn("unknown", global_cfg)
|
||||
self.assertNotIn("unknown", host_cfg)
|
||||
|
||||
def test_missing_config_errors_use_operator_labels(self) -> None:
|
||||
with self.assertRaisesMessage(ConfigRepositoryError, "Missing global config 'default'"):
|
||||
global_config_data()
|
||||
|
||||
GlobalConfig.objects.create(name="default", backup_root="/backups")
|
||||
|
||||
with self.assertRaisesMessage(ConfigRepositoryError, "Missing enabled host 'web-01'"):
|
||||
host_config_data("web-01")
|
||||
|
||||
Reference in New Issue
Block a user