Merge branch 'pr/NaruZosa/252' into decluttarr-v2

This commit is contained in:
Benjamin Harder
2025-06-02 14:26:03 +02:00
58 changed files with 848 additions and 744 deletions

View File

@@ -1,56 +1,94 @@
import pytest
from unittest.mock import MagicMock
from tests.jobs.utils import shared_fix_affected_items, shared_test_affected_items
from src.jobs.remove_metadata_missing import RemoveMetadataMissing
# Test to check if items with the specific error message are included in affected items with parameterized data
@pytest.mark.asyncio
@pytest.mark.parametrize(
"queue_data, expected_download_ids",
("queue_data", "expected_download_ids"),
[
(
[
{"downloadId": "1", "status": "queued", "errorMessage": "qBittorrent is downloading metadata"}, # Valid item
{"downloadId": "2", "status": "completed", "errorMessage": "qBittorrent is downloading metadata"}, # Wrong status
{"downloadId": "3", "status": "queued", "errorMessage": "Some other error"} # Incorrect errorMessage
{
"downloadId": "1",
"status": "queued",
"errorMessage": "qBittorrent is downloading metadata",
}, # Valid item
{
"downloadId": "2",
"status": "completed",
"errorMessage": "qBittorrent is downloading metadata",
}, # Wrong status
{
"downloadId": "3",
"status": "queued",
"errorMessage": "Some other error",
}, # Incorrect errorMessage
],
["1"] # Only the item with "queued" status and the correct errorMessage should be affected
[
"1"
], # Only the item with "queued" status and the correct errorMessage should be affected
),
(
[
{"downloadId": "1", "status": "queued", "errorMessage": "Some other error"}, # Incorrect errorMessage
{"downloadId": "2", "status": "completed", "errorMessage": "qBittorrent is downloading metadata"}, # Wrong status
{"downloadId": "3", "status": "queued", "errorMessage": "qBittorrent is downloading metadata"} # Correct item
{
"downloadId": "1",
"status": "queued",
"errorMessage": "Some other error",
}, # Incorrect errorMessage
{
"downloadId": "2",
"status": "completed",
"errorMessage": "qBittorrent is downloading metadata",
}, # Wrong status
{
"downloadId": "3",
"status": "queued",
"errorMessage": "qBittorrent is downloading metadata",
}, # Correct item
],
["3"] # Only the item with "queued" status and the correct errorMessage should be affected
[
"3"
], # Only the item with "queued" status and the correct errorMessage should be affected
),
(
[
{"downloadId": "1", "status": "queued", "errorMessage": "qBittorrent is downloading metadata"}, # Valid item
{"downloadId": "2", "status": "queued", "errorMessage": "qBittorrent is downloading metadata"} # Another valid item
{
"downloadId": "1",
"status": "queued",
"errorMessage": "qBittorrent is downloading metadata",
}, # Valid item
{
"downloadId": "2",
"status": "queued",
"errorMessage": "qBittorrent is downloading metadata",
}, # Another valid item
],
["1", "2"] # Both items match the condition
["1", "2"], # Both items match the condition
),
(
[
{"downloadId": "1", "status": "completed", "errorMessage": "qBittorrent is downloading metadata"}, # Wrong status
{"downloadId": "2", "status": "queued", "errorMessage": "Some other error"} # Incorrect errorMessage
{
"downloadId": "1",
"status": "completed",
"errorMessage": "qBittorrent is downloading metadata",
}, # Wrong status
{
"downloadId": "2",
"status": "queued",
"errorMessage": "Some other error",
}, # Incorrect errorMessage
],
[] # No items match the condition
)
]
[], # No items match the condition
),
],
)
async def test_find_affected_items(queue_data, expected_download_ids):
# Arrange
removal_job = RemoveMetadataMissing(arr=MagicMock(), settings=MagicMock(),job_name="test")
removal_job.queue = queue_data
removal_job = shared_fix_affected_items(RemoveMetadataMissing, queue_data)
# Act
affected_items = await removal_job._find_affected_items() # pylint: disable=W0212
# Assert
assert isinstance(affected_items, list)
# Assert that the affected items match the expected download IDs
affected_download_ids = [item["downloadId"] for item in affected_items]
assert sorted(affected_download_ids) == sorted(expected_download_ids), \
f"Expected affected items with downloadIds {expected_download_ids}, got {affected_download_ids}"
# Act and Assert
await shared_test_affected_items(removal_job, expected_download_ids)