Skip to content

Commit f6fb3ee

Browse files
committed
Update tests and user model to accurately reflect profile_image requirements
1 parent 25a25b7 commit f6fb3ee

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

users/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from core.validators import (
2424
image_validator,
2525
large_file_max_size_validator,
26+
downscale_image_file_size_validator,
2627
)
2728
from core.templatetags.custom_static import large_static
2829

@@ -208,7 +209,7 @@ class User(BaseUser):
208209
upload_to="profile-images",
209210
null=True,
210211
blank=True,
211-
validators=[image_validator],
212+
validators=[image_validator, downscale_image_file_size_validator],
212213
)
213214
image_thumbnail = ImageSpecField(
214215
source="profile_image",

users/tests/test_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def test_user_model_image_file_size(user):
5959
Test that the `image` field rejects files larger than a specific size.
6060
"""
6161
valid_image = SimpleUploadedFile(
62-
"test.jpg", b"a" * (1 * 1024 * 1024 - 1), content_type="image/jpeg"
62+
"test.jpg", b"a" * (5 * 1024 * 1024 - 1), content_type="image/jpeg"
6363
)
6464
user.profile_image = valid_image
6565
# This should not raise any errors
6666
user.full_clean()
6767

6868
# This should fail (just over 1MB)
6969
invalid_image = SimpleUploadedFile(
70-
"too_large.jpg", b"a" * (1 * 1024 * 1024 + 1), content_type="image/jpeg"
70+
"too_large.jpg", b"a" * (5 * 1024 * 1024 + 1), content_type="image/jpeg"
7171
)
7272
user.profile_image = invalid_image
7373
# This should raise a ValidationError for file size

0 commit comments

Comments
 (0)