feat: add tests, update configs, fix state.py return, update gitignore
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
import pytest
|
||||
from config import validate, HEADERS, Config
|
||||
|
||||
class TestValidate:
|
||||
def test_valid_config(self, env_vars):
|
||||
cfg = validate()
|
||||
assert isinstance(cfg, Config)
|
||||
assert cfg.ics_url == "https://example.com/cal.ics"
|
||||
assert cfg.baikal_url == "https://baikal.com/dav.php/calendars/user/cal/"
|
||||
assert cfg.baikal_user == "user"
|
||||
assert cfg.baikal_pass == "pass"
|
||||
assert cfg.sync_frequency == 5
|
||||
|
||||
def test_default_frequency(self, monkeypatch, env_vars):
|
||||
monkeypatch.delenv("SYNC_FREQUENCY", raising=False)
|
||||
cfg = validate()
|
||||
assert cfg.sync_frequency == 5
|
||||
|
||||
def test_missing_ics_url(self, monkeypatch, env_vars):
|
||||
monkeypatch.delenv("ICS_URL", raising=False)
|
||||
with pytest.raises(ValueError, match="ICS_URL"):
|
||||
validate()
|
||||
|
||||
def test_missing_all_required(self, monkeypatch, env_vars):
|
||||
for var in ["ICS_URL", "BAIKAL_URL", "BAIKAL_USER", "BAIKAL_PASS"]:
|
||||
monkeypatch.delenv(var, raising=False)
|
||||
with pytest.raises(ValueError):
|
||||
validate()
|
||||
|
||||
def test_invalid_frequency(self, monkeypatch, env_vars):
|
||||
monkeypatch.setenv("SYNC_FREQUENCY", "-1")
|
||||
with pytest.raises(ValueError, match="SYNC_FREQUENCY"):
|
||||
validate()
|
||||
|
||||
def test_frequency_zero(self, monkeypatch, env_vars):
|
||||
monkeypatch.setenv("SYNC_FREQUENCY", "0")
|
||||
with pytest.raises(ValueError, match="SYNC_FREQUENCY"):
|
||||
validate()
|
||||
|
||||
def test_frequency_string(self, monkeypatch, env_vars):
|
||||
monkeypatch.setenv("SYNC_FREQUENCY", "abc")
|
||||
with pytest.raises(ValueError, match="SYNC_FREQUENCY"):
|
||||
validate()
|
||||
|
||||
class TestHeaders:
|
||||
def test_headers_exist(self):
|
||||
assert "User-Agent" in HEADERS
|
||||
assert "Unraid-Sync" in HEADERS["User-Agent"]
|
||||
Reference in New Issue
Block a user