-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds some tests for the size and suffix logic
- Loading branch information
Showing
2 changed files
with
89 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from unittest.mock import Mock | ||
|
||
from flickr_api.objects import Photo | ||
from flickr_download.flick_download import _get_size_and_suffix | ||
|
||
|
||
def tests_get_size_and_suffix_video() -> None: | ||
# Fallback when no video formats | ||
photo = Mock(Photo) | ||
photo.getSizes.return_value = None | ||
# The code does a .get("video")... slightly ugly mocking. | ||
photo.get.return_value = True | ||
(size, suffix) = _get_size_and_suffix(photo, None) | ||
assert size == "Site MP4" | ||
assert suffix == ".mp4" | ||
|
||
# The standard video format | ||
photo.getSizes.return_value = {"HD MP4": {}} | ||
(size, suffix) = _get_size_and_suffix(photo, None) | ||
assert size == "HD MP4" | ||
assert suffix == ".mp4" | ||
|
||
|
||
def tests_get_size_and_suffix_extension() -> None: | ||
# Source is there | ||
photo = Mock(Photo) | ||
photo.getSizes.return_value = {"Original": {"source": "some_file.png"}} | ||
photo.get.return_value = False | ||
(size, suffix) = _get_size_and_suffix(photo, None) | ||
assert size is None | ||
assert suffix == ".png" | ||
|
||
# Source is not there | ||
photo = Mock(Photo) | ||
photo.getSizes.return_value = {} | ||
photo.get.return_value = False | ||
(size, suffix) = _get_size_and_suffix(photo, None) | ||
assert size is None | ||
assert suffix == ".jpg" | ||
|
||
# Different source is there | ||
photo = Mock(Photo) | ||
photo.getSizes.return_value = {"Large": {"source": "some_file.png"}} | ||
photo.get.return_value = False | ||
(size, suffix) = _get_size_and_suffix(photo, None) | ||
assert size is None | ||
assert suffix == ".jpg" | ||
|
||
# Source is there, size is passed in | ||
photo = Mock(Photo) | ||
photo.getSizes.return_value = {"Original": {"source": "some_file.jpeg"}} | ||
photo.get.return_value = False | ||
(size, suffix) = _get_size_and_suffix(photo, "Original") | ||
assert size == "Original" | ||
assert suffix == ".jpeg" |