|
| 1 | +from unittest.mock import MagicMock |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from src.jobs.remove_metadata_missing import RemoveMetadataMissing |
@@ -91,3 +93,100 @@ async def test_find_affected_items(queue_data, expected_download_ids): |
91 | 93 |
|
92 | 94 | # Act and Assert |
93 | 95 | await shared_test_affected_items(removal_job, expected_download_ids) |
| 96 | + |
| 97 | + |
| 98 | +# Tests the opt-in, client-agnostic detection of items stuck without metadata |
| 99 | +# (status "queued" + size 0), e.g. on Transmission/Deluge which do not surface the |
| 100 | +# qBittorrent "downloading metadata" message in the *arr queue (see issue #57). |
| 101 | +@pytest.mark.asyncio |
| 102 | +@pytest.mark.parametrize( |
| 103 | + ("detect_via_missing_size", "queue_data", "expected_download_ids"), |
| 104 | + [ |
| 105 | + # Disabled (default): a queued size-0 item is NOT flagged; only the qBit message is. |
| 106 | + ( |
| 107 | + False, |
| 108 | + [ |
| 109 | + { |
| 110 | + "id": 1, |
| 111 | + "downloadId": "a", |
| 112 | + "status": "queued", |
| 113 | + "size": 0, |
| 114 | + "errorMessage": None, |
| 115 | + }, |
| 116 | + { |
| 117 | + "id": 2, |
| 118 | + "downloadId": "b", |
| 119 | + "status": "queued", |
| 120 | + "errorMessage": "qBittorrent is downloading metadata", |
| 121 | + }, |
| 122 | + ], |
| 123 | + ["b"], |
| 124 | + ), |
| 125 | + # Enabled: queued + size 0 is flagged; size > 0 and non-queued are left alone. |
| 126 | + ( |
| 127 | + True, |
| 128 | + [ |
| 129 | + { |
| 130 | + "id": 1, |
| 131 | + "downloadId": "a", |
| 132 | + "status": "queued", |
| 133 | + "size": 0, |
| 134 | + "errorMessage": None, |
| 135 | + }, |
| 136 | + { |
| 137 | + "id": 2, |
| 138 | + "downloadId": "b", |
| 139 | + "status": "queued", |
| 140 | + "size": 1234, |
| 141 | + "errorMessage": None, |
| 142 | + }, |
| 143 | + { |
| 144 | + "id": 3, |
| 145 | + "downloadId": "c", |
| 146 | + "status": "downloading", |
| 147 | + "size": 0, |
| 148 | + "errorMessage": None, |
| 149 | + }, |
| 150 | + ], |
| 151 | + ["a"], |
| 152 | + ), |
| 153 | + # Enabled: an item matching BOTH the qBit message and size 0 is not duplicated. |
| 154 | + ( |
| 155 | + True, |
| 156 | + [ |
| 157 | + { |
| 158 | + "id": 1, |
| 159 | + "downloadId": "a", |
| 160 | + "status": "queued", |
| 161 | + "size": 0, |
| 162 | + "errorMessage": "qBittorrent is downloading metadata", |
| 163 | + }, |
| 164 | + { |
| 165 | + "id": 2, |
| 166 | + "downloadId": "b", |
| 167 | + "status": "queued", |
| 168 | + "size": 0, |
| 169 | + "errorMessage": None, |
| 170 | + }, |
| 171 | + ], |
| 172 | + ["a", "b"], |
| 173 | + ), |
| 174 | + # Enabled but no size key present (e.g. partial item): not matched. |
| 175 | + ( |
| 176 | + True, |
| 177 | + [ |
| 178 | + {"id": 1, "downloadId": "a", "status": "queued", "errorMessage": None}, |
| 179 | + ], |
| 180 | + [], |
| 181 | + ), |
| 182 | + ], |
| 183 | +) |
| 184 | +async def test_find_affected_items_via_missing_size( |
| 185 | + detect_via_missing_size, queue_data, expected_download_ids |
| 186 | +): |
| 187 | + # Arrange |
| 188 | + removal_job = shared_fix_affected_items(RemoveMetadataMissing, queue_data) |
| 189 | + removal_job.job = MagicMock(detect_via_missing_size=detect_via_missing_size) |
| 190 | + |
| 191 | + # Act and Assert |
| 192 | + await shared_test_affected_items(removal_job, expected_download_ids) |
0 commit comments