Skip to content

Commit 9187549

Browse files
committed
Update tests
1 parent d469663 commit 9187549

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

news/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class EntryForm(forms.ModelForm):
99
title = forms.CharField(widget=forms.TextInput(attrs={"size": 100}))
10-
image = forms.ImageField(validators=[max_file_size_validator])
10+
image = forms.ImageField(validators=[max_file_size_validator], required=False)
1111

1212
class Meta:
1313
model = Entry

news/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
attachment_validator,
1717
image_validator,
1818
large_file_max_size_validator,
19+
downscale_image_file_size_validator,
1920
)
2021

2122
from . import acl
@@ -111,7 +112,7 @@ class AlreadyApprovedError(Exception):
111112
upload_to="news/%Y/%m/",
112113
null=True,
113114
blank=True,
114-
validators=[image_validator],
115+
validators=[image_validator, downscale_image_file_size_validator],
115116
)
116117
created_at = models.DateTimeField(default=now)
117118
approved_at = models.DateTimeField(null=True, blank=True)

news/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_entry_model_image_file_size(tp):
104104

105105
# This should fail (just over 1MB)
106106
invalid_image = SimpleUploadedFile(
107-
"too_large.jpg", b"a" * (1 * 1024 * 1024 + 1), content_type="image/jpeg"
107+
"too_large.jpg", b"a" * (5 * 1024 * 1024 + 1), content_type="image/jpeg"
108108
)
109109
entry.image = invalid_image
110110
# This should raise a ValidationError for file size

0 commit comments

Comments
 (0)