mirror of
https://github.com/ManiMatter/decluttarr.git
synced 2026-04-18 12:54:02 +02:00
Merge branch 'pr/NaruZosa/252' into decluttarr-v2
This commit is contained in:
@@ -1,32 +1,35 @@
|
||||
"""Test loading the user configuration from environment variables."""
|
||||
import os
|
||||
import textwrap
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from unittest.mock import patch
|
||||
|
||||
from src.settings._user_config import _load_from_env
|
||||
|
||||
# ---- Pytest Fixtures ----
|
||||
# Pre-define multiline YAML snippets with dedent and strip for clarity
|
||||
# Single values as plain strings (not YAML block strings)
|
||||
log_level_value = "VERBOSE"
|
||||
timer_value = "10"
|
||||
ssl_verification_value = "true"
|
||||
LOG_LEVEL_VALUE = "VERBOSE"
|
||||
TIMER_VALUE = "10"
|
||||
SSL_VERIFICATION_VALUE = "true"
|
||||
|
||||
# List
|
||||
ignored_download_clients_yaml = textwrap.dedent("""
|
||||
ignored_download_clients_yaml = textwrap.dedent("""
|
||||
- emulerr
|
||||
- napster
|
||||
""").strip()
|
||||
|
||||
# Job: No settings
|
||||
remove_bad_files_yaml = "" # empty string represents flag enabled with no config
|
||||
remove_bad_files_yaml = "" # pylint: disable=C0103; empty string represents flag enabled with no config
|
||||
|
||||
# Job: One Setting
|
||||
# Job: One Setting
|
||||
remove_slow_yaml = textwrap.dedent("""
|
||||
- max_strikes: 3
|
||||
""").strip()
|
||||
|
||||
# Job: Multiple Setting
|
||||
# Job: Multiple Setting
|
||||
remove_stalled_yaml = textwrap.dedent("""
|
||||
- min_speed: 100
|
||||
- max_strikes: 3
|
||||
@@ -55,12 +58,13 @@ qbit_yaml = textwrap.dedent("""
|
||||
password: "qbit_password1"
|
||||
""").strip()
|
||||
|
||||
|
||||
@pytest.fixture(name="env_vars")
|
||||
def fixture_env_vars():
|
||||
env = {
|
||||
"LOG_LEVEL": log_level_value,
|
||||
"TIMER": timer_value,
|
||||
"SSL_VERIFICATION": ssl_verification_value,
|
||||
"LOG_LEVEL": LOG_LEVEL_VALUE,
|
||||
"TIMER": TIMER_VALUE,
|
||||
"SSL_VERIFICATION": SSL_VERIFICATION_VALUE,
|
||||
"IGNORED_DOWNLOAD_CLIENTS": ignored_download_clients_yaml,
|
||||
"REMOVE_BAD_FILES": remove_bad_files_yaml,
|
||||
"REMOVE_SLOW": remove_slow_yaml,
|
||||
@@ -82,9 +86,10 @@ radarr_expected = yaml.safe_load(radarr_yaml)
|
||||
sonarr_expected = yaml.safe_load(sonarr_yaml)
|
||||
qbit_expected = yaml.safe_load(qbit_yaml)
|
||||
|
||||
@pytest.mark.parametrize("section,key,expected", [
|
||||
("general", "log_level", log_level_value),
|
||||
("general", "timer", int(timer_value)),
|
||||
|
||||
@pytest.mark.parametrize(("section", "key", "expected"), [
|
||||
("general", "log_level", LOG_LEVEL_VALUE),
|
||||
("general", "timer", int(TIMER_VALUE)),
|
||||
("general", "ssl_verification", True),
|
||||
("general", "ignored_download_clients", remove_ignored_download_clients_expected),
|
||||
("jobs", "remove_bad_files", remove_bad_files_expected),
|
||||
@@ -94,16 +99,14 @@ qbit_expected = yaml.safe_load(qbit_yaml)
|
||||
("instances", "sonarr", sonarr_expected),
|
||||
("download_clients", "qbittorrent", qbit_expected),
|
||||
])
|
||||
def test_env_loading_parametrized(env_vars, section, key, expected): # pylint: disable=unused-argument
|
||||
def test_env_loading_parametrized(env_vars, section, key, expected): # pylint: disable=unused-argument # noqa: ARG001
|
||||
config = _load_from_env()
|
||||
assert section in config
|
||||
assert key in config[section]
|
||||
value = config[section][key]
|
||||
|
||||
|
||||
if isinstance(expected, list):
|
||||
# Compare as lists
|
||||
assert value == expected
|
||||
else:
|
||||
assert value == expected
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user