test(torrent_api): fix priority in mock tests
Torrent API CI / build (push) Successful in 29s
Torrent API CI / test (push) Successful in 16s
Torrent API CI / lint (push) Successful in 9s
Torrent API CI / install (vivohost) (push) Successful in 3s
Torrent API CI / install (quiethost) (push) Successful in 3s
Torrent API CI / install (serverhost) (push) Successful in 2s
Torrent API CI / install (mediahost) (push) Successful in 2s

This commit is contained in:
Lucas Vivo committed 2026-11-23 14:37:37 +01:00
1 parent e889a4dc73
commit 9caa2c10bc
2 files changed
+15 -10

No files matched your search

+5 -2
View File
@@ -51,12 +51,15 @@ class MainTest(unittest.TestCase):
@patch.dict("os.environ", {}, clear=True)
@patch("sys.argv", ["torrent-api"])
def test_cli_requires_keys(self):
with contextlib.redirect_stderr(io.StringIO()) as stderr:
@patch("torrent_api.cli.setup_logging")
def test_cli_requires_keys(self, setup_logging):
with self.assertLogs("torrent_api.cli", level="ERROR") as logs, \
contextlib.redirect_stderr(io.StringIO()) as stderr:
with self.assertRaises(SystemExit) as error:
main()
self.assertEqual(error.exception.code, 2)
self.assertIn("Set QBITTORRENT_PRIVATE_API_KEY", stderr.getvalue())
self.assertIn("Required qBittorrent API keys are not set", logs.output[0])
def test_debug_entry_point_shows_help(self):
project_dir = Path(__file__).resolve().parents[1]
+10 -8
View File
@@ -68,8 +68,9 @@ class TorrentHelpersTest(unittest.TestCase):
def test_contents_by_name_or_hash(self, get_torrents, get):
get_torrents.return_value = self.torrents
get.return_value.json.return_value = [
{"name": "folder/file.txt", "progress": 1.0},
{"name": "partial.txt", "progress": 0.5},
{"name": "folder/file.txt", "progress": 1.0, "priority": 1},
{"name": "partial.txt", "progress": 0.5, "priority": 1},
{"name": "skipped.txt", "progress": 1.0, "priority": 0},
]
for identifier in ("first", "a"):
with self.subTest(identifier=identifier):
@@ -80,6 +81,7 @@ class TorrentHelpersTest(unittest.TestCase):
self.assertIn("folder/file.txt Progress: 100%", output.getvalue())
self.assertIn("partial.txt", output.getvalue())
self.assertIn("Progress: 50%", output.getvalue())
self.assertNotIn("skipped.txt", output.getvalue())
get.assert_called_with(
"http://localhost:8080/api/v2/torrents/files",
params={"hash": "a"},
@@ -100,8 +102,8 @@ class TorrentHelpersTest(unittest.TestCase):
(source / "torrent" / "partial.txt").write_text("partial")
get_torrents.return_value = [{**self.torrents[0], "save_path": str(source)}]
get.return_value.json.return_value = [
{"name": "torrent/complete.txt", "progress": 1.0},
{"name": "torrent/partial.txt", "progress": 0.5},
{"name": "torrent/complete.txt", "progress": 1.0, "priority": 1},
{"name": "torrent/partial.txt", "progress": 0.5, "priority": 1},
]
self.instance.show_and_copy_torrent_contents(
@@ -127,7 +129,7 @@ class TorrentHelpersTest(unittest.TestCase):
get_torrents.return_value = [
{**self.torrents[0], "save_path": "/downloads/public/subdir"}
]
get.return_value.json.return_value = [{"name": "torrent/complete.txt", "progress": 1.0}]
get.return_value.json.return_value = [{"name": "torrent/complete.txt", "progress": 1.0, "priority": 1}]
self.instance.show_and_copy_torrent_contents("a", copy_to=destination)
@@ -138,7 +140,7 @@ class TorrentHelpersTest(unittest.TestCase):
def test_contents_dry_run_uses_mapped_path(self, get_torrents, get):
self.instance.path_mappings = {"/downloads-public": "/host/downloads"}
get_torrents.return_value = [{**self.torrents[0], "save_path": "/downloads-public/subdir"}]
get.return_value.json.return_value = [{"name": "complete.txt", "progress": 1.0}]
get.return_value.json.return_value = [{"name": "complete.txt", "progress": 1.0, "priority": 1}]
with self.assertLogs(qbittorrent.logger, level="DEBUG") as logs:
self.instance.show_and_copy_torrent_contents("a", copy_to="/copied", dry_run=True)
@@ -162,7 +164,7 @@ class TorrentHelpersTest(unittest.TestCase):
root = Path(temporary_directory)
destination = root / "copied"
get_torrents.return_value = [{**self.torrents[0], "save_path": "/downloads"}]
get.return_value.json.return_value = [{"name": "folder/complete.txt", "progress": 1.0}]
get.return_value.json.return_value = [{"name": "folder/complete.txt", "progress": 1.0, "priority": 1}]
with self.assertLogs(qbittorrent.logger, level="DEBUG") as logs:
self.instance.show_and_copy_torrent_contents(
@@ -187,7 +189,7 @@ class TorrentHelpersTest(unittest.TestCase):
):
get_torrents.return_value = [{**self.torrents[0], "save_path": "/downloads"}]
get.return_value.json.return_value = [
{"name": "complete.txt", "progress": 1.0},
{"name": "complete.txt", "progress": 1.0, "priority": 1},
]
with self.assertRaisesRegex(RuntimeError, "qBittorrent host is not local"):