more unit tests
This commit is contained in:
parent
4c01198ce9
commit
1243832178
5 changed files with 31 additions and 51 deletions
|
|
@ -42,7 +42,7 @@ def upload_month():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def upload_day():
|
def upload_day():
|
||||||
return 6
|
return 12
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -61,8 +61,8 @@ def thumbnail_ext():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def thumbnail(thumbnail_ext):
|
def download_thumbnail_name(uid, thumbnail_ext):
|
||||||
return f"thumb.{thumbnail_ext}"
|
return f"{uid}.{thumbnail_ext}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -77,9 +77,7 @@ def mock_entry_to_dict(
|
||||||
ext,
|
ext,
|
||||||
upload_date,
|
upload_date,
|
||||||
upload_year,
|
upload_year,
|
||||||
thumbnail,
|
|
||||||
thumbnail_ext,
|
thumbnail_ext,
|
||||||
extractor,
|
|
||||||
description,
|
description,
|
||||||
upload_month,
|
upload_month,
|
||||||
upload_day,
|
upload_day,
|
||||||
|
|
@ -96,22 +94,22 @@ def mock_entry_to_dict(
|
||||||
"upload_month_padded": _pad(upload_month),
|
"upload_month_padded": _pad(upload_month),
|
||||||
"upload_day": upload_day,
|
"upload_day": upload_day,
|
||||||
"upload_day_padded": _pad(upload_day),
|
"upload_day_padded": _pad(upload_day),
|
||||||
"thumbnail": thumbnail,
|
|
||||||
"thumbnail_ext": thumbnail_ext,
|
"thumbnail_ext": thumbnail_ext,
|
||||||
"extractor": extractor,
|
|
||||||
"description": description,
|
"description": description,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_entry_kwargs(uid, title, ext, upload_date, thumbnail, extractor, description):
|
def mock_entry_kwargs(
|
||||||
|
uid, title, ext, upload_date, extractor, description, download_thumbnail_name
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"id": uid,
|
"id": uid,
|
||||||
"extractor": extractor,
|
"extractor": extractor,
|
||||||
"title": title,
|
"title": title,
|
||||||
"ext": ext,
|
"ext": ext,
|
||||||
"upload_date": upload_date,
|
"upload_date": upload_date,
|
||||||
"thumbnail": thumbnail,
|
"thumbnail": download_thumbnail_name,
|
||||||
"description": description,
|
"description": description,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,9 +126,10 @@ def validate_entry_properties(
|
||||||
upload_date,
|
upload_date,
|
||||||
upload_year,
|
upload_year,
|
||||||
ext,
|
ext,
|
||||||
thumbnail,
|
extractor,
|
||||||
thumbnail_ext,
|
thumbnail_ext,
|
||||||
download_file_name,
|
download_file_name,
|
||||||
|
download_thumbnail_name,
|
||||||
):
|
):
|
||||||
def _validate_entry_properties(entry: Entry):
|
def _validate_entry_properties(entry: Entry):
|
||||||
assert entry.uid == uid
|
assert entry.uid == uid
|
||||||
|
|
@ -140,9 +139,11 @@ def validate_entry_properties(
|
||||||
assert entry.upload_date == upload_date
|
assert entry.upload_date == upload_date
|
||||||
assert entry.upload_year == upload_year
|
assert entry.upload_year == upload_year
|
||||||
assert entry.ext == ext
|
assert entry.ext == ext
|
||||||
assert entry.thumbnail == thumbnail
|
|
||||||
assert entry.thumbnail_ext == thumbnail_ext
|
assert entry.thumbnail_ext == thumbnail_ext
|
||||||
assert entry.download_file_name == download_file_name
|
assert entry.download_file_name == download_file_name
|
||||||
|
assert entry.download_thumbnail_name == download_thumbnail_name
|
||||||
|
assert entry.playlist_metadata is None
|
||||||
|
assert entry.extractor == extractor
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
import tempfile
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ytdl_subscribe.validators.base.string_formatter_validators import StringFormatterValidator
|
|
||||||
from ytdl_subscribe.validators.exceptions import StringFormattingException
|
|
||||||
|
|
||||||
|
|
||||||
class TestEntry(object):
|
class TestEntry(object):
|
||||||
def test_entry_properties(
|
def test_entry_properties(
|
||||||
|
|
@ -22,16 +17,6 @@ class TestEntry(object):
|
||||||
):
|
):
|
||||||
assert validate_entry_dict_contains_valid_formatters(mock_entry)
|
assert validate_entry_dict_contains_valid_formatters(mock_entry)
|
||||||
|
|
||||||
def test_entry_file_path(self, mock_entry, download_file_name):
|
|
||||||
relative_directory = tempfile.TemporaryDirectory()
|
|
||||||
|
|
||||||
try:
|
|
||||||
file_path = mock_entry.file_path(relative_directory.name)
|
|
||||||
assert isinstance(file_path, str)
|
|
||||||
assert file_path == f"{relative_directory.name}/{download_file_name}"
|
|
||||||
finally:
|
|
||||||
relative_directory.cleanup()
|
|
||||||
|
|
||||||
def test_entry_missing_kwarg(self, mock_entry):
|
def test_entry_missing_kwarg(self, mock_entry):
|
||||||
key = "dne"
|
key = "dne"
|
||||||
expected_error_msg = f"Expected '{key}' in Entry but does not exist."
|
expected_error_msg = f"Expected '{key}' in Entry but does not exist."
|
||||||
|
|
|
||||||
|
|
@ -164,3 +164,8 @@ class TestDictFormatterValidator(object):
|
||||||
|
|
||||||
assert validator.dict["key1"].format_variables == ["variable"]
|
assert validator.dict["key1"].format_variables == ["variable"]
|
||||||
assert validator.dict["key2"].format_variables == []
|
assert validator.dict["key2"].format_variables == []
|
||||||
|
|
||||||
|
assert validator.dict_with_format_strings == {
|
||||||
|
"key1": key1_format_string,
|
||||||
|
"key2": key2_format_string,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ class BaseEntry(ABC):
|
||||||
"""Returns the entry's values as a dictionary"""
|
"""Returns the entry's values as a dictionary"""
|
||||||
return {
|
return {
|
||||||
"uid": self.uid,
|
"uid": self.uid,
|
||||||
"extractor": self.extractor,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -125,16 +124,6 @@ class Entry(BaseEntry):
|
||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return self.kwargs("description")
|
return self.kwargs("description")
|
||||||
|
|
||||||
@property
|
|
||||||
def thumbnail(self) -> str:
|
|
||||||
"""Returns the entry's thumbnail url"""
|
|
||||||
return self.kwargs("thumbnail")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def thumbnail_ext(self) -> str:
|
|
||||||
"""Returns the entry's thumbnail extension"""
|
|
||||||
return self.thumbnail.split(".")[-1]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def download_file_name(self) -> str:
|
def download_file_name(self) -> str:
|
||||||
"""Returns the entry's file name when downloaded locally"""
|
"""Returns the entry's file name when downloaded locally"""
|
||||||
|
|
@ -142,16 +131,15 @@ class Entry(BaseEntry):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def download_thumbnail_name(self) -> str:
|
def download_thumbnail_name(self) -> str:
|
||||||
"""Returns the thumbnail's file name when downloaded locally TODO: unit test this"""
|
"""Returns the thumbnail's file name when downloaded locally"""
|
||||||
return f"{self.uid}.{self.thumbnail_ext}"
|
return self.kwargs("thumbnail")
|
||||||
|
|
||||||
def file_path(self, relative_directory: str):
|
@property
|
||||||
"""Returns the entry's file path with respect to the relative directory"""
|
def thumbnail_ext(self) -> str:
|
||||||
return str(Path(relative_directory) / self.download_file_name)
|
"""
|
||||||
|
:return: The entry's thumbnail extension
|
||||||
def thumbnail_path(self, relative_directory: str):
|
"""
|
||||||
"""Returns the entry's thumbnail path with respect to the relative directory"""
|
return self.download_thumbnail_name.split(".")[-1]
|
||||||
return str(Path(relative_directory) / self.download_thumbnail_name)
|
|
||||||
|
|
||||||
def to_dict(self) -> Dict:
|
def to_dict(self) -> Dict:
|
||||||
"""Returns the entry's values as a dictionary"""
|
"""Returns the entry's values as a dictionary"""
|
||||||
|
|
@ -162,6 +150,7 @@ class Entry(BaseEntry):
|
||||||
"sanitized_title": self.sanitized_title,
|
"sanitized_title": self.sanitized_title,
|
||||||
"description": self.description,
|
"description": self.description,
|
||||||
"ext": self.ext,
|
"ext": self.ext,
|
||||||
|
"thumbnail_ext": self.thumbnail_ext,
|
||||||
"upload_date": self.upload_date,
|
"upload_date": self.upload_date,
|
||||||
"upload_date_standardized": self.upload_date_standardized,
|
"upload_date_standardized": self.upload_date_standardized,
|
||||||
"upload_year": self.upload_year,
|
"upload_year": self.upload_year,
|
||||||
|
|
@ -169,7 +158,5 @@ class Entry(BaseEntry):
|
||||||
"upload_month_padded": self.upload_month_padded,
|
"upload_month_padded": self.upload_month_padded,
|
||||||
"upload_day": self.upload_day,
|
"upload_day": self.upload_day,
|
||||||
"upload_day_padded": self.upload_day_padded,
|
"upload_day_padded": self.upload_day_padded,
|
||||||
"thumbnail": self.thumbnail,
|
|
||||||
"thumbnail_ext": self.thumbnail_ext,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,9 @@ class Subscription(Generic[SourceT], ABC):
|
||||||
Tags the entry's audio file using values defined in the metadata options
|
Tags the entry's audio file using values defined in the metadata options
|
||||||
"""
|
"""
|
||||||
id3_options = self.metadata_options.id3
|
id3_options = self.metadata_options.id3
|
||||||
audio_file = music_tag.load_file(entry.file_path(relative_directory=self.working_directory))
|
entry_source_file_path = Path(self.working_directory) / entry.download_file_name
|
||||||
|
|
||||||
|
audio_file = music_tag.load_file(entry_source_file_path)
|
||||||
for tag, tag_formatter in id3_options.tags.dict.items():
|
for tag, tag_formatter in id3_options.tags.dict.items():
|
||||||
audio_file[tag] = self._apply_formatter(formatter=tag_formatter, entry=entry)
|
audio_file[tag] = self._apply_formatter(formatter=tag_formatter, entry=entry)
|
||||||
audio_file.save()
|
audio_file.save()
|
||||||
|
|
@ -175,7 +177,7 @@ class Subscription(Generic[SourceT], ABC):
|
||||||
self._archive_entry_file_name(entry=entry, relative_file_name=nfo_file_name)
|
self._archive_entry_file_name(entry=entry, relative_file_name=nfo_file_name)
|
||||||
|
|
||||||
def _post_process_thumbnail(self, entry: Entry):
|
def _post_process_thumbnail(self, entry: Entry):
|
||||||
source_thumbnail_path = entry.thumbnail_path(relative_directory=self.working_directory)
|
source_thumbnail_path = Path(self.working_directory) / entry.download_thumbnail_name
|
||||||
|
|
||||||
# Bug that mismatches webp and jpg extensions. Try to hotfix here
|
# Bug that mismatches webp and jpg extensions. Try to hotfix here
|
||||||
if not os.path.isfile(source_thumbnail_path):
|
if not os.path.isfile(source_thumbnail_path):
|
||||||
|
|
@ -214,7 +216,7 @@ class Subscription(Generic[SourceT], ABC):
|
||||||
|
|
||||||
def _copy_entry_file_to_output_directory(self, entry: Entry):
|
def _copy_entry_file_to_output_directory(self, entry: Entry):
|
||||||
# Move the file after all direct file modifications are complete
|
# Move the file after all direct file modifications are complete
|
||||||
entry_source_file_path = entry.file_path(relative_directory=self.working_directory)
|
entry_source_file_path = Path(self.working_directory) / entry.download_file_name
|
||||||
|
|
||||||
output_file_name = self._apply_formatter(
|
output_file_name = self._apply_formatter(
|
||||||
formatter=self.output_options.file_name, entry=entry
|
formatter=self.output_options.file_name, entry=entry
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue