[DEV] Simple TV Show by Date tests
This commit is contained in:
parent
a3f59d5420
commit
d6c1f12a0f
2 changed files with 153 additions and 221 deletions
|
|
@ -2,241 +2,21 @@ import copy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Optional
|
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from expected_download import assert_expected_downloads
|
from expected_download import assert_expected_downloads
|
||||||
from expected_transaction_log import assert_transaction_log_matches
|
from expected_transaction_log import assert_transaction_log_matches
|
||||||
|
|
||||||
from ytdl_sub.prebuilt_presets.music import MusicPresets
|
from ytdl_sub.prebuilt_presets.music import MusicPresets
|
||||||
from ytdl_sub.prebuilt_presets.music_videos import MusicVideoExtrasPresets
|
|
||||||
from ytdl_sub.prebuilt_presets.music_videos import MusicVideoPresets
|
from ytdl_sub.prebuilt_presets.music_videos import MusicVideoPresets
|
||||||
from ytdl_sub.prebuilt_presets.tv_show import TvShowByDateEpisodeFormattingPresets
|
|
||||||
from ytdl_sub.prebuilt_presets.tv_show import TvShowByDateOldPresets
|
|
||||||
from ytdl_sub.prebuilt_presets.tv_show import TvShowCollectionEpisodeFormattingPresets
|
from ytdl_sub.prebuilt_presets.tv_show import TvShowCollectionEpisodeFormattingPresets
|
||||||
from ytdl_sub.prebuilt_presets.tv_show import TvShowCollectionPresets
|
from ytdl_sub.prebuilt_presets.tv_show import TvShowCollectionPresets
|
||||||
from ytdl_sub.prebuilt_presets.tv_show import TvShowCollectionSeasonPresets
|
from ytdl_sub.prebuilt_presets.tv_show import TvShowCollectionSeasonPresets
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
from ytdl_sub.utils.exceptions import RegexNoMatchException
|
|
||||||
from ytdl_sub.utils.exceptions import ValidationException
|
from ytdl_sub.utils.exceptions import ValidationException
|
||||||
|
|
||||||
|
|
||||||
def _tv_show_by_date_combos() -> List[Tuple[None, str, str]]:
|
|
||||||
combos: List[Tuple[None, str, str]] = []
|
|
||||||
|
|
||||||
for media_player_preset in TvShowByDateOldPresets.preset_names:
|
|
||||||
for tv_show_structure_preset in TvShowByDateEpisodeFormattingPresets.preset_names:
|
|
||||||
combos.append((None, media_player_preset, tv_show_structure_preset))
|
|
||||||
|
|
||||||
return combos
|
|
||||||
|
|
||||||
|
|
||||||
def _tv_show_by_date_parent_presets(
|
|
||||||
all_in_one_preset: Optional[str],
|
|
||||||
media_player_preset: str,
|
|
||||||
tv_show_structured_preset: str,
|
|
||||||
) -> List[str]:
|
|
||||||
"""Hack to include the all_in_one presets in this test suite"""
|
|
||||||
if all_in_one_preset is not None:
|
|
||||||
return [all_in_one_preset]
|
|
||||||
return [
|
|
||||||
media_player_preset,
|
|
||||||
tv_show_structured_preset,
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"all_in_one_preset, media_player_preset, tv_show_structure_preset",
|
|
||||||
[
|
|
||||||
# Test that the all-in-ones are equivalent to using the two underlying ones
|
|
||||||
("Kodi TV Show by Date", "kodi_tv_show_by_date", "season_by_year__episode_by_month_day"),
|
|
||||||
(
|
|
||||||
"Jellyfin TV Show by Date",
|
|
||||||
"jellyfin_tv_show_by_date",
|
|
||||||
"season_by_year__episode_by_month_day",
|
|
||||||
),
|
|
||||||
("Plex TV Show by Date", "plex_tv_show_by_date", "season_by_year__episode_by_month_day"),
|
|
||||||
*_tv_show_by_date_combos(),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
class TestPrebuiltTVShowPresets:
|
|
||||||
def test_compilation(
|
|
||||||
self,
|
|
||||||
config,
|
|
||||||
all_in_one_preset: Optional[str],
|
|
||||||
media_player_preset: str,
|
|
||||||
tv_show_structure_preset: str,
|
|
||||||
):
|
|
||||||
parent_presets = _tv_show_by_date_parent_presets(
|
|
||||||
all_in_one_preset, 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_many_urls(
|
|
||||||
self,
|
|
||||||
config,
|
|
||||||
all_in_one_preset: Optional[str],
|
|
||||||
media_player_preset: str,
|
|
||||||
tv_show_structure_preset: str,
|
|
||||||
):
|
|
||||||
parent_presets = _tv_show_by_date_parent_presets(
|
|
||||||
all_in_one_preset, media_player_preset, tv_show_structure_preset
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = Subscription.from_dict(
|
|
||||||
config=config,
|
|
||||||
preset_name="preset_test",
|
|
||||||
preset_dict={
|
|
||||||
"preset": parent_presets,
|
|
||||||
"download": "https://second.url",
|
|
||||||
"overrides": {
|
|
||||||
"url": "https://your.name.here",
|
|
||||||
"tv_show_name": "test-compile",
|
|
||||||
"tv_show_directory": "output_dir",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_compilation_errors_missing_one(
|
|
||||||
self,
|
|
||||||
config,
|
|
||||||
all_in_one_preset: Optional[str],
|
|
||||||
media_player_preset: str,
|
|
||||||
tv_show_structure_preset: str,
|
|
||||||
):
|
|
||||||
parent_presets = _tv_show_by_date_parent_presets(
|
|
||||||
all_in_one_preset, 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])
|
|
||||||
@pytest.mark.parametrize("is_many_urls", [True, False])
|
|
||||||
def test_non_collection_presets_compile(
|
|
||||||
self,
|
|
||||||
config,
|
|
||||||
subscription_name,
|
|
||||||
output_directory,
|
|
||||||
mock_download_collection_entries,
|
|
||||||
all_in_one_preset: Optional[str],
|
|
||||||
media_player_preset: str,
|
|
||||||
tv_show_structure_preset: str,
|
|
||||||
is_youtube_channel: bool,
|
|
||||||
is_many_urls: bool,
|
|
||||||
):
|
|
||||||
|
|
||||||
expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
|
||||||
media_player_preset,
|
|
||||||
tv_show_structure_preset,
|
|
||||||
int(is_youtube_channel),
|
|
||||||
"_many_urls" if is_many_urls else "",
|
|
||||||
)
|
|
||||||
parent_presets = _tv_show_by_date_parent_presets(
|
|
||||||
all_in_one_preset, media_player_preset, tv_show_structure_preset
|
|
||||||
)
|
|
||||||
|
|
||||||
preset_dict = {
|
|
||||||
"preset": parent_presets,
|
|
||||||
"overrides": {
|
|
||||||
"url": "https://your.name.here",
|
|
||||||
"tv_show_name": "Best Prebuilt TV Show by Date",
|
|
||||||
"tv_show_directory": output_directory,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if is_many_urls:
|
|
||||||
preset_dict["overrides"]["url2"] = "https://url.number.2.here"
|
|
||||||
|
|
||||||
subscription = Subscription.from_dict(
|
|
||||||
config=config,
|
|
||||||
preset_name=subscription_name,
|
|
||||||
preset_dict=preset_dict,
|
|
||||||
)
|
|
||||||
|
|
||||||
with mock_download_collection_entries(
|
|
||||||
is_youtube_channel=is_youtube_channel, num_urls=2 if is_many_urls else 1
|
|
||||||
):
|
|
||||||
transaction_log = subscription.download(dry_run=False)
|
|
||||||
|
|
||||||
assert_transaction_log_matches(
|
|
||||||
output_directory=output_directory,
|
|
||||||
transaction_log=transaction_log,
|
|
||||||
transaction_log_summary_file_name=f"{expected_summary_name}.txt",
|
|
||||||
)
|
|
||||||
assert_expected_downloads(
|
|
||||||
output_directory=output_directory,
|
|
||||||
dry_run=False,
|
|
||||||
expected_download_summary_file_name=f"{expected_summary_name}.json",
|
|
||||||
)
|
|
||||||
|
|
||||||
###################################### Perform reformat
|
|
||||||
reformatted_tv_show_structure_preset = "season_by_year__episode_by_download_index"
|
|
||||||
reformatted_expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
|
||||||
media_player_preset,
|
|
||||||
reformatted_tv_show_structure_preset,
|
|
||||||
int(is_youtube_channel),
|
|
||||||
"_many_urls" if is_many_urls else "",
|
|
||||||
)
|
|
||||||
|
|
||||||
reformatted_preset_dict = {
|
|
||||||
"preset": parent_presets + [reformatted_tv_show_structure_preset],
|
|
||||||
"output_options": {
|
|
||||||
"migrated_download_archive_name": ".ytdl-sub-{tv_show_name_sanitized}-download-archive.json"
|
|
||||||
},
|
|
||||||
"overrides": {
|
|
||||||
"url": "https://your.name.here",
|
|
||||||
"tv_show_name": "Best Prebuilt TV Show by Date",
|
|
||||||
"tv_show_directory": output_directory,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if is_many_urls:
|
|
||||||
reformatted_preset_dict["overrides"]["url2"] = "https://url.number.2.here"
|
|
||||||
|
|
||||||
reformatted_subscription = Subscription.from_dict(
|
|
||||||
config=config, preset_name=subscription_name, preset_dict=reformatted_preset_dict
|
|
||||||
)
|
|
||||||
|
|
||||||
reformatted_transaction_log = reformatted_subscription.update_with_info_json(dry_run=False)
|
|
||||||
assert_transaction_log_matches(
|
|
||||||
output_directory=output_directory,
|
|
||||||
transaction_log=reformatted_transaction_log,
|
|
||||||
transaction_log_summary_file_name=(
|
|
||||||
f"{expected_summary_name}_reformatted_to_{reformatted_tv_show_structure_preset}.txt"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
assert_expected_downloads(
|
|
||||||
output_directory=output_directory,
|
|
||||||
dry_run=False,
|
|
||||||
expected_download_summary_file_name=f"{reformatted_expected_summary_name}_migrated.json",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("media_player_preset", TvShowCollectionPresets.preset_names)
|
@pytest.mark.parametrize("media_player_preset", TvShowCollectionPresets.preset_names)
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
|
||||||
152
tests/integration/prebuilt_presets/test_tv_show_by_date.py
Normal file
152
tests/integration/prebuilt_presets/test_tv_show_by_date.py
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
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.prebuilt_presets.tv_show import TvShowByDateEpisodeFormattingPresets, \
|
||||||
|
TvShowByDatePresets
|
||||||
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
|
|
||||||
|
DEPRECATED_TV_SHOW_PRESET_EQUIVALENTS = {
|
||||||
|
"Kodi TV Show by Date": "kodi_tv_show_by_date",
|
||||||
|
"Kodi TV Show Collection": "kodi_tv_show_collection",
|
||||||
|
"Jellyfin TV Show by Date": "jellyfin_tv_show_by_date",
|
||||||
|
"Jellyfin TV Show Collection": "jellyfin_tv_show_collection",
|
||||||
|
"Plex TV Show by Date": "plex_tv_show_by_date",
|
||||||
|
"Plex TV Show Collection": "plex_tv_show_collection",
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_TV_SHOW_STRUCTURE = "season_by_year__episode_by_month_day"
|
||||||
|
|
||||||
|
class TestPrebuiltTVShowPresets:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(
|
||||||
|
config: ConfigFile,
|
||||||
|
subscription_name: str,
|
||||||
|
output_directory: str,
|
||||||
|
tv_show_preset: str,
|
||||||
|
episode_ordering_preset: str,
|
||||||
|
is_youtube_channel: bool = True,
|
||||||
|
is_many_urls: bool = False,
|
||||||
|
):
|
||||||
|
|
||||||
|
expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
||||||
|
DEPRECATED_TV_SHOW_PRESET_EQUIVALENTS[tv_show_preset],
|
||||||
|
episode_ordering_preset,
|
||||||
|
int(is_youtube_channel),
|
||||||
|
"_many_urls" if is_many_urls else "",
|
||||||
|
)
|
||||||
|
|
||||||
|
preset_dict = {
|
||||||
|
"preset": [tv_show_preset, episode_ordering_preset],
|
||||||
|
"overrides": {
|
||||||
|
"url": "https://your.name.here",
|
||||||
|
"tv_show_name": "Best Prebuilt TV Show by Date",
|
||||||
|
"tv_show_directory": output_directory,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if is_many_urls:
|
||||||
|
preset_dict["overrides"]["url2"] = "https://url.number.2.here"
|
||||||
|
|
||||||
|
subscription = Subscription.from_dict(
|
||||||
|
config=config,
|
||||||
|
preset_name=subscription_name,
|
||||||
|
preset_dict=preset_dict,
|
||||||
|
)
|
||||||
|
|
||||||
|
transaction_log = subscription.download(dry_run=False)
|
||||||
|
|
||||||
|
assert_transaction_log_matches(
|
||||||
|
output_directory=output_directory,
|
||||||
|
transaction_log=transaction_log,
|
||||||
|
transaction_log_summary_file_name=f"{expected_summary_name}.txt",
|
||||||
|
)
|
||||||
|
assert_expected_downloads(
|
||||||
|
output_directory=output_directory,
|
||||||
|
dry_run=False,
|
||||||
|
expected_download_summary_file_name=f"{expected_summary_name}.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
###################################### Perform reformat
|
||||||
|
reformatted_tv_show_structure_preset = "season_by_year__episode_by_download_index"
|
||||||
|
reformatted_expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
||||||
|
DEPRECATED_TV_SHOW_PRESET_EQUIVALENTS[tv_show_preset],
|
||||||
|
reformatted_tv_show_structure_preset,
|
||||||
|
int(is_youtube_channel),
|
||||||
|
"_many_urls" if is_many_urls else "",
|
||||||
|
)
|
||||||
|
|
||||||
|
reformatted_preset_dict = {
|
||||||
|
"preset": [tv_show_preset, reformatted_tv_show_structure_preset],
|
||||||
|
"output_options": {
|
||||||
|
"migrated_download_archive_name": ".ytdl-sub-{tv_show_name_sanitized}-download-archive.json"
|
||||||
|
},
|
||||||
|
"overrides": {
|
||||||
|
"url": "https://your.name.here",
|
||||||
|
"tv_show_name": "Best Prebuilt TV Show by Date",
|
||||||
|
"tv_show_directory": output_directory,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if is_many_urls:
|
||||||
|
reformatted_preset_dict["overrides"]["url2"] = "https://url.number.2.here"
|
||||||
|
|
||||||
|
reformatted_subscription = Subscription.from_dict(
|
||||||
|
config=config, preset_name=subscription_name, preset_dict=reformatted_preset_dict
|
||||||
|
)
|
||||||
|
|
||||||
|
reformatted_transaction_log = reformatted_subscription.update_with_info_json(dry_run=False)
|
||||||
|
assert_transaction_log_matches(
|
||||||
|
output_directory=output_directory,
|
||||||
|
transaction_log=reformatted_transaction_log,
|
||||||
|
transaction_log_summary_file_name=(
|
||||||
|
f"{expected_summary_name}_reformatted_to_{reformatted_tv_show_structure_preset}.txt"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert_expected_downloads(
|
||||||
|
output_directory=output_directory,
|
||||||
|
dry_run=False,
|
||||||
|
expected_download_summary_file_name=f"{reformatted_expected_summary_name}_migrated.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("tv_show_preset", TvShowByDatePresets.preset_names)
|
||||||
|
def test_tv_show_presets(
|
||||||
|
self,
|
||||||
|
config,
|
||||||
|
subscription_name,
|
||||||
|
output_directory,
|
||||||
|
mock_download_collection_entries,
|
||||||
|
tv_show_preset: str,
|
||||||
|
):
|
||||||
|
|
||||||
|
with mock_download_collection_entries(
|
||||||
|
is_youtube_channel=True
|
||||||
|
):
|
||||||
|
self.run(
|
||||||
|
config=config,
|
||||||
|
subscription_name=subscription_name,
|
||||||
|
output_directory=output_directory,
|
||||||
|
tv_show_preset=tv_show_preset,
|
||||||
|
episode_ordering_preset=DEFAULT_TV_SHOW_STRUCTURE,
|
||||||
|
)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("episode_ordering_preset", TvShowByDateEpisodeFormattingPresets.preset_names)
|
||||||
|
def test_episode_ordering_presets(
|
||||||
|
self,
|
||||||
|
config,
|
||||||
|
subscription_name,
|
||||||
|
output_directory,
|
||||||
|
mock_download_collection_entries,
|
||||||
|
episode_ordering_preset: str,
|
||||||
|
):
|
||||||
|
|
||||||
|
with mock_download_collection_entries(
|
||||||
|
is_youtube_channel=True,
|
||||||
|
):
|
||||||
|
self.run(
|
||||||
|
config=config,
|
||||||
|
subscription_name=subscription_name,
|
||||||
|
output_directory=output_directory,
|
||||||
|
tv_show_preset="Kodi TV Show by Date",
|
||||||
|
episode_ordering_preset=episode_ordering_preset,
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue