Formatting issues

This commit is contained in:
Benjamin Harder
2025-10-01 18:43:38 +02:00
parent 1a4bd8f4be
commit 8d9a64798d
41 changed files with 725 additions and 387 deletions

View File

@@ -1,5 +1,7 @@
from unittest.mock import AsyncMock, patch, MagicMock
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from src.settings._instances import ArrInstance

View File

@@ -1,4 +1,5 @@
from unittest.mock import Mock, AsyncMock
from unittest.mock import AsyncMock, Mock
import pytest
from src.settings._download_clients_sabnzbd import SabnzbdClient, SabnzbdClients
@@ -11,9 +12,7 @@ class TestSabnzbdClient:
settings.min_versions = Mock()
settings.min_versions.sabnzbd = "4.0.0"
client = SabnzbdClient(
settings=settings,
base_url="http://sabnzbd:8080",
api_key="test_api_key"
settings=settings, base_url="http://sabnzbd:8080", api_key="test_api_key"
)
assert client.base_url == "http://sabnzbd:8080"
assert client.api_url == "http://sabnzbd:8080/api"
@@ -29,7 +28,7 @@ class TestSabnzbdClient:
settings=settings,
base_url="http://sabnzbd:8080/",
api_key="test_api_key",
name="Custom SABnzbd"
name="Custom SABnzbd",
)
assert client.base_url == "http://sabnzbd:8080"
assert client.api_url == "http://sabnzbd:8080/api"
@@ -55,23 +54,14 @@ class TestSabnzbdClient:
settings.min_versions = Mock()
settings.min_versions.sabnzbd = "4.0.0"
client = SabnzbdClient(
settings=settings,
base_url="http://sabnzbd:8080",
api_key="test_api_key"
settings=settings, base_url="http://sabnzbd:8080", api_key="test_api_key"
)
# Mock the get_queue_items method
client.get_queue_items = AsyncMock(return_value=[
{
"nzo_id": "test_id_1",
"mb": "1000",
"mbleft": "200"
},
{
"nzo_id": "test_id_2",
"mb": "2000",
"mbleft": "1000"
}
]
client.get_queue_items = AsyncMock(
return_value=[
{"nzo_id": "test_id_1", "mb": "1000", "mbleft": "200"},
{"nzo_id": "test_id_2", "mb": "2000", "mbleft": "1000"},
]
)
# Test getting progress for existing download
progress = await client.fetch_download_progress("test_id_1")
@@ -95,15 +85,12 @@ class TestSabnzbdClients:
config = {
"download_clients": {
"sabnzbd": [
{"base_url": "http://sabnzbd1:8080", "api_key": "api_key_1"},
{
"base_url": "http://sabnzbd1:8080",
"api_key": "api_key_1"
},
{
"base_url": "http://sabnzbd2:8080",
"base_url": "http://sabnzbd2:8080",
"api_key": "api_key_2",
"name": "SABnzbd 2"
}
"name": "SABnzbd 2",
},
]
}
}
@@ -121,11 +108,7 @@ class TestSabnzbdClients:
def test_init_invalid_config_format(self, caplog):
"""Test SabnzbdClients initialization with invalid config format."""
config = {
"download_clients": {
"sabnzbd": "not_a_list"
}
}
config = {"download_clients": {"sabnzbd": "not_a_list"}}
settings = Mock()
clients = SabnzbdClients(config, settings)
assert len(clients) == 0

View File

@@ -1,4 +1,5 @@
"""Test loading the user configuration from environment variables."""
import os
import textwrap
from unittest.mock import patch
@@ -16,47 +17,61 @@ TIMER_VALUE = "10"
SSL_VERIFICATION_VALUE = "true"
# List
ignored_download_clients_yaml = textwrap.dedent("""
ignored_download_clients_yaml = textwrap.dedent(
"""
- emulerr
- napster
""").strip()
"""
).strip()
# Job: No settings
remove_bad_files_yaml = "" # pylint: disable=C0103; 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
remove_slow_yaml = textwrap.dedent("""
remove_slow_yaml = textwrap.dedent(
"""
- max_strikes: 3
""").strip()
"""
).strip()
# Job: Multiple Setting
remove_stalled_yaml = textwrap.dedent("""
remove_stalled_yaml = textwrap.dedent(
"""
- min_speed: 100
- max_strikes: 3
- some_bool_upper: TRUE
- some_bool_lower: false
- some_bool_sentence: False
""").strip()
"""
).strip()
# Arr Instances
radarr_yaml = textwrap.dedent("""
radarr_yaml = textwrap.dedent(
"""
- base_url: "http://radarr:7878"
api_key: "radarr1_key"
""").strip()
"""
).strip()
sonarr_yaml = textwrap.dedent("""
sonarr_yaml = textwrap.dedent(
"""
- base_url: "sonarr_1_api_key"
api_key: "sonarr1_api_url"
- base_url: "sonarr_2_api_key"
api_key: "sonarr2_api_url"
""").strip()
"""
).strip()
# Qbit Instances
qbit_yaml = textwrap.dedent("""
qbit_yaml = textwrap.dedent(
"""
- base_url: "http://qbittorrent:8080"
username: "qbit_username1"
password: "qbit_password1"
""").strip()
"""
).strip()
@pytest.fixture(name="env_vars")
@@ -87,19 +102,28 @@ 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)),
("general", "ssl_verification", True),
("general", "ignored_download_clients", remove_ignored_download_clients_expected),
("jobs", "remove_bad_files", remove_bad_files_expected),
("jobs", "remove_slow", remove_slow_expected),
("jobs", "remove_stalled", remove_stalled_expected),
("instances", "radarr", radarr_expected),
("instances", "sonarr", sonarr_expected),
("download_clients", "qbittorrent", qbit_expected),
])
def test_env_loading_parametrized(env_vars, section, key, expected): # pylint: disable=unused-argument # noqa: ARG001
@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),
("jobs", "remove_slow", remove_slow_expected),
("jobs", "remove_stalled", remove_stalled_expected),
("instances", "radarr", radarr_expected),
("instances", "sonarr", sonarr_expected),
("download_clients", "qbittorrent", qbit_expected),
],
)
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]