From b17d773248bb6c0ea98a8653ade5d3acec402242 Mon Sep 17 00:00:00 2001 From: jbannon Date: Tue, 12 Apr 2022 04:07:31 +0000 Subject: [PATCH] fix unit tests --- config.yaml | 3 +- subscriptions.yaml | 42 ++++++++--------- tests/unit/entries/conftest.py | 46 +++++++++++++++++-- tests/unit/entries/test_entry.py | 2 - ytdl_subscribe/entries/entry.py | 5 +- .../enhanced_download_archive.py | 2 +- 6 files changed, 68 insertions(+), 32 deletions(-) diff --git a/config.yaml b/config.yaml index 4051c0c1..a2e8fb53 100644 --- a/config.yaml +++ b/config.yaml @@ -13,6 +13,7 @@ presets: file_name: "[{album_year}] {sanitized_album}/{track_number_padded} - {sanitized_title}.{ext}" convert_thumbnail: "jpeg" thumbnail_name: "[{album_year}] {sanitized_album}/folder.jpeg" + maintain_download_archive: True metadata_options: id3: id3_version: "2.4" @@ -65,7 +66,7 @@ presets: episode: "{upload_month}{upload_day_padded}" plot: "{description}" year: "{upload_year}" - aired: "{upload_year}-{upload_month_padded}-{upload_day_padded}" + aired: "{upload_date_standardized}" output_directory_nfo: nfo_name: "tvshow.nfo" nfo_root: "tvshow" diff --git a/subscriptions.yaml b/subscriptions.yaml index 3de8d90d..b8c9e13f 100644 --- a/subscriptions.yaml +++ b/subscriptions.yaml @@ -18,15 +18,15 @@ # artist: "DeLorra" # genre: "Synthwave / Electronic" # -#bl00dwave: -# preset: "soundcloud_with_id3_tags" -# soundcloud: -# username: bl00dwave -# output_options: -# output_directory: "/tmp/bl00dwave" -# overrides: -# artist: "bl00dwave" -# genre: "Synthwave / Electronic" +bl00dwave: + preset: "soundcloud_with_id3_tags" + soundcloud: + username: bl00dwave + output_options: + output_directory: "/tmp/bl00dwave" + overrides: + artist: "bl00dwave" + genre: "Synthwave / Electronic" # #tom_petty: # preset: "music_videos" @@ -58,15 +58,15 @@ # overrides: # artist: "The Gogos" -recent_channel_test: - preset: "yt_channel" - ytdl_options: - break_on_reject: True - youtube: - download_strategy: "channel" - channel_id: "UCRcCVDu_4oARsAKFkKYydAQ" - after: today-8months - output_options: - output_directory: "/tmp/dunkey" - overrides: - tv_show_name: "Youtube: Dunkey" \ No newline at end of file +#recent_channel_test: +# preset: "yt_channel" +# ytdl_options: +# break_on_reject: True +# youtube: +# download_strategy: "channel" +# channel_id: "UCRcCVDu_4oARsAKFkKYydAQ" +# after: today-2days +# output_options: +# output_directory: "/tmp/dunkey" +# overrides: +# tv_show_name: "Youtube: Dunkey" \ No newline at end of file diff --git a/tests/unit/entries/conftest.py b/tests/unit/entries/conftest.py index c8f1009f..cd7877fe 100644 --- a/tests/unit/entries/conftest.py +++ b/tests/unit/entries/conftest.py @@ -4,6 +4,12 @@ from ytdl_subscribe.entries.entry import Entry from ytdl_subscribe.validators.base.string_formatter_validators import StringFormatterValidator +def _pad(num): + if num < 10: + return f"0{num}" + return str(num) + + @pytest.fixture def uid(): return "abc123" @@ -19,14 +25,29 @@ def title(): return "entry title" +@pytest.fixture +def description(): + return "a description" + + @pytest.fixture def upload_year(): return 2021 @pytest.fixture -def upload_date(upload_year): - return f"{upload_year}-01-06" +def upload_month(): + return 1 + + +@pytest.fixture +def upload_day(): + return 6 + + +@pytest.fixture +def upload_date(upload_year, upload_month, upload_day): + return f"{upload_year}{_pad(upload_month)}{_pad(upload_day)}" @pytest.fixture @@ -51,7 +72,17 @@ def download_file_name(uid, ext): @pytest.fixture def mock_entry_to_dict( - uid, title, ext, upload_date, upload_year, thumbnail, thumbnail_ext, extractor + uid, + title, + ext, + upload_date, + upload_year, + thumbnail, + thumbnail_ext, + extractor, + description, + upload_month, + upload_day, ): return { "uid": uid, @@ -59,15 +90,21 @@ def mock_entry_to_dict( "sanitized_title": title, "ext": ext, "upload_date": upload_date, + "upload_date_standardized": f"{upload_year}-{_pad(upload_month)}-{_pad(upload_day)}", "upload_year": upload_year, + "upload_month": upload_month, + "upload_month_padded": _pad(upload_month), + "upload_day": upload_day, + "upload_day_padded": _pad(upload_day), "thumbnail": thumbnail, "thumbnail_ext": thumbnail_ext, "extractor": extractor, + "description": description, } @pytest.fixture -def mock_entry_kwargs(uid, title, ext, upload_date, thumbnail): +def mock_entry_kwargs(uid, title, ext, upload_date, thumbnail, extractor, description): return { "id": uid, "extractor": extractor, @@ -75,6 +112,7 @@ def mock_entry_kwargs(uid, title, ext, upload_date, thumbnail): "ext": ext, "upload_date": upload_date, "thumbnail": thumbnail, + "description": description, } diff --git a/tests/unit/entries/test_entry.py b/tests/unit/entries/test_entry.py index c113f7dd..79f94f5b 100644 --- a/tests/unit/entries/test_entry.py +++ b/tests/unit/entries/test_entry.py @@ -3,9 +3,7 @@ import tempfile import pytest from ytdl_subscribe.validators.base.string_formatter_validators import StringFormatterValidator -from ytdl_subscribe.validators.config.overrides.overrides_validator import OverridesValidator from ytdl_subscribe.validators.exceptions import StringFormattingException -from ytdl_subscribe.validators.exceptions import ValidationException class TestEntry(object): diff --git a/ytdl_subscribe/entries/entry.py b/ytdl_subscribe/entries/entry.py index 45fdeaf5..71256929 100644 --- a/ytdl_subscribe/entries/entry.py +++ b/ytdl_subscribe/entries/entry.py @@ -18,7 +18,6 @@ class PlaylistMetadata: playlist_extractor: str -# TODO: strip things out of entry into BaseEntry class BaseEntry(ABC): def __init__(self, **kwargs): """ @@ -131,7 +130,7 @@ class Entry(BaseEntry): return int(self.upload_day_padded.lstrip("0")) @property - def standardized_upload_date(self) -> str: + def upload_date_standardized(self) -> str: """ :return: upload date as YYYY-MM-DD """ @@ -179,12 +178,12 @@ class Entry(BaseEntry): "description": self.description, "ext": self.ext, "upload_date": self.upload_date, + "upload_date_standardized": self.upload_date_standardized, "upload_year": self.upload_year, "upload_month": self.upload_month, "upload_month_padded": self.upload_month_padded, "upload_day": self.upload_day, "upload_day_padded": self.upload_day_padded, - "standardized_upload_date": self.standardized_upload_date, "thumbnail": self.thumbnail, "thumbnail_ext": self.thumbnail_ext, }, diff --git a/ytdl_subscribe/ytdl_additions/enhanced_download_archive.py b/ytdl_subscribe/ytdl_additions/enhanced_download_archive.py index c5e2a71d..7f206e95 100644 --- a/ytdl_subscribe/ytdl_additions/enhanced_download_archive.py +++ b/ytdl_subscribe/ytdl_additions/enhanced_download_archive.py @@ -43,7 +43,7 @@ class DownloadMapping: @classmethod def from_entry(cls, entry: Entry) -> "DownloadMapping": return DownloadMapping( - upload_date=entry.standardized_upload_date, + upload_date=entry.upload_date_standardized, extractor=entry.extractor, file_names=set(), )