workflows: humanize size of export_to_model's document (#51941)

This commit is contained in:
Lauréline Guérin 2021-03-29 09:55:25 +02:00
parent 82cb70b26a
commit c1909f5321
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 41 additions and 2 deletions

View File

@ -12,6 +12,7 @@ except ImportError:
lasso = None
import pytest
from quixote.http_request import Upload as QuixoteUpload
from utilities import clean_temporary_pub, create_temporary_pub, get_app, login
from webtest import Upload
@ -19,6 +20,7 @@ from wcs import fields
from wcs.carddef import CardDef
from wcs.formdef import FormDef
from wcs.qommon.errors import ConnectionError
from wcs.qommon.form import UploadedFile
from wcs.qommon.http_request import HTTPRequest
from wcs.wf.create_carddata import CreateCarddataWorkflowStatusItem
from wcs.wf.create_formdata import CreateFormdataWorkflowStatusItem, Mapping
@ -1300,6 +1302,42 @@ def test_workflows_variables_edit_with_all_action_types(pub):
assert Workflow.get(1).variables_formdef.fields[0].varname == 'xxx'
def test_workflows_export_to_model_action_display(pub):
create_superuser(pub)
Workflow.wipe()
workflow = Workflow(name='foo')
baz_status = workflow.add_status(name='baz')
export_to = ExportToModel()
export_to.label = 'create doc'
baz_status.items.append(export_to)
workflow.store()
app = login(get_app(pub))
resp = app.get('/backoffice/workflows/1/status/1/')
assert 'Document Creation (no model set)' in resp
upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
upload.fp = io.BytesIO()
upload.fp.write(b'HELLO WORLD')
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
export_to.id = '_export_to'
export_to.by = ['_submitter']
workflow.store()
resp = app.get('/backoffice/workflows/1/status/1/')
assert 'Document Creation (with model named test.rtf of 11 bytes)' in resp
upload.fp.write(b'HELLO WORLD' * 4242)
upload.fp.seek(0)
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
workflow.store()
resp = app.get('/backoffice/workflows/1/status/1/')
assert 'Document Creation (with model named test.rtf of 45.6 KB)' in resp
def test_workflows_variables_with_export_to_model_action(pub):
test_workflows_variables(pub)

View File

@ -26,6 +26,7 @@ import time
import zipfile
from xml.etree import ElementTree as ET
from django.template.defaultfilters import filesizeformat
from django.utils.encoding import force_bytes, force_text
from quixote import get_publisher, get_request, get_response
from quixote.directory import Directory
@ -245,9 +246,9 @@ class ExportToModel(WorkflowStatusItem):
def get_line_details(self):
if self.model_file:
return _('with model named %(file_name)s of %(size)s bytes') % {
return _('with model named %(file_name)s of %(size)s') % {
'file_name': self.model_file.base_filename,
'size': self.model_file.size,
'size': filesizeformat(self.model_file.size),
}
else:
return _('no model set')