-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error handling for an invalid image file and add image processing…
… tests #29
- Loading branch information
1 parent
13dc50c
commit d55250a
Showing
6 changed files
with
64 additions
and
7 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
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
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,32 @@ | ||
""" | ||
Unit tests for image processing functions. | ||
""" | ||
|
||
import pytest | ||
from fastapi import UploadFile | ||
|
||
from object_storage_api.core.exceptions import InvalidImageFileError | ||
from object_storage_api.core.image import generate_thumbnail_base64_str | ||
|
||
|
||
class TestGenerateThumbnailBase64Str: | ||
"""Tests for the `generate_thumbnail_base64_str` method.""" | ||
|
||
def test_with_valid_image(self): | ||
"""Tests `generate_thumbnail_base64_str` with a valid image file provided.""" | ||
|
||
with open("test/files/image.jpg", "rb") as file: | ||
uploaded_image_file = UploadFile(file, filename="image.jpg") | ||
result = generate_thumbnail_base64_str(uploaded_image_file) | ||
|
||
assert result == "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA" | ||
|
||
def test_with_invalid_image(self): | ||
"""Tests `generate_thumbnail_base64_str` with an invalid image file provided.""" | ||
|
||
with open("test/files/invalid_image.jpg", "rb") as file: | ||
uploaded_image_file = UploadFile(file, filename="image.jpg") | ||
with pytest.raises(InvalidImageFileError) as exc: | ||
generate_thumbnail_base64_str(uploaded_image_file) | ||
|
||
assert str(exc.value) == f"The uploaded file '{uploaded_image_file.filename}' could not be opened by Pillow" |