import os import pytest from ovdashboard_api.core.settings import Settings @pytest.fixture(autouse=True, scope="function") def patch_settings_env_file(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(os, "environ", {}) monkeypatch.delitem(Settings.model_config, "env_file") def test_empty(): s = Settings.model_validate({}) assert s.log_level == "INFO" assert s.production_mode is False assert s.ui_directory == "/usr/local/share/ovdashboard_ui/html" assert s.ping_host == "1.0.0.0" assert s.ping_port == 1 assert s.openapi_url == "/api/openapi.json" assert s.docs_url == "/api/docs" assert s.redoc_url == "/api/redoc" # webdav assert s.webdav.protocol == "https" assert s.webdav.host == "example.com" assert s.webdav.username == "ovd_user" assert s.webdav.password == "password" assert s.webdav.cache_ttl == 600 assert s.webdav.path == "/remote.php/webdav" assert s.webdav.config_filename == "config.txt" assert s.webdav.disable_check is False assert s.webdav.retries == 20 assert s.webdav.retry_delay == 30 assert s.webdav.prefix == "/ovdashboard" # caldav assert s.caldav.protocol == "https" assert s.caldav.host == "example.com" assert s.caldav.username == "ovd_user" assert s.caldav.password == "password" assert s.caldav.cache_ttl == 600 assert s.caldav.path == "/remote.php/dav" def test_prod(): s = Settings.model_validate({"production_mode": True}) assert s.log_level == "INFO" assert s.production_mode is True assert s.openapi_url is None assert s.docs_url is None assert s.redoc_url is None def test_set_caldav(): s = Settings.model_validate( { "caldav": { "protocol": "cd_protocol", "host": "cd_host", "username": "cd_username", "password": "cd_password", "cache_ttl": "0", "path": "cd_path", } } ) # webdav assert s.webdav.protocol == "https" assert s.webdav.host == "example.com" assert s.webdav.username == "ovd_user" assert s.webdav.password == "password" assert s.webdav.cache_ttl == 600 assert s.webdav.path == "/remote.php/webdav" assert s.webdav.config_filename == "config.txt" assert s.webdav.disable_check is False assert s.webdav.retries == 20 assert s.webdav.retry_delay == 30 assert s.webdav.prefix == "/ovdashboard" # caldav assert s.caldav.protocol == "cd_protocol" assert s.caldav.host == "cd_host" assert s.caldav.username == "cd_username" assert s.caldav.password == "cd_password" assert s.caldav.cache_ttl == 0 assert s.caldav.path == "cd_path" def test_set_webdav(): s = Settings.model_validate( { "webdav": { "protocol": "wd_protocol", "host": "wd_host", "username": "wd_username", "password": "wd_password", "cache_ttl": "99", "path": "wd_path", "config_filename": "wd_config_filename", "disable_check": "true", "retries": "99", "retry_delay": "99", "prefix": "wd_prefix", } } ) # webdav assert s.webdav.protocol == "wd_protocol" assert s.webdav.host == "wd_host" assert s.webdav.username == "wd_username" assert s.webdav.password == "wd_password" assert s.webdav.cache_ttl == 99 assert s.webdav.path == "wd_path" assert s.webdav.config_filename == "wd_config_filename" assert s.webdav.disable_check is True assert s.webdav.retries == 99 assert s.webdav.retry_delay == 99 assert s.webdav.prefix == "wd_prefix" # caldav assert s.caldav.protocol == "wd_protocol" assert s.caldav.host == "wd_host" assert s.caldav.username == "wd_username" assert s.caldav.password == "wd_password" assert s.caldav.cache_ttl == 99 assert s.caldav.path == "/remote.php/dav" def test_set_caldav_webdav(): s = Settings.model_validate( { "webdav": { "protocol": "wd_protocol", "host": "wd_host", "username": "wd_username", "password": "wd_password", "cache_ttl": "99", "path": "wd_path", "config_filename": "wd_config_filename", "disable_check": "true", "retries": "99", "retry_delay": "99", "prefix": "wd_prefix", }, "caldav": { "protocol": "cd_protocol", "host": "cd_host", "username": "cd_username", "password": "cd_password", "cache_ttl": "0", "path": "cd_path", }, } ) # webdav assert s.webdav.protocol == "wd_protocol" assert s.webdav.host == "wd_host" assert s.webdav.username == "wd_username" assert s.webdav.password == "wd_password" assert s.webdav.cache_ttl == 99 assert s.webdav.path == "wd_path" assert s.webdav.config_filename == "wd_config_filename" assert s.webdav.disable_check is True assert s.webdav.retries == 99 assert s.webdav.retry_delay == 99 assert s.webdav.prefix == "wd_prefix" # caldav assert s.caldav.protocol == "cd_protocol" assert s.caldav.host == "cd_host" assert s.caldav.username == "cd_username" assert s.caldav.password == "cd_password" assert s.caldav.cache_ttl == 0 assert s.caldav.path == "cd_path"