misc: return correct mimetype for thumbnailed files (#11307)

This commit is contained in:
Frédéric Péters 2016-06-11 13:53:22 +02:00
parent a9b8c3af0c
commit 79215353eb
2 changed files with 30 additions and 0 deletions

View File

@ -11,6 +11,11 @@ import base64
from webtest import Upload
import mock
try:
from PIL import Image
except ImportError:
Image = None
from quixote.http_request import Upload as QuixoteUpload
from wcs.qommon.form import UploadedFile
from wcs.qommon.ident.password_accounts import PasswordAccount
@ -1457,6 +1462,30 @@ def test_form_file_field_submit(pub):
assert resp.content_type == 'text/plain'
assert resp.body == 'foobar'
def test_form_file_field_image_submit(pub):
formdef = create_formdef()
formdef.fields = [fields.FileField(id='0', label='file')]
formdef.store()
formdef.data_class().wipe()
image_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()
upload = Upload('test.jpg', image_content, 'image/jpeg')
app = get_app(pub)
resp = app.get('/test/')
resp.forms[0]['f0$file'] = upload
resp = resp.forms[0].submit('submit')
assert 'Check values then click submit.' in resp.body
assert '<img alt="" src="tempfile?' in resp.body
tempfile_id = resp.body[resp.body.index('tempfile?'):].split('&', 1)[0].split('=')[1]
resp = app.get('/test/tempfile?t=%s' % tempfile_id)
assert resp.body == image_content
if Image: # check thumbnailing
resp = app.get('/test/tempfile?t=%s&thumbnail=1' % tempfile_id)
assert resp.content_type == 'image/png'
def test_form_file_field_submit_wrong_mimetype(pub):
formdef = create_formdef()
formdef.fields = [fields.FileField(id='0', label='file')]

View File

@ -1018,6 +1018,7 @@ class FormPage(Directory):
except IOError:
# too bad we couldn't load the image, return the whole file :/
return file_pointer.read()
response.set_content_type('image/png')
return image_thumb_fp.getvalue()
else:
return file_pointer.read()