Files
pobsync/src/pobsync_backend/tests/test_config_repository.py

48 lines
1.8 KiB
Python
Raw Normal View History

from __future__ import annotations
import tempfile
from pathlib import Path
from django.test import TestCase
from pobsync.config.load import load_global_config, load_host_config
from pobsync_backend.config_repository import export_runtime_configs
from pobsync_backend.models import GlobalConfig, HostConfig
class ConfigRepositoryTests(TestCase):
def test_exports_database_configs_to_engine_yaml(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
prefix = Path(tmp)
GlobalConfig.objects.create(
name="default",
backup_root="/backups",
pobsync_home=str(prefix),
data={
"backup_root": "/ignored",
"pobsync_home": "/ignored",
"retention_defaults": {"daily": 7, "weekly": 4, "monthly": 3, "yearly": 1},
},
)
HostConfig.objects.create(
host="web-01",
address="web-01.example.test",
config={
"host": "ignored",
"address": "ignored",
"retention": {"daily": 7, "weekly": 4, "monthly": 3, "yearly": 1},
"includes": [],
"excludes_add": ["/tmp/***"],
},
)
written = export_runtime_configs(prefix=prefix, host="web-01")
self.assertEqual(len(written), 2)
global_cfg = load_global_config(prefix / "config" / "global.yaml")
host_cfg = load_host_config(prefix / "config" / "hosts" / "web-01.yaml")
self.assertEqual(global_cfg["backup_root"], "/backups")
self.assertEqual(global_cfg["pobsync_home"], str(prefix))
self.assertEqual(host_cfg["host"], "web-01")
self.assertEqual(host_cfg["address"], "web-01.example.test")