diff --git a/src/jobs/removal_handler.py b/src/jobs/removal_handler.py index 5924332..4b97b19 100644 --- a/src/jobs/removal_handler.py +++ b/src/jobs/removal_handler.py @@ -9,7 +9,7 @@ class RemovalHandler: async def remove_downloads(self, affected_downloads, blocklist): for download_id in list(affected_downloads.keys()): logger.debug( - "remove_download/deleted_downloads.dict IN: %s", + "removal_handler.py/remove_downloads/arr.tracker.deleted IN: %s", str(self.arr.tracker.deleted), ) @@ -33,7 +33,7 @@ class RemovalHandler: self.arr.tracker.deleted.append(download_id) logger.debug( - "remove_download/arr_instance.tracker.deleted OUT: %s", + "removal_handler.py/remove_downloads/arr.tracker.deleted OUT: %s", str(self.arr.tracker.deleted), ) diff --git a/src/utils/common.py b/src/utils/common.py index 61786c8..cf08fd9 100644 --- a/src/utils/common.py +++ b/src/utils/common.py @@ -11,7 +11,7 @@ def sanitize_kwargs(data): if isinstance(data, dict): redacted = {} for key, value in data.items(): - if key.lower() in {"username", "password", "x-api-key"} and value: + if key.lower() in {"username", "password", "x-api-key", "cookies"} and value: redacted[key] = "[**redacted**]" else: redacted[key] = sanitize_kwargs(value) diff --git a/src/utils/queue_manager.py b/src/utils/queue_manager.py index bae634c..43ebeab 100644 --- a/src/utils/queue_manager.py +++ b/src/utils/queue_manager.py @@ -1,3 +1,4 @@ +import logging from src.utils.log_setup import logger from src.utils.common import make_request @@ -25,6 +26,8 @@ class QueueManager: queue_items = await self._get_queue(full_queue=True) else: raise ValueError(f"Invalid queue_scope: {queue_scope}") + if logger.isEnabledFor(logging.DEBUG): + logger.debug("queue_manager.py/get_queue_items/queue (%s): %s", queue_scope, self.format_queue(queue_items)) return queue_items async def _get_queue(self, full_queue=False): @@ -151,9 +154,9 @@ class QueueManager: formatted_dict[download_id] = { "downloadId": download_id, "downloadTitle": queue_item.get("title"), - "IDs": [item_id], "protocol": [queue_item.get("protocol")], "status": [queue_item.get("status")], + "IDs": [item_id], } return list(formatted_dict.values()) diff --git a/tests/utils/test_queue_manager.py b/tests/utils/test_queue_manager.py new file mode 100644 index 0000000..eb3b56e --- /dev/null +++ b/tests/utils/test_queue_manager.py @@ -0,0 +1,97 @@ +import pytest + +# Assuming your method is part of a class called QueueManager +from src.utils.queue_manager import QueueManager +from unittest.mock import Mock + +# ---------- Fixtures ---------- +@pytest.fixture(name="mock_queue_manager") +def mock_queue_manager(): + mock_arr = Mock() + mock_settings = Mock() + return QueueManager(arr=mock_arr, settings=mock_settings) + +# ---------- Tests ---------- +def test_format_queue_empty(mock_queue_manager): + result = mock_queue_manager.format_queue([]) + assert result == "empty" + +def test_format_queue_single_item(mock_queue_manager): + queue_items = [ + { + "downloadId": "abc123", + "title": "Example Download Title", + "protocol": "torrent", + "status": "queued", + "id": 1, + } + ] + expected = [{ + "downloadId": "abc123", + "downloadTitle": "Example Download Title", + "protocol": ["torrent"], + "status": ["queued"], + "IDs": [1], + }] + assert mock_queue_manager.format_queue(queue_items) == expected + +def test_format_queue_multiple_same_download_id(mock_queue_manager): + queue_items = [ + { + "downloadId": "xyz789", + "title": "Example Download Title", + "protocol": "usenet", + "status": "downloading", + "id": 1, + }, + { + "downloadId": "xyz789", + "title": "Example Download Title", + "protocol": "usenet", + "status": "downloading", + "id": 2, + } + ] + expected = [{ + "downloadId": "xyz789", + "downloadTitle": "Example Download Title", + "protocol": ["usenet"], + "status": ["downloading"], + "IDs": [1, 2], + }] + assert mock_queue_manager.format_queue(queue_items) == expected + +def test_format_queue_multiple_different_download_ids(mock_queue_manager): + queue_items = [ + { + "downloadId": "aaa111", + "title": "Example Download Title A", + "protocol": "torrent", + "status": "queued", + "id": 10, + }, + { + "downloadId": "bbb222", + "title": "Example Download Title B", + "protocol": "usenet", + "status": "completed", + "id": 20, + } + ] + expected = [ + { + "downloadId": "aaa111", + "downloadTitle": "Example Download Title A", + "protocol": ["torrent"], + "status": ["queued"], + "IDs": [10], + }, + { + "downloadId": "bbb222", + "downloadTitle": "Example Download Title B", + "protocol": ["usenet"], + "status": ["completed"], + "IDs": [20], + } + ] + assert mock_queue_manager.format_queue(queue_items) == expected