Aggiunge tray app e backup manuale
This commit is contained in:
52
tests/test_backup.py
Normal file
52
tests/test_backup.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from bakrest.backup import _build_rsync_command, _split_existing_files
|
||||
from bakrest.config import parse_config
|
||||
from bakrest.registry import ChangeEvent
|
||||
|
||||
|
||||
def test_split_existing_files_ignores_deleted(tmp_path: Path) -> None:
|
||||
existing = tmp_path / "image.jpg"
|
||||
existing.write_text("ok", encoding="utf-8")
|
||||
events = [
|
||||
ChangeEvent(path=str(existing), event_type="modified"),
|
||||
ChangeEvent(path=str(tmp_path / "missing.jpg"), event_type="deleted"),
|
||||
]
|
||||
|
||||
present, skipped = _split_existing_files(events)
|
||||
|
||||
assert [event.path for event in present] == [str(existing)]
|
||||
assert [event.path for event in skipped] == [str(tmp_path / "missing.jpg")]
|
||||
|
||||
|
||||
def test_build_rsync_command_uses_files_from(tmp_path: Path) -> None:
|
||||
source = tmp_path / "source"
|
||||
source.mkdir()
|
||||
image = source / "image.jpg"
|
||||
image.write_text("ok", encoding="utf-8")
|
||||
config = parse_config(
|
||||
{
|
||||
"watch": {
|
||||
"include_dirs": [str(source)],
|
||||
"include_extensions": [".jpg"],
|
||||
"exclude_dirs": [],
|
||||
"exclude_patterns": [],
|
||||
},
|
||||
"backup": {
|
||||
"rsync_path": "rsync",
|
||||
"remote_destination": "user@host:/backup/",
|
||||
"server_check": {"type": "tcp", "port": 22, "interval_seconds": 300, "timeout_seconds": 1},
|
||||
},
|
||||
},
|
||||
tmp_path / "config.toml",
|
||||
)
|
||||
|
||||
command = _build_rsync_command(config, [ChangeEvent(path=str(image), event_type="modified")])
|
||||
|
||||
assert command[0] == "rsync"
|
||||
assert "-av" in command
|
||||
assert "--relative" in command
|
||||
assert any(part.startswith("--files-from=") for part in command)
|
||||
assert command[-1] == "user@host:/backup/"
|
||||
Reference in New Issue
Block a user