Skip to content

Commit

Permalink
image_file.file
Browse files Browse the repository at this point in the history
  • Loading branch information
BelousSofiya committed Oct 8, 2023
1 parent e8057a2 commit 4ac70bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion profiles/tests/test_crud_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def _generate_image(ext, size):
image.save(file, formatext)
file.name = f"test.{formatext}"
file.seek(0)
# print(file.name, sys.getsizeof(file), sys.getsizeof(image), type(image))
return file

def setUp(self) -> None:
# self.right_image = self._generate_image("jpeg", (10, 10))
self.right_image = self._generate_image("png", (1, 1))
self.right_image = self._generate_image("png", (100, 100))
self.wrong_image = self._generate_image("png", (5, 5))
self.user = UserFactory(email="[email protected]")
self.profile = ProfileStartupFactory.create(
Expand Down
10 changes: 6 additions & 4 deletions validation/validate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ def validate_image_format(image: Image):
)


def validate_image_size(image: Image):
def validate_image_size(image_file):
import sys

max_size = sys.getsizeof(image)
print(f"{max_size=}")
if max_size > 50:
max_size = sys.getsizeof(image_file.file)
# print(image_file, f"{max_size=}", f"{type(image_file)}")
# print(sys.getsizeof(image_file.file))
# print(image_file.__dict__)
if max_size > 50000:
raise ValidationError("Image size exceeds the maximum allowed (50MB).")

0 comments on commit 4ac70bf

Please sign in to comment.