From 93fb3c1aa3550fa2d8646b22d7253f0802bdf76e Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sat, 1 Oct 2022 10:40:07 -0700 Subject: [PATCH] compilation tests --- .../tv_show/tv_show_type.yaml | 10 +- .../prebuilt_presets/test_prebuilt_presets.py | 164 ++++++++++++++---- 2 files changed, 137 insertions(+), 37 deletions(-) diff --git a/src/ytdl_sub/prebuilt_presets/tv_show/tv_show_type.yaml b/src/ytdl_sub/prebuilt_presets/tv_show/tv_show_type.yaml index 8466f6b8..3b1bfbd4 100644 --- a/src/ytdl_sub/prebuilt_presets/tv_show/tv_show_type.yaml +++ b/src/ytdl_sub/prebuilt_presets/tv_show/tv_show_type.yaml @@ -28,7 +28,7 @@ presets: season_number: "{collection_season_number}" season_number_padded: "{collection_season_number_padded}" - tv_show_collection_season_1: + collection_season_1: generic: urls: - url: "{collection_season_1_url}" @@ -52,7 +52,7 @@ presets: attributes: number: "1" - tv_show_collection_season_2: + collection_season_2: generic: urls: - url: "{collection_season_2_url}" @@ -70,7 +70,7 @@ presets: attributes: number: "2" - tv_show_collection_season_3: + collection_season_3: generic: urls: - url: "{collection_season_3_url}" @@ -88,7 +88,7 @@ presets: attributes: number: "3" - tv_show_collection_season_4: + collection_season_4: generic: urls: - url: "{collection_season_4_url}" @@ -106,7 +106,7 @@ presets: attributes: number: "4" - tv_show_collection_season_5: + collection_season_5: generic: urls: - url: "{collection_season_5_url}" diff --git a/tests/unit/prebuilt_presets/test_prebuilt_presets.py b/tests/unit/prebuilt_presets/test_prebuilt_presets.py index ac1283ca..32404528 100644 --- a/tests/unit/prebuilt_presets/test_prebuilt_presets.py +++ b/tests/unit/prebuilt_presets/test_prebuilt_presets.py @@ -1,3 +1,4 @@ +import copy from typing import Dict from typing import List @@ -9,25 +10,70 @@ from ytdl_sub.prebuilt_presets.tv_show import PrebuiltJellyfinTVShowPresets from ytdl_sub.prebuilt_presets.tv_show import PrebuiltKodiTVShowPresets from ytdl_sub.prebuilt_presets.tv_show import PrebuiltPlexTVShowPresets from ytdl_sub.subscriptions.subscription import Subscription +from ytdl_sub.utils.exceptions import ValidationException +@pytest.mark.parametrize( + "media_player_preset", + [ + "kodi_tv_show_url", + "jellyfin_tv_show_url", + "plex_tv_show_url", + ], +) +@pytest.mark.parametrize( + "tv_show_structure_preset", + [ + "season_by_year__episode_by_month_day", + "season_by_year__episode_by_month_day_reversed", + "season_by_year_month__episode_by_day", + ], +) class TestPrebuiltTVShowPresets: - @pytest.mark.parametrize( - "media_player_preset", - [ - "kodi_tv_show_url", - "jellyfin_tv_show_url", - "plex_tv_show_url", - ], - ) - @pytest.mark.parametrize( - "tv_show_structure_preset", - [ - "season_by_year__episode_by_month_day", - "season_by_year__episode_by_month_day_reversed", - "season_by_year_month__episode_by_day", - ], - ) + def test_compilation( + self, + config, + media_player_preset: str, + tv_show_structure_preset: str, + ): + parent_presets: List[str] = [media_player_preset, tv_show_structure_preset] + _ = Subscription.from_dict( + config=config, + preset_name="preset_test", + preset_dict={ + "preset": parent_presets, + "overrides": { + "url": "https://your.name.here", + "tv_show_name": "test-compile", + "tv_show_directory": "output_dir", + }, + }, + ) + + def test_compilation_errors_missing_one( + self, + config, + media_player_preset: str, + tv_show_structure_preset: str, + ): + parent_presets: List[str] = [media_player_preset, tv_show_structure_preset] + for parent_preset in parent_presets: + parent_presets_missing_one = copy.deepcopy(parent_presets).remove(parent_preset) + + with pytest.raises(ValidationException): + _ = Subscription.from_dict( + config=config, + preset_name="preset_test", + preset_dict={ + "preset": parent_presets_missing_one, + "overrides": { + "url": "https://your.name.here", + "tv_show_name": "test-compile", + "tv_show_directory": "output_dir", + }, + }, + ) + @pytest.mark.parametrize("is_youtube_channel", [True, False]) def test_non_collection_presets_compile( self, @@ -75,21 +121,75 @@ class TestPrebuiltTVShowPresets: regenerate_expected_download_summary=True, ) - @pytest.mark.parametrize( - "media_player_preset", - [ - "kodi_tv_show_collection", - "jellyfin_tv_show_collection", - "plex_tv_show_collection", - ], - ) - @pytest.mark.parametrize( - "tv_show_structure_preset", - [ - "season_by_collection__episode_by_year_month_day", - "season_by_collection__episode_by_year_month_day_reversed", - ], - ) + +@pytest.mark.parametrize( + "media_player_preset", + [ + "kodi_tv_show_collection", + "jellyfin_tv_show_collection", + "plex_tv_show_collection", + ], +) +@pytest.mark.parametrize( + "tv_show_structure_preset", + [ + "season_by_collection__episode_by_year_month_day", + "season_by_collection__episode_by_year_month_day_reversed", + ], +) +class TestPrebuiltTvShowCollectionPresets: + @pytest.mark.parametrize("season_preset", ["collection_season_1", "collection_season_2"]) + def test_compilation( + self, + config, + media_player_preset: str, + tv_show_structure_preset: str, + season_preset: str, + ): + parent_presets: List[str] = [media_player_preset, tv_show_structure_preset, season_preset] + _ = Subscription.from_dict( + config=config, + preset_name="preset_test", + preset_dict={ + "preset": parent_presets, + "overrides": { + "url": "https://your.name.here", + "tv_show_name": "test-compile", + "tv_show_directory": "output_dir", + f"{season_preset}_url": "https://your.name.here", + f"{season_preset}_name": "test season name", + }, + }, + ) + + @pytest.mark.parametrize("season_preset", ["collection_season_1", "collection_season_2"]) + def test_compilation_errors_missing_one( + self, + config, + media_player_preset: str, + tv_show_structure_preset: str, + season_preset: str, + ): + parent_presets: List[str] = [media_player_preset, tv_show_structure_preset, season_preset] + for parent_preset in parent_presets: + parent_presets_missing_one = copy.deepcopy(parent_presets).remove(parent_preset) + + with pytest.raises(ValidationException): + _ = Subscription.from_dict( + config=config, + preset_name="preset_test", + preset_dict={ + "preset": parent_presets_missing_one, + "overrides": { + "url": "https://your.name.here", + "tv_show_name": "test-compile", + "tv_show_directory": "output_dir", + f"{season_preset}_url": "https://your.name.here", + f"{season_preset}_name": "test season name", + }, + }, + ) + @pytest.mark.parametrize("season_indices", [[1], [1, 2]]) @pytest.mark.parametrize("is_youtube_channel", [True, False]) def test_collection_presets_compile( @@ -113,7 +213,7 @@ class TestPrebuiltTVShowPresets: overrides: Dict[str, str] = {} for season_index in season_indices: - parent_presets.append(f"tv_show_collection_season_{season_index}") + parent_presets.append(f"collection_season_{season_index}") overrides = dict( overrides,