From 6410ecd8dc3e8b151ca77e0fa27adf4e2490a774 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Wed, 2 Oct 2024 21:11:28 -0700 Subject: [PATCH] migration test --- .../plugins/test_output_options.py | 107 +++++++++++++++ .../output_options/post_migration.json | 36 +++++ .../plugins/output_options/pre_migration.json | 20 +++ .../plugins/output_options/post_migration.txt | 127 +++++++++++++++++ .../plugins/output_options/pre_migration.txt | 128 ++++++++++++++++++ 5 files changed, 418 insertions(+) create mode 100644 tests/resources/expected_downloads_summaries/plugins/output_options/post_migration.json create mode 100644 tests/resources/expected_downloads_summaries/plugins/output_options/pre_migration.json create mode 100644 tests/resources/transaction_log_summaries/plugins/output_options/post_migration.txt create mode 100644 tests/resources/transaction_log_summaries/plugins/output_options/pre_migration.txt diff --git a/tests/integration/plugins/test_output_options.py b/tests/integration/plugins/test_output_options.py index cde55f32..c4ed9eb9 100644 --- a/tests/integration/plugins/test_output_options.py +++ b/tests/integration/plugins/test_output_options.py @@ -1,7 +1,10 @@ +from pathlib import Path from typing import Dict from unittest.mock import patch import pytest +from mergedeep import mergedeep + from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches @@ -32,6 +35,110 @@ def output_options_subscription_dict(output_directory) -> Dict: class TestOutputOptions: + + @classmethod + def _ensure_subscription_migrates( + cls, + config: ConfigFile, + subscription_name: str, + subscription_dict: Dict, + output_directory: Path, + ): + # Ensure download archive migrates + mergedeep.merge( + subscription_dict, + { + "output_options": { + "migrated_download_archive_name": ".ytdl-sub-{tv_show_name_sanitized}-download-archive.json" + } + }, + ) + migrated_subscription = Subscription.from_dict( + config=config, + preset_name=subscription_name, + preset_dict=subscription_dict, + ) + transaction_log = migrated_subscription.download() + + assert_transaction_log_matches( + output_directory=output_directory, + transaction_log=transaction_log, + transaction_log_summary_file_name="youtube/test_playlist_archive_migrated.txt", + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=False, + expected_download_summary_file_name="youtube/test_playlist_archive_migrated.json", + ) + + # Ensure no changes after migration + transaction_log = migrated_subscription.download() + assert transaction_log.is_empty + assert_expected_downloads( + output_directory=output_directory, + dry_run=False, + expected_download_summary_file_name="youtube/test_playlist_archive_migrated.json", + ) + + def test_download_archive_migration( + self, + config: ConfigFile, + subscription_name: str, + output_options_subscription_dict: Dict, + output_directory: str, + mock_download_collection_entries, + ): + subscription = Subscription.from_dict( + config=config, + preset_name=subscription_name, + preset_dict=output_options_subscription_dict, + ) + + with mock_download_collection_entries( + is_youtube_channel=False, + num_urls=1, + is_extracted_audio=False, + is_dry_run=False, + ): + transaction_log = 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/pre_migration.txt", + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=False, + expected_download_summary_file_name="plugins/output_options/pre_migration.json", + ) + + output_options_subscription_dict["output_options"]["migrated_download_archive_name"] = ".ytdl-sub-{tv_show_name_sanitized}-migrated-download-archive.json" + subscription = Subscription.from_dict( + config=config, + preset_name=subscription_name, + preset_dict=output_options_subscription_dict, + ) + + with mock_download_collection_entries( + is_youtube_channel=False, + num_urls=1, + is_extracted_audio=False, + is_dry_run=False, + ): + transaction_log = 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/post_migration.txt", + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=False, + expected_download_summary_file_name="plugins/output_options/post_migration.json", + ) + @pytest.mark.parametrize("dry_run", [True, False]) def test_empty_info_json_and_thumb( self, diff --git a/tests/resources/expected_downloads_summaries/plugins/output_options/post_migration.json b/tests/resources/expected_downloads_summaries/plugins/output_options/post_migration.json new file mode 100644 index 00000000..1b4adc0d --- /dev/null +++ b/tests/resources/expected_downloads_summaries/plugins/output_options/post_migration.json @@ -0,0 +1,36 @@ +{ + ".ytdl-sub-JMC-migrated-download-archive.json": "66de2cc62b86fb0cdae8a2085a35412b", + "Season 2020/s2020.e000001 - Mock Entry 20-3-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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 2020/s2020.e000005 - Mock Entry 20-1-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "Season 2020/s2020.e000005 - Mock Entry 20-1.info.json": "INFO_JSON", + "Season 2020/s2020.e000005 - Mock Entry 20-1.mp4": "619fe168c38daad37bf1e3e5e063f5c9", + "Season 2020/s2020.e000005 - Mock Entry 20-1.nfo": "1d136ac5b5debe51ea4f9bfeeb5a7b2a", + "Season 2020/s2020.e000005 - Mock Entry 20-2-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "Season 2020/s2020.e000005 - Mock Entry 20-2.info.json": "INFO_JSON", + "Season 2020/s2020.e000005 - Mock Entry 20-2.mp4": "724f018060e3bb74a2cec6f9acb23663", + "Season 2020/s2020.e000005 - Mock Entry 20-2.nfo": "69a1dc9d7b2517a01cfb35c85872fac0", + "Season 2020/s2020.e000005 - Mock Entry 20-3-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "Season 2020/s2020.e000005 - Mock Entry 20-3.info.json": "INFO_JSON", + "Season 2020/s2020.e000005 - Mock Entry 20-3.mp4": "b48150a340c3454824042ae283c5195a", + "Season 2020/s2020.e000005 - Mock Entry 20-3.nfo": "8cd9c68536a56bc1c877f6e6203e6bfd", + "Season 2021/s2021.e000004 - Mock Entry 21-1-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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", + "Season 2021/s2021.e000005 - Mock Entry 21-1-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "Season 2021/s2021.e000005 - Mock Entry 21-1.info.json": "INFO_JSON", + "Season 2021/s2021.e000005 - Mock Entry 21-1.mp4": "a6fd7345d046f697c2e71e378d328a8c", + "Season 2021/s2021.e000005 - Mock Entry 21-1.nfo": "f5ee75ac3d6f28f6bb84bbf2d4f638aa", + "tvshow.nfo": "cccca1086b41af04d8ea004b1aa250e8" +} \ No newline at end of file diff --git a/tests/resources/expected_downloads_summaries/plugins/output_options/pre_migration.json b/tests/resources/expected_downloads_summaries/plugins/output_options/pre_migration.json new file mode 100644 index 00000000..61c1c924 --- /dev/null +++ b/tests/resources/expected_downloads_summaries/plugins/output_options/pre_migration.json @@ -0,0 +1,20 @@ +{ + ".ytdl-sub-subscription_test-download-archive.json": "456d8882fc5e35d74f19b386d1d9a059", + "Season 2020/s2020.e000001 - Mock Entry 20-3-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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-thumb.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "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/post_migration.txt b/tests/resources/transaction_log_summaries/plugins/output_options/post_migration.txt new file mode 100644 index 00000000..d0b4bae2 --- /dev/null +++ b/tests/resources/transaction_log_summaries/plugins/output_options/post_migration.txt @@ -0,0 +1,127 @@ +Files created: +---------------------------------------- +{output_directory} + .ytdl-sub-JMC-migrated-download-archive.json +{output_directory}/Season 2020 + s2020.e000005 - Mock Entry 20-1-thumb.jpg + s2020.e000005 - Mock Entry 20-1.info.json + s2020.e000005 - Mock Entry 20-1.mp4 + Video Tags: + contentRating: TV-14 + date: 2020-08-08 + episode_id: 5 + genre: ytdl-sub + show: JMC + synopsis: + https://20-1.com + + The Description + title: 2020-08-08 - Mock Entry 20-1 + year: 2020 + s2020.e000005 - Mock Entry 20-1.nfo + NFO tags: + episodedetails: + aired: 2020-08-08 + episode: 5 + 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 + s2020.e000005 - Mock Entry 20-2-thumb.jpg + s2020.e000005 - Mock Entry 20-2.info.json + s2020.e000005 - Mock Entry 20-2.mp4 + Video Tags: + contentRating: TV-14 + date: 2020-08-08 + episode_id: 5 + genre: ytdl-sub + show: JMC + synopsis: + https://20-2.com + + The Description + title: 2020-08-08 - Mock Entry 20-2 + year: 2020 + s2020.e000005 - Mock Entry 20-2.nfo + NFO tags: + episodedetails: + aired: 2020-08-08 + episode: 5 + 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.e000005 - Mock Entry 20-3-thumb.jpg + s2020.e000005 - Mock Entry 20-3.info.json + s2020.e000005 - Mock Entry 20-3.mp4 + Video Tags: + contentRating: TV-14 + date: 2020-08-07 + episode_id: 5 + genre: ytdl-sub + show: JMC + synopsis: + https://20-3.com + + The Description + title: 2020-08-07 - Mock Entry 20-3 + year: 2020 + s2020.e000005 - Mock Entry 20-3.nfo + NFO tags: + episodedetails: + aired: 2020-08-07 + episode: 5 + 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 +{output_directory}/Season 2021 + s2021.e000005 - Mock Entry 21-1-thumb.jpg + s2021.e000005 - Mock Entry 21-1.info.json + s2021.e000005 - Mock Entry 21-1.mp4 + Video Tags: + contentRating: TV-14 + date: 2021-08-08 + episode_id: 5 + genre: ytdl-sub + show: JMC + synopsis: + https://21-1.com + + The Description + title: 2021-08-08 - Mock Entry 21-1 + year: 2021 + s2021.e000005 - Mock Entry 21-1.nfo + NFO tags: + episodedetails: + aired: 2021-08-08 + episode: 5 + 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 + +Files removed: +---------------------------------------- +{output_directory} + .ytdl-sub-subscription_test-download-archive.json \ No newline at end of file diff --git a/tests/resources/transaction_log_summaries/plugins/output_options/pre_migration.txt b/tests/resources/transaction_log_summaries/plugins/output_options/pre_migration.txt new file mode 100644 index 00000000..91954dec --- /dev/null +++ b/tests/resources/transaction_log_summaries/plugins/output_options/pre_migration.txt @@ -0,0 +1,128 @@ +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-thumb.jpg + 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-thumb.jpg + 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-thumb.jpg + 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-thumb.jpg + 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