test
This commit is contained in:
parent
4d093ec571
commit
c5f771faec
5 changed files with 50 additions and 10 deletions
|
|
@ -14,7 +14,9 @@ from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from expected_download import _get_files_in_directory
|
from expected_download import _get_files_in_directory
|
||||||
from resources import copy_file_fixture, file_fixture_path
|
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.config.config_file import ConfigFile
|
||||||
from ytdl_sub.subscriptions.subscription_download import SubscriptionDownload
|
from ytdl_sub.subscriptions.subscription_download import SubscriptionDownload
|
||||||
|
|
@ -68,13 +70,13 @@ def working_directory() -> str:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def output_directory() -> Path:
|
def output_directory() -> str:
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
yield temp_dir
|
yield temp_dir
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def reformat_directory() -> Path:
|
def reformat_directory() -> str:
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
yield temp_dir
|
yield temp_dir
|
||||||
|
|
||||||
|
|
@ -163,25 +165,35 @@ def preset_dict_to_subscription_yaml_generator() -> Callable:
|
||||||
|
|
||||||
return _preset_dict_to_subscription_yaml_generator
|
return _preset_dict_to_subscription_yaml_generator
|
||||||
|
|
||||||
|
|
||||||
###################################################################################################
|
###################################################################################################
|
||||||
# Staging a mock already-existing download
|
# Staging a mock already-existing download
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pz_channel_mock_downloaded_with_archive_factory(output_directory: Path) -> Callable:
|
def pz_channel_mock_downloaded_with_archive_factory(output_directory: Path) -> Callable:
|
||||||
def _pz_channel_mock_downloaded_with_archive_factory(subscription_name: str, download_archive_file_name: str):
|
def _pz_channel_mock_downloaded_with_archive_factory(tv_show_name: str, archive_file_name: str):
|
||||||
copy_file_fixture(fixture_name="pz_download_archive.json", output_file_path=output_directory / download_archive_file_name)
|
subscription_path = Path(output_directory) / sanitize_filename(tv_show_name)
|
||||||
with open(file_fixture_path("pz_download_archive.json"), "r", encoding="utf-8") as archive_file:
|
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)
|
archive_dict = json.load(archive_file)
|
||||||
|
|
||||||
assert isinstance(archive_dict, dict)
|
assert isinstance(archive_dict, dict)
|
||||||
for uid, metadata in archive_dict.items():
|
for uid, metadata in archive_dict.items():
|
||||||
assert isinstance(metadata, dict)
|
assert isinstance(metadata, dict)
|
||||||
for filename in metadata['file_names']:
|
for filename in metadata["file_names"]:
|
||||||
assert isinstance(filename, str)
|
assert isinstance(filename, str)
|
||||||
|
output_file_path = subscription_path / filename
|
||||||
if filename.endswith(".mp4"):
|
if filename.endswith(".mp4"):
|
||||||
copy_file_fixture("sample_vid.mp4", output_directory / filename)
|
copy_file_fixture("sample_vid.mp4", output_file_path)
|
||||||
else:
|
else:
|
||||||
copy_file_fixture("empty.txt", output_directory / filename)
|
copy_file_fixture("empty.txt", output_file_path)
|
||||||
|
|
||||||
return _pz_channel_mock_downloaded_with_archive_factory
|
return _pz_channel_mock_downloaded_with_archive_factory
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
from typing import Callable
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
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.config.config_file import ConfigFile
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,3 +69,22 @@ class TestChannel:
|
||||||
dry_run=dry_run,
|
dry_run=dry_run,
|
||||||
expected_download_summary_file_name="youtube/test_channel_full.json",
|
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
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ _TRANSACTION_LOG_SUMMARY_PATH = RESOURCE_PATH / "transaction_log_summaries"
|
||||||
|
|
||||||
|
|
||||||
def assert_transaction_log_matches(
|
def assert_transaction_log_matches(
|
||||||
output_directory: Path,
|
output_directory: Path | str,
|
||||||
transaction_log: FileHandlerTransactionLog,
|
transaction_log: FileHandlerTransactionLog,
|
||||||
transaction_log_summary_file_name: str,
|
transaction_log_summary_file_name: str,
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
@ -6,8 +7,11 @@ REGENERATE_FIXTURES: bool = False
|
||||||
RESOURCE_PATH: Path = Path("tests") / "resources"
|
RESOURCE_PATH: Path = Path("tests") / "resources"
|
||||||
_FILE_FIXTURE_PATH: Path = RESOURCE_PATH / "file_fixtures"
|
_FILE_FIXTURE_PATH: Path = RESOURCE_PATH / "file_fixtures"
|
||||||
|
|
||||||
|
|
||||||
def file_fixture_path(fixture_name: str) -> Path:
|
def file_fixture_path(fixture_name: str) -> Path:
|
||||||
return _FILE_FIXTURE_PATH / fixture_name
|
return _FILE_FIXTURE_PATH / fixture_name
|
||||||
|
|
||||||
|
|
||||||
def copy_file_fixture(fixture_name: str, output_file_path: Path) -> None:
|
def copy_file_fixture(fixture_name: str, output_file_path: Path) -> None:
|
||||||
|
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
|
||||||
shutil.copy(file_fixture_path(fixture_name), output_file_path)
|
shutil.copy(file_fixture_path(fixture_name), output_file_path)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
empty
|
||||||
Loading…
Reference in a new issue