Projet

Général

Profil

0001-field-display-attachment-utf-8-filenames-34783.patch

Nicolas Roche, 08 octobre 2019 18:23

Télécharger (3,91 ko)

Voir les différences:

Subject: [PATCH] field: display attachment utf-8 filenames (#34783)

 tests/test_form_pages.py                        | 15 +++++++++++++++
 tests/test_sessions.py                          | 17 +++++++++++++++++
 .../templates/qommon/forms/widgets/file.html    |  2 +-
 wcs/root.py                                     |  2 +-
 4 files changed, 34 insertions(+), 2 deletions(-)
tests/test_form_pages.py
2680 2680
    assert 'fargo.js' not in resp.body
2681 2681
    assert 'use-file-from-fargo' not in resp.body
2682 2682

  
2683
def test_form_file_field_upload(pub):
2684
    user = create_user(pub)
2685
    formdef = create_formdef()
2686
    formdef.fields = [fields.FileField(id='0', type='file')]
2687
    formdef.store()
2688
    formdef.data_class().wipe()
2689

  
2690
    upload = Upload(u'téêèst👀.txt', 'foobar', 'text/plain')
2691

  
2692
    resp = get_app(pub).get('/test/')
2693
    resp.forms[0]['f0$file'] = upload
2694
    resp = resp.forms[0].submit('submit')
2695
    assert 'Check values then click submit.' in resp.body
2696
    assert u'téêèst👀.txt' in resp.text
2697

  
2683 2698
def test_form_file_field_submit(pub):
2684 2699
    formdef = create_formdef()
2685 2700
    formdef.fields = [fields.FileField(id='0', label='file')]
tests/test_sessions.py
1
# -*- coding: utf-8 -*-
2

  
1 3
import os
2 4
import shutil
3 5
import time
......
199 201
    assert pub.session_manager.session_class.count() == 1
200 202
    session_id = pub.session_manager.session_class.select()[0].id
201 203
    assert 'COM1' in resp.body
204

  
205
def test_tmp_upload(pub, user, app):
206
    user_agent = {'User-agent': 'Mozilla/5.0'}
207
    files = [('field0', u'téêèst👀.txt', r'file content')]
208

  
209
    # submit a file using the endpoint
210
    resp = app.post('/tmp-upload', headers=user_agent, upload_files=files)
211
    assert resp.json[0]['name'] == u'téêèst👀.txt'
212
    token = resp.json[0]['token']
213

  
214
    # retrieve the file from session
215
    session = pub.session_manager.session_class.select()[0]
216
    tempfile = session.get_tempfile_path(token)
217
    with open(tempfile) as handler:
218
        assert handler.read() == r'file content'
wcs/qommon/templates/qommon/forms/widgets/file.html
21 21
       data-error="{% trans "Error during upload." %}"></div>
22 22
</div>
23 23
<div class="fileinfo {% if widget.readonly and widget.has_tempfile_image %}thumbnail{% endif %}">
24
  <span class="filename">{{ widget.tempfile.base_filename }}</span>
24
  <span class="filename">{{ widget.tempfile.orig_filename }}</span>
25 25
{% if not widget.readonly %}
26 26
  <a href="#" class="remove" title="{% trans 'Remove this file' %}">{% trans "remove" %}</a>
27 27
{% elif widget.has_tempfile_image %}
wcs/root.py
296 296
        for k, v in get_request().form.items():
297 297
            if hasattr(v, 'fp'):
298 298
                tempfile = get_session().add_tempfile(v)
299
                results.append({'name': tempfile.get('base_filename'),
299
                results.append({'name': tempfile.get('orig_filename'),
300 300
                                'type': tempfile.get('content_type'),
301 301
                                'size': tempfile.get('size'),
302 302
                                'token': tempfile.get('token')})
303
-