diff --git a/stdimage/validators.py b/stdimage/validators.py index f0abd7d..b609c55 100644 --- a/stdimage/validators.py +++ b/stdimage/validators.py @@ -28,8 +28,9 @@ def __call__(self, value): def clean(value): value.seek(0) stream = BytesIO(value.read()) - img = Image.open(stream) - return img.size + size = Image.open(stream).size + value.seek(0) + return size class MaxSizeValidator(BaseSizeValidator): diff --git a/tests/test_models.py b/tests/test_models.py index 021c912..f681e7a 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -227,15 +227,17 @@ def test_render_variations_overwrite(self, db, image_upload_file): class TestValidators(TestStdImage): def test_max_size_validator(self, admin_client): - admin_client.post('/admin/tests/maxsizemodel/add/', { + response = admin_client.post('/admin/tests/maxsizemodel/add/', { 'image': self.fixtures['600x400.jpg'], }) + assert 'too large' in response.context['adminform'].form.errors['image'][0] assert not os.path.exists(os.path.join(IMG_DIR, '800x600.jpg')) def test_min_size_validator(self, admin_client): - admin_client.post('/admin/tests/minsizemodel/add/', { + response = admin_client.post('/admin/tests/minsizemodel/add/', { 'image': self.fixtures['100.gif'], }) + assert 'too small' in response.context['adminform'].form.errors['image'][0] assert not os.path.exists(os.path.join(IMG_DIR, '100.gif'))