From a44cbc8f5ffc6111703b745b0ca2134f2f9fa3ce Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Wed, 2 Oct 2024 20:23:31 -0700 Subject: [PATCH] [DEV] More OutputOption unit tests --- tests/e2e/youtube/test_video.py | 40 ------ .../plugins/test_output_options.py | 53 ++++++++ .../output_options/test_missing_thumb.json | 16 +++ .../output_options/test_missing_thumb.txt | 124 ++++++++++++++++++ 4 files changed, 193 insertions(+), 40 deletions(-) create mode 100644 tests/resources/expected_downloads_summaries/plugins/output_options/test_missing_thumb.json create mode 100644 tests/resources/transaction_log_summaries/plugins/output_options/test_missing_thumb.txt diff --git a/tests/e2e/youtube/test_video.py b/tests/e2e/youtube/test_video.py index 8753a157..c07fc944 100644 --- a/tests/e2e/youtube/test_video.py +++ b/tests/e2e/youtube/test_video.py @@ -70,46 +70,6 @@ class TestYoutubeVideo: expected_download_summary_file_name="youtube/test_video.json", ) - def test_single_video_download_missing_thumbnail( - self, - default_config, - single_video_preset_dict, - working_directory, - output_directory, - ): - single_video_subscription = Subscription.from_dict( - config=default_config, - preset_name="music_video_single_video_test", - preset_dict=single_video_preset_dict, - ) - - def delete_entry_thumb(entry: Entry) -> None: - FileHandler.delete(entry.get_download_thumbnail_path()) - try_convert_download_thumbnail(entry=entry) - - # Pretend the thumbnail did not download via returning nothing for its downloaded path - with ( - patch.object(YTDLP, "_EXTRACT_ENTRY_NUM_RETRIES", 1), - patch.object(Entry, "try_get_ytdlp_download_thumbnail_path") as mock_ytdlp_path, - patch( - "ytdl_sub.downloaders.url.downloader.try_convert_download_thumbnail", - side_effect=delete_entry_thumb, - ), - ): - mock_ytdlp_path.return_value = None - transaction_log = single_video_subscription.download(dry_run=False) - - assert_transaction_log_matches( - output_directory=output_directory, - transaction_log=transaction_log, - transaction_log_summary_file_name="youtube/test_video_missing_thumb.txt", - ) - assert_expected_downloads( - output_directory=output_directory, - dry_run=False, - expected_download_summary_file_name="youtube/test_video_missing_thumb.json", - ) - @pytest.mark.parametrize("dry_run", [True, False]) def test_single_video_download_from_cli_dl( self, diff --git a/tests/integration/plugins/test_output_options.py b/tests/integration/plugins/test_output_options.py index e834c793..cde55f32 100644 --- a/tests/integration/plugins/test_output_options.py +++ b/tests/integration/plugins/test_output_options.py @@ -1,11 +1,16 @@ from typing import Dict +from unittest.mock import patch import pytest from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches from ytdl_sub.config.config_file import ConfigFile +from ytdl_sub.downloaders.ytdlp import YTDLP +from ytdl_sub.entries.entry import Entry from ytdl_sub.subscriptions.subscription import Subscription +from ytdl_sub.utils.file_handler import FileHandler +from ytdl_sub.utils.thumbnail import try_convert_download_thumbnail @pytest.fixture @@ -64,3 +69,51 @@ class TestOutputOptions: dry_run=dry_run, expected_download_summary_file_name="plugins/output_options/empty_info_json_thumb.json", ) + + def test_missing_thumbnail( + self, + config: ConfigFile, + subscription_name: str, + output_options_subscription_dict: Dict, + working_directory, + output_directory, + mock_download_collection_entries, + ): + single_video_subscription = Subscription.from_dict( + config=config, + preset_name=subscription_name, + preset_dict=output_options_subscription_dict, + ) + + def delete_entry_thumb(entry: Entry) -> None: + FileHandler.delete(entry.get_download_thumbnail_path()) + try_convert_download_thumbnail(entry=entry) + + # Pretend the thumbnail did not download via returning nothing for its downloaded path + with ( + mock_download_collection_entries( + is_youtube_channel=False, + num_urls=1, + is_extracted_audio=False, + is_dry_run=False, + ), + patch.object(YTDLP, "_EXTRACT_ENTRY_NUM_RETRIES", 1), + patch.object(Entry, "try_get_ytdlp_download_thumbnail_path") as mock_ytdlp_path, + patch( + "ytdl_sub.downloaders.url.downloader.try_convert_download_thumbnail", + side_effect=delete_entry_thumb, + ), + ): + mock_ytdlp_path.return_value = None + transaction_log = single_video_subscription.download(dry_run=False) + + assert_transaction_log_matches( + output_directory=output_directory, + transaction_log=transaction_log, + transaction_log_summary_file_name="plugins/output_options/test_missing_thumb.txt", + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=False, + expected_download_summary_file_name="plugins/output_options/test_missing_thumb.json", + ) diff --git a/tests/resources/expected_downloads_summaries/plugins/output_options/test_missing_thumb.json b/tests/resources/expected_downloads_summaries/plugins/output_options/test_missing_thumb.json new file mode 100644 index 00000000..21967d07 --- /dev/null +++ b/tests/resources/expected_downloads_summaries/plugins/output_options/test_missing_thumb.json @@ -0,0 +1,16 @@ +{ + ".ytdl-sub-subscription_test-download-archive.json": "e049068ba7f5bdc27c474b18f4c6b402", + "Season 2020/s2020.e000001 - Mock Entry 20-3.info.json": "INFO_JSON", + "Season 2020/s2020.e000001 - Mock Entry 20-3.mp4": "7d2ee7fe8003ea63ece37dd2a441c123", + "Season 2020/s2020.e000001 - Mock Entry 20-3.nfo": "dbe61f2c8ae41041773f713ba5376726", + "Season 2020/s2020.e000002 - Mock Entry 20-2.info.json": "INFO_JSON", + "Season 2020/s2020.e000002 - Mock Entry 20-2.mp4": "699017cd1b67ae216eda769bef413415", + "Season 2020/s2020.e000002 - Mock Entry 20-2.nfo": "0f071078c9fa2569bbcb998664d40681", + "Season 2020/s2020.e000003 - Mock Entry 20-1.info.json": "INFO_JSON", + "Season 2020/s2020.e000003 - Mock Entry 20-1.mp4": "a16741d4fbf657d1de4c50493db14062", + "Season 2020/s2020.e000003 - Mock Entry 20-1.nfo": "837a61dca11bbe1874ea07cb8ef8a7c9", + "Season 2021/s2021.e000004 - Mock Entry 21-1.info.json": "INFO_JSON", + "Season 2021/s2021.e000004 - Mock Entry 21-1.mp4": "7433153952b069a5674e2a3ed529b49b", + "Season 2021/s2021.e000004 - Mock Entry 21-1.nfo": "8ee3845c514a411425b7e9198666b61c", + "tvshow.nfo": "cccca1086b41af04d8ea004b1aa250e8" +} \ No newline at end of file diff --git a/tests/resources/transaction_log_summaries/plugins/output_options/test_missing_thumb.txt b/tests/resources/transaction_log_summaries/plugins/output_options/test_missing_thumb.txt new file mode 100644 index 00000000..7d0a1d58 --- /dev/null +++ b/tests/resources/transaction_log_summaries/plugins/output_options/test_missing_thumb.txt @@ -0,0 +1,124 @@ +Files created: +---------------------------------------- +{output_directory} + .ytdl-sub-subscription_test-download-archive.json + tvshow.nfo + NFO tags: + tvshow: + genre: ytdl-sub + mpaa: TV-14 + title: JMC +{output_directory}/Season 2020 + s2020.e000001 - Mock Entry 20-3.info.json + s2020.e000001 - Mock Entry 20-3.mp4 + Video Tags: + contentRating: TV-14 + date: 2020-08-07 + episode_id: 1 + genre: ytdl-sub + show: JMC + synopsis: + https://20-3.com + + The Description + title: 2020-08-07 - Mock Entry 20-3 + year: 2020 + s2020.e000001 - Mock Entry 20-3.nfo + NFO tags: + episodedetails: + aired: 2020-08-07 + episode: 1 + genre: ytdl-sub + mpaa: TV-14 + plot: + https://20-3.com + + The Description + season: 2020 + title: 2020-08-07 - Mock Entry 20-3 + year: 2020 + s2020.e000002 - Mock Entry 20-2.info.json + s2020.e000002 - Mock Entry 20-2.mp4 + Video Tags: + contentRating: TV-14 + date: 2020-08-08 + episode_id: 2 + genre: ytdl-sub + show: JMC + synopsis: + https://20-2.com + + The Description + title: 2020-08-08 - Mock Entry 20-2 + year: 2020 + s2020.e000002 - Mock Entry 20-2.nfo + NFO tags: + episodedetails: + aired: 2020-08-08 + episode: 2 + genre: ytdl-sub + mpaa: TV-14 + plot: + https://20-2.com + + The Description + season: 2020 + title: 2020-08-08 - Mock Entry 20-2 + year: 2020 + s2020.e000003 - Mock Entry 20-1.info.json + s2020.e000003 - Mock Entry 20-1.mp4 + Video Tags: + contentRating: TV-14 + date: 2020-08-08 + episode_id: 3 + genre: ytdl-sub + show: JMC + synopsis: + https://20-1.com + + The Description + title: 2020-08-08 - Mock Entry 20-1 + year: 2020 + s2020.e000003 - Mock Entry 20-1.nfo + NFO tags: + episodedetails: + aired: 2020-08-08 + episode: 3 + genre: ytdl-sub + mpaa: TV-14 + plot: + https://20-1.com + + The Description + season: 2020 + title: 2020-08-08 - Mock Entry 20-1 + year: 2020 +{output_directory}/Season 2021 + s2021.e000004 - Mock Entry 21-1.info.json + s2021.e000004 - Mock Entry 21-1.mp4 + Video Tags: + contentRating: TV-14 + date: 2021-08-08 + episode_id: 4 + genre: ytdl-sub + show: JMC + synopsis: + https://21-1.com + + The Description + title: 2021-08-08 - Mock Entry 21-1 + year: 2021 + s2021.e000004 - Mock Entry 21-1.nfo + NFO tags: + episodedetails: + aired: 2021-08-08 + episode: 4 + genre: ytdl-sub + mpaa: TV-14 + plot: + https://21-1.com + + The Description + season: 2021 + title: 2021-08-08 - Mock Entry 21-1 + year: 2021 \ No newline at end of file