test
This commit is contained in:
parent
9fd46bf929
commit
43ceea9b54
3 changed files with 46 additions and 8 deletions
|
|
@ -106,7 +106,7 @@ class OutputOptions(OptionsDictValidator):
|
|||
"keep_files_after",
|
||||
"keep_max_files",
|
||||
"download_archive_standardized_date",
|
||||
"entry_date_eval",
|
||||
"keep_files_date_eval",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
|
@ -164,10 +164,10 @@ class OutputOptions(OptionsDictValidator):
|
|||
self._keep_max_files = self._validate_key_if_present(
|
||||
"keep_max_files", OverridesIntegerFormatterValidator
|
||||
)
|
||||
self._entry_date_eval = self._validate_key(
|
||||
"entry_date_eval",
|
||||
self._keep_files_date_eval = self._validate_key(
|
||||
"keep_files_date_eval",
|
||||
StandardizedDateValidator,
|
||||
default=f"{{{v.upload_date_standardized.variable_name}}}"
|
||||
default=f"{{{v.upload_date_standardized.variable_name}}}",
|
||||
)
|
||||
|
||||
if (
|
||||
|
|
@ -286,7 +286,7 @@ class OutputOptions(OptionsDictValidator):
|
|||
return self._keep_files_after
|
||||
|
||||
@property
|
||||
def entry_date_eval(self) -> StandardizedDateValidator:
|
||||
def keep_files_date_eval(self) -> StandardizedDateValidator:
|
||||
"""
|
||||
:expected type: str
|
||||
:description:
|
||||
|
|
@ -295,7 +295,7 @@ class OutputOptions(OptionsDictValidator):
|
|||
perform evaluation for keep_files_before/after and keep_max_files. Defaults
|
||||
to the entry's upload_date_standardized variable.
|
||||
"""
|
||||
return self._entry_date_eval
|
||||
return self._keep_files_date_eval
|
||||
|
||||
@property
|
||||
def keep_max_files(self) -> Optional[OverridesIntegerFormatterValidator]:
|
||||
|
|
|
|||
|
|
@ -221,12 +221,16 @@ class SubscriptionDownload(BaseSubscription, ABC):
|
|||
|
||||
# Inject OutputOption variables here
|
||||
entry.add(
|
||||
{VARIABLES.ytdl_sub_entry_date_eval: self.output_options.entry_date_eval.format_string}
|
||||
{
|
||||
VARIABLES.ytdl_sub_entry_date_eval: (
|
||||
self.output_options.keep_files_date_eval.format_string
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
# Run it to make sure it's actually a standardized date
|
||||
_ = self.overrides.apply_formatter(
|
||||
formatter=self.output_options.entry_date_eval, entry=entry
|
||||
formatter=self.output_options.keep_files_date_eval, entry=entry
|
||||
)
|
||||
|
||||
for plugin in PluginMapping.order_plugins_by(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from unittest.mock import patch
|
||||
|
|
@ -11,6 +12,7 @@ from ytdl_sub.config.config_file import ConfigFile
|
|||
from ytdl_sub.downloaders.ytdlp import YTDLP
|
||||
from ytdl_sub.entries.entry import Entry
|
||||
from ytdl_sub.subscriptions.subscription import Subscription
|
||||
from ytdl_sub.utils.exceptions import ValidationException
|
||||
from ytdl_sub.utils.file_handler import FileHandler
|
||||
from ytdl_sub.utils.thumbnail import try_convert_download_thumbnail
|
||||
|
||||
|
|
@ -223,3 +225,35 @@ class TestOutputOptions:
|
|||
dry_run=False,
|
||||
expected_download_summary_file_name="plugins/output_options/test_missing_thumb.json",
|
||||
)
|
||||
|
||||
def test_invalid_keep_files_date_eval(
|
||||
self,
|
||||
config: ConfigFile,
|
||||
subscription_name: str,
|
||||
output_options_subscription_dict: Dict,
|
||||
output_directory: str,
|
||||
mock_download_collection_entries,
|
||||
):
|
||||
output_options_subscription_dict["output_options"]["keep_files_date_eval"] = "nope"
|
||||
|
||||
subscription = Subscription.from_dict(
|
||||
config=config,
|
||||
preset_name=subscription_name,
|
||||
preset_dict=output_options_subscription_dict,
|
||||
)
|
||||
|
||||
expected_error_msg = (
|
||||
"Validation error in subscription_test.output_options.keep_files_date_eval: "
|
||||
"Expected a standardized date in the form of YYYY-MM-DD, but received 'nope'"
|
||||
)
|
||||
|
||||
with (
|
||||
mock_download_collection_entries(
|
||||
is_youtube_channel=False,
|
||||
num_urls=1,
|
||||
is_extracted_audio=False,
|
||||
is_dry_run=True,
|
||||
),
|
||||
pytest.raises(ValidationException, match=re.escape(expected_error_msg)),
|
||||
):
|
||||
subscription.download(dry_run=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue