from io import BytesIO import pytest from werkzeug.datastructures import FileStorage from core_notifications.images.forms import ImageForm class TestImageForm: def test_success(self, app, db_session): with app.test_request_context(): source = BytesIO() file = FileStorage(stream=source, filename="test.png") form = ImageForm(file=file) assert form.validate() def test_invalid_ext(self, app, db_session): with app.test_request_context(): source = BytesIO() file = FileStorage(stream=source, filename="test.txt") form = ImageForm(file=file) assert not form.validate() def test_miss_file(self, app): with app.test_request_context(): form = ImageForm(file=None) assert not form.validate() @pytest.mark.parametrize( "ext", tuple("jpg jpe jpeg png gif svg bmp webp".split()), ) def test_valid_extensions(self, app, db_session, ext): with app.test_request_context(): source = BytesIO() file = FileStorage(stream=source, filename=f"test.{ext}") form = ImageForm(file=file) assert form.validate()