Add unit tests for backup_first_start and run them in CI
CI / build-and-scan (push) Failing after 40s

This commit is contained in:
Djeex
2026-08-22 11:09:24 +02:00
parent 4753d80891
commit 267d9e52e0
5 changed files with 56 additions and 0 deletions
+7
View File
@@ -36,6 +36,13 @@ jobs:
exit(1)
"
- name: Run unit tests
run: |
docker run --rm -v "$PWD":/app -w /app python:3.13-alpine sh -c "
pip install --no-cache-dir -r requirements-dev.txt &&
pytest -v
"
- name: Check deprecation warnings
run: |
docker run --rm adguard-cidre:ci python -W error::DeprecationWarning -c "import blocklist_scheduler" 2>&1 | tee deprecation.log || true
+2
View File
@@ -1,2 +1,4 @@
/adguard/*.log
/tmp/
__pycache__/
.pytest_cache/
+2
View File
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
+4
View File
@@ -0,0 +1,4 @@
requests
pyyaml
schedule
pytest
+41
View File
@@ -0,0 +1,41 @@
import pytest
import blocklist_scheduler as bs
def test_backup_first_start_creates_backup_when_missing(tmp_path, monkeypatch):
adguard_yaml = tmp_path / "AdGuardHome.yaml"
adguard_yaml.write_text("original: config\n")
first_backup = tmp_path / "AdGuardHome.yaml.first-start.bak"
monkeypatch.setattr(bs, "ADGUARD_YAML", adguard_yaml)
monkeypatch.setattr(bs, "FIRST_BACKUP", first_backup)
bs.backup_first_start()
assert first_backup.read_text() == "original: config\n"
def test_backup_first_start_does_not_overwrite_existing_backup(tmp_path, monkeypatch):
adguard_yaml = tmp_path / "AdGuardHome.yaml"
adguard_yaml.write_text("new: config\n")
first_backup = tmp_path / "AdGuardHome.yaml.first-start.bak"
first_backup.write_text("pristine: original\n")
monkeypatch.setattr(bs, "ADGUARD_YAML", adguard_yaml)
monkeypatch.setattr(bs, "FIRST_BACKUP", first_backup)
bs.backup_first_start()
assert first_backup.read_text() == "pristine: original\n"
def test_backup_first_start_raises_if_adguard_yaml_missing(tmp_path, monkeypatch):
adguard_yaml = tmp_path / "AdGuardHome.yaml"
first_backup = tmp_path / "AdGuardHome.yaml.first-start.bak"
monkeypatch.setattr(bs, "ADGUARD_YAML", adguard_yaml)
monkeypatch.setattr(bs, "FIRST_BACKUP", first_backup)
with pytest.raises(FileNotFoundError):
bs.backup_first_start()