Skip to content

Commit

Permalink
disable aspect ratio validation for images (#2487)
Browse files Browse the repository at this point in the history
* disable aspect ratio validation for images

* fix

---------

Co-authored-by: Vignesh Hari <[email protected]>
  • Loading branch information
sainak and vigneshhari authored Sep 23, 2024
1 parent 9038b93 commit 9816822
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
4 changes: 3 additions & 1 deletion care/utils/models/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ def __init__(
self.aspect_ratio_str = ", ".join(
f"{ratio.numerator}:{ratio.denominator}" for ratio in self.aspect_ratio
)
else:
self.aspect_ratio = None
self.aspect_ratio_str = None

def __call__(self, value: UploadedFile) -> None:
with Image.open(value.file) as image:
Expand Down Expand Up @@ -326,7 +329,6 @@ def _humanize_bytes(self, size: int) -> str:
min_height=400,
max_width=1024,
max_height=1024,
aspect_ratio=[1 / 1],
min_size=1024, # 1 KB
max_size=1024 * 1024 * 2, # 2 MB
)
Expand Down
12 changes: 0 additions & 12 deletions care/utils/tests/test_image_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,3 @@ def test_invalid_image_too_large(self):
"Image size is greater than the maximum allowed size of 2 MB.",
],
)

def test_invalid_image_aspect_ratio(self):
image = Image.new("RGB", (400, 800))
file = io.BytesIO()
image.save(file, format="JPEG")
test_file = UploadedFile(file, "test.jpg", "image/jpeg", 2048)
with self.assertRaises(ValidationError) as cm:
self.cover_image_validator(test_file)
self.assertEqual(
cm.exception.messages,
["Image aspect ratio must be one of the following: 1:1."],
)

0 comments on commit 9816822

Please sign in to comment.