Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbannon committed Oct 3, 2024
1 parent 45c42a1 commit 68238e6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 105 deletions.
7 changes: 5 additions & 2 deletions src/ytdl_sub/cli/parsers/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ def timestamps_file_path():
yield tmp.name
finally:
FileHandler.delete(tmp.name)


76 changes: 1 addition & 75 deletions tests/e2e/youtube/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
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

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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/youtube/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
33 changes: 18 additions & 15 deletions tests/integration/cli/test_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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,
Expand All @@ -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)

Expand Down
12 changes: 2 additions & 10 deletions tests/unit/config/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]},
}
},
},
Expand Down Expand Up @@ -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"]},
}


Expand Down

0 comments on commit 68238e6

Please sign in to comment.