| … | … | @@ -336,3 +336,71 @@ def test_the_player_runs_subtitles_when_only_wyzie_is_enabled(): |
| 336 | 336 | assert body is not None, "handle_subtitles not found in player.py" |
| 337 | 337 | assert "wyzie_subtitle_enabled" in body.group(0), \ |
| 338 | 338 | "handle_subtitles never checks the wyzie setting" |
| 339 | |
| 340 | |
| 341 | class TestIdentFromOriginalId: |
| 342 | """The catalogs that most need this carry no tmdb_id or imdb_id at all. |
| 343 | |
| 344 | Measured on the Pi, playing No Other Choice from the flixlab catalog, the |
| 345 | playback payload was: |
| 346 | |
| 347 | "ids": {"tmdb_id": "", "tvdb_id": "", "imdb_id": "", |
| 348 | "original_id": "fxl:639988"} |
| 349 | |
| 350 | -- empty strings, not missing keys, with the only real id under |
| 351 | `original_id` behind a catalog prefix. So the fetch bailed with "no_imdb" |
| 352 | for exactly the titles the tmdb-or-imdb endpoint was supposed to rescue. |
| 353 | """ |
| 354 | |
| 355 | def test_an_fxl_original_id_yields_the_bare_tmdb_id(self, tmp_path): |
| 356 | m = _manager({"title": "No Other Choice", "mode": "movies", |
| 357 | "ids": {"tmdb_id": "", "imdb_id": "", |
| 358 | "original_id": "fxl:639988"}}) |
| 359 | m.wyzie_client.get_subtitles = MagicMock(return_value=[]) |
| 360 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 361 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 362 | assert m.wyzie_client.get_subtitles.call_args[0][1] == "639988" |
| 363 | |
| 364 | def test_a_tmdb_prefixed_original_id_is_also_stripped(self, tmp_path): |
| 365 | m = _manager({"title": "X", "mode": "movies", |
| 366 | "ids": {"original_id": "tmdb:1396"}}) |
| 367 | m.wyzie_client.get_subtitles = MagicMock(return_value=[]) |
| 368 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 369 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 370 | assert m.wyzie_client.get_subtitles.call_args[0][1] == "1396" |
| 371 | |
| 372 | def test_an_imdb_original_id_is_left_intact(self, tmp_path): |
| 373 | """tt-ids are what the endpoint wants; stripping is only for prefixes.""" |
| 374 | m = _manager({"title": "X", "mode": "movies", |
| 375 | "ids": {"original_id": "tt0903747"}}) |
| 376 | m.wyzie_client.get_subtitles = MagicMock(return_value=[]) |
| 377 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 378 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 379 | assert m.wyzie_client.get_subtitles.call_args[0][1] == "tt0903747" |
| 380 | |
| 381 | def test_a_real_imdb_id_still_wins_over_original_id(self, tmp_path): |
| 382 | m = _manager({"title": "X", "mode": "movies", |
| 383 | "ids": {"imdb_id": "tt31967670", "original_id": "fxl:639988"}}) |
| 384 | m.wyzie_client.get_subtitles = MagicMock(return_value=[]) |
| 385 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 386 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 387 | assert m.wyzie_client.get_subtitles.call_args[0][1] == "tt31967670" |
| 388 | |
| 389 | def test_empty_strings_are_treated_as_absent_not_as_ids(self, tmp_path): |
| 390 | """The keys are PRESENT and empty, so `.get(...)` returns "" and any |
| 391 | check that only tests for None would sail straight past it.""" |
| 392 | m = _manager({"title": "X", "mode": "movies", |
| 393 | "ids": {"tmdb_id": "", "imdb_id": "", "original_id": ""}}) |
| 394 | m.wyzie_client.get_subtitles = MagicMock() |
| 395 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 396 | assert m.fetch_subtitles(folder_path=str(tmp_path)) is None |
| 397 | assert m.last_fetch_status == "no_imdb" |
| 398 | m.wyzie_client.get_subtitles.assert_not_called() |
| 399 | |
| 400 | def test_a_prefixed_non_numeric_id_is_not_mangled(self, tmp_path): |
| 401 | m = _manager({"title": "X", "mode": "movies", |
| 402 | "ids": {"original_id": "kitsu:anime-42"}}) |
| 403 | m.wyzie_client.get_subtitles = MagicMock(return_value=[]) |
| 404 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 405 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 406 | assert m.wyzie_client.get_subtitles.call_args[0][1] == "kitsu:anime-42" |