diff --git a/src/ytdl_sub/cli/parsers/dl.py b/src/ytdl_sub/cli/parsers/dl.py index 790eacbef..7fbf7ac42 100644 --- a/src/ytdl_sub/cli/parsers/dl.py +++ b/src/ytdl_sub/cli/parsers/dl.py @@ -243,9 +243,12 @@ def to_subscription_dict(self) -> Dict: return subscription_dict def get_dl_subscription_name(self) -> str: + """ + Returns a deterministic name based on input args + """ to_hash = str(sorted(self._unknown_arguments)) - hash = hashlib.sha256(to_hash.encode()).hexdigest()[-8:] - return f"cli-dl-{hash}" + hash_str = hashlib.sha256(to_hash.encode()).hexdigest()[-8:] + return f"cli-dl-{hash_str}" @classmethod def from_dl_override(cls, override: str, config: ConfigFile) -> "DownloadArgsParser": diff --git a/tests/conftest.py b/tests/conftest.py index 28f4e1146..12ba38a91 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,7 @@ import sys import tempfile from pathlib import Path -from typing import Any, List +from typing import Any from typing import Callable from typing import Dict from typing import List diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index aac8a0762..99ef3f92f 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -25,5 +25,3 @@ def timestamps_file_path(): yield tmp.name finally: FileHandler.delete(tmp.name) - - diff --git a/tests/e2e/youtube/test_playlist.py b/tests/e2e/youtube/test_playlist.py index 65193c151..05e94fc70 100644 --- a/tests/e2e/youtube/test_playlist.py +++ b/tests/e2e/youtube/test_playlist.py @@ -2,7 +2,7 @@ from typing import Dict import pytest -from conftest import assert_logs, mock_run_from_cli +from conftest import assert_logs from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches from mergedeep import mergedeep @@ -10,7 +10,6 @@ from ytdl_sub.config.config_file import ConfigFile from ytdl_sub.downloaders.ytdlp import YTDLP from ytdl_sub.subscriptions.subscription import Subscription -from ytdl_sub.utils.system import IS_WINDOWS @pytest.fixture @@ -192,79 +191,6 @@ def test_playlist_download( output_directory=output_directory, ) - @pytest.mark.parametrize("dry_run", [True, False]) - def test_playlist_download_from_cli_sub_no_provided_config( - self, - preset_dict_to_subscription_yaml_generator, - playlist_preset_dict, - output_directory, - dry_run, - ): - # TODO: Fix CLI parsing on windows when dealing with spaces - if IS_WINDOWS: - return - - # No config needed when using only prebuilt presets - with preset_dict_to_subscription_yaml_generator( - subscription_name="music_video_playlist_test", preset_dict=playlist_preset_dict - ) as subscription_path: - args = "--dry-run " if dry_run else "" - args += f"sub '{subscription_path}'" - subscriptions = mock_run_from_cli(args=args) - - assert len(subscriptions) == 1 - transaction_log = subscriptions[0].transaction_log - - assert_transaction_log_matches( - output_directory=output_directory, - transaction_log=transaction_log, - transaction_log_summary_file_name="youtube/test_playlist.txt", - ) - assert_expected_downloads( - output_directory=output_directory, - dry_run=dry_run, - expected_download_summary_file_name="youtube/test_playlist.json", - ) - - if not dry_run: - # Ensure another invocation will hit ExistingVideoReached - with assert_logs( - logger=YTDLP.logger, - expected_message="ExistingVideoReached, stopping additional downloads", - log_level="debug", - ): - transaction_log = mock_run_from_cli(args=args)[0].transaction_log - - assert transaction_log.is_empty - assert_expected_downloads( - output_directory=output_directory, - dry_run=dry_run, - expected_download_summary_file_name="youtube/test_playlist.json", - ) - - def test_playlist_download_from_cli_sub_with_override_arg( - self, - preset_dict_to_subscription_yaml_generator, - playlist_preset_dict, - output_directory, - ): - # TODO: Fix CLI parsing on windows when dealing with spaces - if IS_WINDOWS: - return - - # No config needed when using only prebuilt presets - with preset_dict_to_subscription_yaml_generator( - subscription_name="music_video_playlist_test", preset_dict=playlist_preset_dict - ) as subscription_path: - args = ( - f"--dry-run sub '{subscription_path}' --dl-override '--date_range.after 20240101'" - ) - - subscriptions = mock_run_from_cli(args=args) - - assert len(subscriptions) == 1 - assert subscriptions[0].transaction_log.is_empty - def test_tv_show_by_date_downloads_bilateral( self, tv_show_by_date_bilateral_dict: Dict, diff --git a/tests/e2e/youtube/test_video.py b/tests/e2e/youtube/test_video.py index 4bf4f8f86..10b4e9745 100644 --- a/tests/e2e/youtube/test_video.py +++ b/tests/e2e/youtube/test_video.py @@ -2,6 +2,7 @@ from conftest import preset_dict_to_dl_args from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches + from ytdl_sub.subscriptions.subscription import Subscription diff --git a/tests/integration/cli/test_dl.py b/tests/integration/cli/test_dl.py index bd464581c..013ad4a67 100644 --- a/tests/integration/cli/test_dl.py +++ b/tests/integration/cli/test_dl.py @@ -2,12 +2,12 @@ from unittest.mock import patch import pytest - -from conftest import preset_dict_to_dl_args, mock_run_from_cli +from conftest import mock_run_from_cli +from conftest import preset_dict_to_dl_args from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches -from ytdl_sub.cli.parsers.dl import DownloadArgsParser +from ytdl_sub.cli.parsers.dl import DownloadArgsParser from ytdl_sub.utils.system import IS_WINDOWS @@ -20,15 +20,12 @@ def dl_subscription_dict(output_directory) -> Dict: "music_video_directory": output_directory, "url": "https://your.name.here", }, - "nfo_tags": { - "tags": { - "custom_tag": "{%array_at( ['hi', 'mom'], 1 )}" - } - } + "nfo_tags": {"tags": {"custom_tag": "{%array_at( ['hi', 'mom'], 1 )}"}}, } class TestCliDl: + @pytest.mark.parametrize("config_provided", [True, False]) @pytest.mark.parametrize("dry_run", [True, False]) def test_cli_dl_command( self, @@ -37,24 +34,30 @@ def test_cli_dl_command( dl_subscription_dict: Dict, output_directory: str, mock_download_collection_entries, - dry_run, + config_provided: bool, + dry_run: bool, ): + # Skip this combo to save time and to avoid mocking working dir + if not config_provided and not dry_run: + return + # TODO: Fix CLI parsing on windows when dealing with spaces if IS_WINDOWS: return args = "--dry-run " if dry_run else "" - args += f"--config {default_config_path} " + args += f"--config {default_config_path} " if config_provided else "" args += f"dl {preset_dict_to_dl_args(dl_subscription_dict)} " with ( patch.object(DownloadArgsParser, "get_dl_subscription_name") as mock_subscription_name, mock_download_collection_entries( - is_youtube_channel=False, - num_urls=1, - is_extracted_audio=False, - is_dry_run=dry_run, - )): + is_youtube_channel=False, + num_urls=1, + is_extracted_audio=False, + is_dry_run=dry_run, + ), + ): mock_subscription_name.return_value = subscription_name subscriptions = mock_run_from_cli(args=args) diff --git a/tests/unit/config/test_subscription.py b/tests/unit/config/test_subscription.py index 88f9dfc67..8fbfac158 100644 --- a/tests/unit/config/test_subscription.py +++ b/tests/unit/config/test_subscription.py @@ -186,11 +186,7 @@ def preset_with_subscription_overrides_map( "elem2", "elem3", ], - "custom_map": { - "custom_map_key": [ - "custom_map_list_value" - ] - } + "custom_map": {"custom_map_key": ["custom_map_list_value"]}, } }, }, @@ -295,11 +291,7 @@ def test_subscription_overrides_map( "elem2", "elem3", ], - "custom_map": { - "custom_map_key": [ - "custom_map_list_value" - ] - } + "custom_map": {"custom_map_key": ["custom_map_list_value"]}, }