From 981682272b22e5670da80c0a3777fb2a95ab2be5 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Mon, 23 Sep 2024 19:36:07 +0530 Subject: [PATCH] disable aspect ratio validation for images (#2487) * disable aspect ratio validation for images * fix --------- Co-authored-by: Vignesh Hari <14056798+vigneshhari@users.noreply.github.com> --- care/utils/models/validators.py | 4 +++- care/utils/tests/test_image_validator.py | 12 ------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/care/utils/models/validators.py b/care/utils/models/validators.py index bf394d9087..1e50d905ea 100644 --- a/care/utils/models/validators.py +++ b/care/utils/models/validators.py @@ -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: @@ -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 ) diff --git a/care/utils/tests/test_image_validator.py b/care/utils/tests/test_image_validator.py index 1c8d2656f0..dccdfb5165 100644 --- a/care/utils/tests/test_image_validator.py +++ b/care/utils/tests/test_image_validator.py @@ -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."], - )