diff --git a/torrent_api/tests/test_main.py b/torrent_api/tests/test_main.py index 7d54748..feb5af0 100644 --- a/torrent_api/tests/test_main.py +++ b/torrent_api/tests/test_main.py @@ -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] diff --git a/torrent_api/tests/test_qbittorrent.py b/torrent_api/tests/test_qbittorrent.py index 8c89f4c..26d0fe1 100644 --- a/torrent_api/tests/test_qbittorrent.py +++ b/torrent_api/tests/test_qbittorrent.py @@ -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"):