[DEV] Test-case for subscription with existing download archive (#819)

This commit is contained in:
Jesse Bannon 2023-11-16 23:37:24 -08:00 committed by GitHub
parent c7fce5dbdd
commit 6123e35c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 192 additions and 4 deletions

View file

@ -14,6 +14,9 @@ from unittest.mock import patch
import pytest
from expected_download import _get_files_in_directory
from resources import copy_file_fixture
from resources import file_fixture_path
from yt_dlp.utils import sanitize_filename
from ytdl_sub.config.config_file import ConfigFile
from ytdl_sub.subscriptions.subscription_download import SubscriptionDownload
@ -67,13 +70,13 @@ def working_directory() -> str:
@pytest.fixture()
def output_directory() -> Path:
def output_directory() -> str:
with tempfile.TemporaryDirectory() as temp_dir:
yield temp_dir
@pytest.fixture()
def reformat_directory() -> Path:
def reformat_directory() -> str:
with tempfile.TemporaryDirectory() as temp_dir:
yield temp_dir
@ -163,6 +166,38 @@ def preset_dict_to_subscription_yaml_generator() -> Callable:
return _preset_dict_to_subscription_yaml_generator
###################################################################################################
# Staging a mock already-existing download
@pytest.fixture
def pz_channel_mock_downloaded_with_archive_factory(output_directory: Path) -> Callable:
def _pz_channel_mock_downloaded_with_archive_factory(tv_show_name: str, archive_file_name: str):
subscription_path = Path(output_directory) / sanitize_filename(tv_show_name)
copy_file_fixture(
fixture_name="pz_download_archive.json",
output_file_path=subscription_path / archive_file_name,
)
with open(
file_fixture_path("pz_download_archive.json"), "r", encoding="utf-8"
) as archive_file:
archive_dict = json.load(archive_file)
assert isinstance(archive_dict, dict)
for uid, metadata in archive_dict.items():
assert isinstance(metadata, dict)
for filename in metadata["file_names"]:
assert isinstance(filename, str)
output_file_path = subscription_path / filename
if filename.endswith(".mp4"):
copy_file_fixture("sample_vid.mp4", output_file_path)
else:
copy_file_fixture("empty.txt", output_file_path)
return _pz_channel_mock_downloaded_with_archive_factory
###################################################################################################
# Example config fixtures

View file

@ -1,7 +1,11 @@
from typing import Callable
from typing import Dict
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.subscriptions.subscription import Subscription
@ -65,3 +69,22 @@ class TestChannel:
dry_run=dry_run,
expected_download_summary_file_name="youtube/test_channel_full.json",
)
def test_full_channel_existing_archive_downloads_nothing(
self,
pz_channel_mock_downloaded_with_archive_factory: Callable,
tv_show_config: ConfigFile,
channel_preset_dict: Dict,
):
subscription_name = "pz"
full_channel_subscription = Subscription.from_dict(
config=tv_show_config, preset_name=subscription_name, preset_dict=channel_preset_dict
)
tv_show_name = channel_preset_dict["overrides"]["tv_show_name"]
archive_file_name = f".ytdl-sub-{subscription_name}-download-archive.json"
pz_channel_mock_downloaded_with_archive_factory(
tv_show_name=tv_show_name, archive_file_name=archive_file_name
)
transaction_log = full_channel_subscription.download(dry_run=True)
assert transaction_log.is_empty

View file

@ -11,7 +11,7 @@ _TRANSACTION_LOG_SUMMARY_PATH = RESOURCE_PATH / "transaction_log_summaries"
def assert_transaction_log_matches(
output_directory: Path,
output_directory: Path | str,
transaction_log: FileHandlerTransactionLog,
transaction_log_summary_file_name: str,
):

View file

@ -1,3 +1,4 @@
import os
import shutil
from pathlib import Path
@ -7,5 +8,10 @@ RESOURCE_PATH: Path = Path("tests") / "resources"
_FILE_FIXTURE_PATH: Path = RESOURCE_PATH / "file_fixtures"
def file_fixture_path(fixture_name: str) -> Path:
return _FILE_FIXTURE_PATH / fixture_name
def copy_file_fixture(fixture_name: str, output_file_path: Path) -> None:
shutil.copy(_FILE_FIXTURE_PATH / fixture_name, output_file_path)
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
shutil.copy(file_fixture_path(fixture_name), output_file_path)

View file

@ -0,0 +1 @@
empty

View file

@ -0,0 +1,123 @@
{
"0SVukUyys10": {
"extractor": "youtube",
"file_names": [
"Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1]-thumb.jpg",
"Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].info.json",
"Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].mp4",
"Season 2011/s2011.e020101 - Jesse's Minecraft Server [Trailer - Feb.1].nfo"
],
"upload_date": "2011-02-01"
},
"6sxlggREhMc": {
"extractor": "youtube",
"file_names": [
"Season 2011/s2011.e063001 - Project Zombie \uff5cFin\uff5c-thumb.jpg",
"Season 2011/s2011.e063001 - Project Zombie \uff5cFin\uff5c.info.json",
"Season 2011/s2011.e063001 - Project Zombie \uff5cFin\uff5c.mp4",
"Season 2011/s2011.e063001 - Project Zombie \uff5cFin\uff5c.nfo"
],
"upload_date": "2011-06-30"
},
"DBjFvs6HafU": {
"extractor": "youtube",
"file_names": [
"Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21]-thumb.jpg",
"Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].info.json",
"Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].mp4",
"Season 2011/s2011.e032101 - Jesse's Minecraft Server [Trailer - Mar.21].nfo"
],
"upload_date": "2011-03-21"
},
"HKTNxEqsN3Q": {
"extractor": "youtube",
"file_names": [
"Season 2010/s2010.e081301 - Oblivion Mod \uff02Falcor\uff02 p.1-thumb.jpg",
"Season 2010/s2010.e081301 - Oblivion Mod \uff02Falcor\uff02 p.1.info.json",
"Season 2010/s2010.e081301 - Oblivion Mod \uff02Falcor\uff02 p.1.mp4",
"Season 2010/s2010.e081301 - Oblivion Mod \uff02Falcor\uff02 p.1.nfo"
],
"upload_date": "2010-08-13"
},
"IV9Z4wcA-z8": {
"extractor": "youtube",
"file_names": [
"Season 2010/s2010.e120201 - Oblivion Mod \uff02Falcor\uff02 p.2-thumb.jpg",
"Season 2010/s2010.e120201 - Oblivion Mod \uff02Falcor\uff02 p.2.info.json",
"Season 2010/s2010.e120201 - Oblivion Mod \uff02Falcor\uff02 p.2.mp4",
"Season 2010/s2010.e120201 - Oblivion Mod \uff02Falcor\uff02 p.2.nfo"
],
"upload_date": "2010-12-02"
},
"LN2e6idGluI": {
"extractor": "youtube",
"file_names": [
"Season 2018/s2018.e110201 - Jesse's Minecraft Server \uff5c IP mc.jesse.id-thumb.jpg",
"Season 2018/s2018.e110201 - Jesse's Minecraft Server \uff5c IP mc.jesse.id.en.srt",
"Season 2018/s2018.e110201 - Jesse's Minecraft Server \uff5c IP mc.jesse.id.info.json",
"Season 2018/s2018.e110201 - Jesse's Minecraft Server \uff5c IP mc.jesse.id.mp4",
"Season 2018/s2018.e110201 - Jesse's Minecraft Server \uff5c IP mc.jesse.id.nfo"
],
"upload_date": "2018-11-02"
},
"c_PZdc0Zi7M": {
"extractor": "youtube",
"file_names": [
"Season 2013/s2013.e071901 - Project Zombie Rewind \uff5cTrailer\uff5c-thumb.jpg",
"Season 2013/s2013.e071901 - Project Zombie Rewind \uff5cTrailer\uff5c.info.json",
"Season 2013/s2013.e071901 - Project Zombie Rewind \uff5cTrailer\uff5c.mp4",
"Season 2013/s2013.e071901 - Project Zombie Rewind \uff5cTrailer\uff5c.nfo"
],
"upload_date": "2013-07-19"
},
"hP-PL_V2wR8": {
"extractor": "youtube",
"file_names": [
"Season 2018/s2018.e102901 - Jesse's Minecraft Server \uff5c Teaser Trailer-thumb.jpg",
"Season 2018/s2018.e102901 - Jesse's Minecraft Server \uff5c Teaser Trailer.info.json",
"Season 2018/s2018.e102901 - Jesse's Minecraft Server \uff5c Teaser Trailer.mp4",
"Season 2018/s2018.e102901 - Jesse's Minecraft Server \uff5c Teaser Trailer.nfo"
],
"upload_date": "2018-10-29"
},
"hxV9b-1hjfw": {
"extractor": "youtube",
"file_names": [
"Season 2011/s2011.e052901 - Project Zombie \uff5cOfficial Trailer\uff5c (IP\uff1a mc.projectzombie.beastnode.net)-thumb.jpg",
"Season 2011/s2011.e052901 - Project Zombie \uff5cOfficial Trailer\uff5c (IP\uff1a mc.projectzombie.beastnode.net).info.json",
"Season 2011/s2011.e052901 - Project Zombie \uff5cOfficial Trailer\uff5c (IP\uff1a mc.projectzombie.beastnode.net).mp4",
"Season 2011/s2011.e052901 - Project Zombie \uff5cOfficial Trailer\uff5c (IP\uff1a mc.projectzombie.beastnode.net).nfo"
],
"upload_date": "2011-05-29"
},
"qPybBrXspds": {
"extractor": "youtube",
"file_names": [
"Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27]-thumb.jpg",
"Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].info.json",
"Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].mp4",
"Season 2011/s2011.e022701 - Jesse's Minecraft Server [Trailer - Feb.27].nfo"
],
"upload_date": "2011-02-27"
},
"qbMJh2df1M4": {
"extractor": "youtube",
"file_names": [
"Season 2011/s2011.e112101 - Skyrim 'Ultra HD w\u29f8Mods' [PC]-thumb.jpg",
"Season 2011/s2011.e112101 - Skyrim 'Ultra HD w\u29f8Mods' [PC].info.json",
"Season 2011/s2011.e112101 - Skyrim 'Ultra HD w\u29f8Mods' [PC].mp4",
"Season 2011/s2011.e112101 - Skyrim 'Ultra HD w\u29f8Mods' [PC].nfo"
],
"upload_date": "2011-11-21"
},
"y5-3ovwQQ_U": {
"extractor": "youtube",
"file_names": [
"Season 2012/s2012.e012301 - Project Zombie \uff5cMap Trailer\uff5c-thumb.jpg",
"Season 2012/s2012.e012301 - Project Zombie \uff5cMap Trailer\uff5c.info.json",
"Season 2012/s2012.e012301 - Project Zombie \uff5cMap Trailer\uff5c.mp4",
"Season 2012/s2012.e012301 - Project Zombie \uff5cMap Trailer\uff5c.nfo"
],
"upload_date": "2012-01-23"
}
}