2026-05-19 04:57:10 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
|
|
from pobsync_backend.config_source import DjangoConfigSource
|
|
|
|
|
from pobsync_backend.models import GlobalConfig, HostConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DjangoConfigSourceTests(TestCase):
|
|
|
|
|
def test_returns_effective_config_from_database(self) -> None:
|
|
|
|
|
GlobalConfig.objects.create(
|
|
|
|
|
name="default",
|
|
|
|
|
backup_root="/backups",
|
|
|
|
|
pobsync_home="/opt/pobsync",
|
2026-05-19 05:04:49 +02:00
|
|
|
rsync_args=["--archive"],
|
|
|
|
|
rsync_extra_args=["--numeric-ids"],
|
|
|
|
|
excludes_default=["/proc/***"],
|
|
|
|
|
retention_daily=7,
|
|
|
|
|
retention_weekly=4,
|
|
|
|
|
retention_monthly=3,
|
|
|
|
|
retention_yearly=1,
|
2026-05-19 04:57:10 +02:00
|
|
|
data={
|
|
|
|
|
"backup_root": "/ignored",
|
|
|
|
|
"pobsync_home": "/ignored",
|
|
|
|
|
"ssh": {"user": "root", "port": 22, "options": []},
|
|
|
|
|
"rsync": {
|
|
|
|
|
"binary": "rsync",
|
|
|
|
|
"args": ["--archive"],
|
|
|
|
|
"timeout_seconds": 0,
|
|
|
|
|
"bwlimit_kbps": 0,
|
|
|
|
|
"extra_args": ["--numeric-ids"],
|
|
|
|
|
},
|
|
|
|
|
"defaults": {"source_root": "/", "destination_subdir": ""},
|
|
|
|
|
"excludes_default": ["/proc/***"],
|
|
|
|
|
"retention_defaults": {"daily": 7, "weekly": 4, "monthly": 3, "yearly": 1},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
HostConfig.objects.create(
|
|
|
|
|
host="web-01",
|
|
|
|
|
address="web-01.example.test",
|
2026-05-19 05:04:49 +02:00
|
|
|
excludes_add=["/tmp/***"],
|
|
|
|
|
rsync_extra_args=["--delete"],
|
|
|
|
|
retention_daily=7,
|
|
|
|
|
retention_weekly=4,
|
|
|
|
|
retention_monthly=3,
|
|
|
|
|
retention_yearly=1,
|
2026-05-19 04:57:10 +02:00
|
|
|
config={
|
2026-05-19 05:04:49 +02:00
|
|
|
"retention": {"daily": 99, "weekly": 99, "monthly": 99, "yearly": 99},
|
|
|
|
|
"excludes_add": ["/ignored/***"],
|
|
|
|
|
"rsync": {"extra_args": ["--ignored"]},
|
2026-05-19 04:57:10 +02:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cfg = DjangoConfigSource().effective_config_for_host("web-01")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cfg["backup_root"], "/backups")
|
|
|
|
|
self.assertEqual(cfg["host"], "web-01")
|
|
|
|
|
self.assertEqual(cfg["address"], "web-01.example.test")
|
|
|
|
|
self.assertEqual(cfg["excludes_effective"], ["/proc/***", "/tmp/***"])
|
|
|
|
|
self.assertEqual(cfg["rsync"]["args_effective"], ["--archive", "--numeric-ids", "--delete"])
|