658 |
658 |
assert resp.request.environ['PATH_INFO'].endswith(file2.filename)
|
659 |
659 |
|
660 |
660 |
|
|
661 |
def test_formdata_generated_document_ods_download(pub):
|
|
662 |
create_user(pub)
|
|
663 |
wf = Workflow(name='status')
|
|
664 |
st1 = wf.add_status('Status1', 'st1')
|
|
665 |
export_to = st1.add_action('export_to_model', id='_export_to')
|
|
666 |
export_to.convert_to_pdf = False
|
|
667 |
export_to.label = 'create doc'
|
|
668 |
template_filename = os.path.join(os.path.dirname(__file__), '..', 'template.ods')
|
|
669 |
with open(template_filename, 'rb') as fd:
|
|
670 |
template = fd.read()
|
|
671 |
upload = QuixoteUpload('/foo/template.ods', content_type='application/octet-stream')
|
|
672 |
upload.fp = io.BytesIO()
|
|
673 |
upload.fp.write(template)
|
|
674 |
upload.fp.seek(0)
|
|
675 |
export_to.model_file = UploadedFile(pub.app_dir, None, upload)
|
|
676 |
export_to.by = ['_submitter']
|
|
677 |
wf.store()
|
|
678 |
|
|
679 |
FormDef.wipe()
|
|
680 |
formdef = FormDef()
|
|
681 |
formdef.name = 'test_formdata_generated_document_ods_download'
|
|
682 |
formdef.url_name = 'test'
|
|
683 |
formdef.workflow_id = wf.id
|
|
684 |
formdef.fields = []
|
|
685 |
formdef.store()
|
|
686 |
formdef.data_class().wipe()
|
|
687 |
|
|
688 |
resp = login(get_app(pub), username='foo', password='foo').get('/test/')
|
|
689 |
resp = resp.forms[0].submit('submit') # -> validation
|
|
690 |
resp = resp.forms[0].submit('submit') # -> submit
|
|
691 |
resp = resp.follow()
|
|
692 |
|
|
693 |
resp = resp.form.submit('button_export_to')
|
|
694 |
|
|
695 |
resp = resp.follow() # $form/$id/create_doc
|
|
696 |
resp = resp.follow() # $form/$id/create_doc/
|
|
697 |
with io.BytesIO(resp.body) as generated_ods:
|
|
698 |
with zipfile.ZipFile(generated_ods) as z_ods:
|
|
699 |
for name in z_ods.namelist():
|
|
700 |
if name != 'content.xml':
|
|
701 |
continue
|
|
702 |
content_bytes = z_ods.read(name)
|
|
703 |
assert b' xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" ' in content_bytes
|
|
704 |
assert b'>test_formdata_generated_document_ods_download<' in content_bytes
|
|
705 |
# check it's valid XML
|
|
706 |
ET.tostring(ET.XML(content_bytes))
|
|
707 |
|
|
708 |
|
661 |
709 |
@pytest.mark.skipif(transform_to_pdf is None, reason='libreoffice not found')
|
662 |
710 |
def test_formdata_generated_document_odt_to_pdf_download(pub):
|
663 |
711 |
create_user(pub)
|