-
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.
feat: add tests, utils and refactor resizer class
- Loading branch information
1 parent
c3b52f9
commit aaa3f6e
Showing
6 changed files
with
68 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALLOWED_INPUT_FORMATS = ["png", "jpeg"] | ||
ALLOWED_CONTENT_TYPE = ["image/png", "image/jpeg"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from src.app.constants import ALLOWED_CONTENT_TYPE, ALLOWED_INPUT_FORMATS | ||
from fastapi.exceptions import HTTPException | ||
from fastapi import status | ||
|
||
|
||
def validate_content_type(filename: str, content_type: str) -> bool: | ||
if content_type not in ALLOWED_CONTENT_TYPE: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail=f"Supported formats: {ALLOWED_INPUT_FORMATS}; provided '{filename}'.", | ||
) |
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,26 @@ | ||
from unittest import TestCase | ||
from src.app.utils import validate_content_type | ||
from fastapi.exceptions import HTTPException | ||
|
||
|
||
class TestValidateContentType(TestCase): | ||
def test_validate_content_type_as_valid(self): | ||
# Arrange | ||
content_type = "image/png" | ||
|
||
# Act | ||
result = validate_content_type("fake.file", content_type) | ||
|
||
# Assert | ||
self.assertIsNone(result) | ||
|
||
def test_validate_content_type_as_invalid(self): | ||
# Arrange | ||
content_type = "image/invalid" | ||
|
||
# Act | ||
with self.assertRaises(Exception) as context: | ||
validate_content_type("fake.file", content_type) | ||
|
||
# Assert | ||
self.assertIsInstance(context.exception, HTTPException) |