tests: add checks for file upload, and attachment file upload
This commit is contained in:
parent
e96d7ad1dc
commit
5cb85dab8d
|
@ -1,11 +1,13 @@
|
|||
import pytest
|
||||
import hashlib
|
||||
import os
|
||||
from webtest import Upload
|
||||
|
||||
from wcs.qommon.ident.password_accounts import PasswordAccount
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.workflows import Workflow, EditableWorkflowStatusItem
|
||||
from wcs.wf.jump import JumpWorkflowStatusItem
|
||||
from wcs.wf.attachment import AddAttachmentWorkflowStatusItem
|
||||
from wcs.categories import Category
|
||||
from wcs.roles import Role, logged_users_role
|
||||
from wcs.tracking_code import TrackingCode
|
||||
|
@ -971,3 +973,65 @@ def test_form_captcha(pub):
|
|||
resp = app.get('/')
|
||||
resp = resp.click('test')
|
||||
assert 'Some field' in resp.body
|
||||
|
||||
def test_form_file_field_submit(pub):
|
||||
formdef = create_formdef()
|
||||
formdef.fields = [fields.FileField(id='0', label='file')]
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
|
||||
upload = Upload('test.txt', 'foobar', 'text/plain')
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
resp.forms[0]['f0$file'] = upload
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert 'Check values then click submit.' in resp.body
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert resp.status_int == 302
|
||||
resp = resp.follow()
|
||||
assert 'The form has been recorded' in resp.body
|
||||
resp = resp.click('test.txt')
|
||||
assert resp.location.endswith('/test.txt')
|
||||
resp = resp.follow()
|
||||
assert resp.content_type == 'text/plain'
|
||||
assert resp.body == 'foobar'
|
||||
|
||||
def test_formdata_attachment_download(pub):
|
||||
create_user(pub)
|
||||
wf = Workflow(name='status')
|
||||
st1 = wf.add_status('Status1', 'st1')
|
||||
attach = AddAttachmentWorkflowStatusItem()
|
||||
attach.id = '_attach'
|
||||
attach.by = ['_submitter']
|
||||
st1.items.append(attach)
|
||||
attach.parent = st1
|
||||
wf.store()
|
||||
|
||||
formdef = create_formdef()
|
||||
formdef.workflow_id = wf.id
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/')
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert 'Check values then click submit.' in resp.body
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert resp.status_int == 302
|
||||
resp = resp.follow()
|
||||
assert 'The form has been recorded' in resp.body
|
||||
|
||||
resp.forms[0]['attachment_attach'] = Upload('test.txt', 'foobar', 'text/plain')
|
||||
resp = resp.forms[0].submit('button_attach')
|
||||
|
||||
assert formdef.data_class().count() == 1
|
||||
formdata = formdef.data_class().select()[0]
|
||||
assert formdata.evolution[-1].parts[0].__class__.__name__ == 'AttachmentEvolutionPart'
|
||||
attachment = formdata.evolution[-1].parts[0]
|
||||
assert attachment.content_type == 'text/plain'
|
||||
assert attachment.orig_filename == 'test.txt'
|
||||
|
||||
resp = resp.follow() # back to form page
|
||||
resp = resp.click('test.txt')
|
||||
assert resp.content_type == 'text/plain'
|
||||
assert resp.body == 'foobar'
|
||||
|
|
Loading…
Reference in New Issue