8000 Change the stream position after reading in validators · codingjoe/django-stdimage@c2a3e79 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2a3e79

Browse filesBrowse files
committed
Change the stream position after reading in validators
1 parent 83e46c0 commit c2a3e79

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

stdimage/validators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def __call__(self, value):
2828
def clean(value):
2929
value.seek(0)
3030
stream = BytesIO(value.read())
31-
img = Image.open(stream)
32-
return img.size
31+
size = Image.open(stream).size
32+
value.seek(0)
33+
return size
3334

3435

3536
class MaxSizeValidator(BaseSizeValidator):

tests/test_models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,17 @@ def test_render_variations_overwrite(self, db, image_upload_file):
227227

228228
class TestValidators(TestStdImage):
229229
def test_max_size_validator(self, admin_client):
230-
admin_client.post('/admin/tests/maxsizemodel/add/', {
230+
response = admin_client.post('/admin/tests/maxsizemodel/add/', {
231231
'image': self.fixtures['600x400.jpg'],
232232
})
233+
assert 'too large' in response.context['adminform'].form.errors['image'][0]
233234
assert not os.path.exists(os.path.join(IMG_DIR, '800x600.jpg'))
234235

235236
def test_min_size_validator(self, admin_client):
236-
admin_client.post('/admin/tests/minsizemodel/add/', {
237+
response = admin_client.post('/admin/tests/minsizemodel/add/', {
237238
'image': self.fixtures['100.gif'],
238239
})
240+
assert 'too small' in response.context['adminform'].form.errors['image'][0]
239241
assert not os.path.exists(os.path.join(IMG_DIR, '100.gif'))
240242

241243

0 commit comments

Comments
 (0)
0