Add unit tests for backup_first_start and run them in CI
CI / build-and-scan (push) Failing after 40s
CI / build-and-scan (push) Failing after 40s
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
/adguard/*.log
|
||||
/tmp/
|
||||
__pycache__/
|
||||
.pytest_cache/
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[pytest]
|
||||
pythonpath = .
|
||||
@@ -0,0 +1,4 @@
|
||||
requests
|
||||
pyyaml
|
||||
schedule
|
||||
pytest
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user