tests: add test importing formdef/workflow from url
This commit is contained in:
parent
fc9357b1cd
commit
0f26a16d28
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import mock
|
||||
import os
|
||||
import re
|
||||
import tarfile
|
||||
|
@ -13,6 +14,7 @@ from webtest import Upload
|
|||
from django.utils.six import StringIO, BytesIO
|
||||
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.qommon.errors import ConnectionError
|
||||
from wcs.categories import Category
|
||||
from wcs.data_sources import NamedDataSource
|
||||
from wcs.wscalls import NamedWsCall
|
||||
|
@ -1023,6 +1025,37 @@ def test_form_import(pub):
|
|||
assert FormDef.get(1).fields[1].id == '2'
|
||||
|
||||
|
||||
def test_form_import_from_url(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
formdef_xml = ET.tostring(formdef.export_to_xml(include_id=True))
|
||||
|
||||
FormDef.wipe()
|
||||
assert FormDef.count() == 0
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/forms/')
|
||||
resp = resp.click(href='import')
|
||||
resp = resp.form.submit()
|
||||
assert 'You have to enter a file or a URL' in resp
|
||||
|
||||
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
|
||||
urlopen.side_effect = ConnectionError('...')
|
||||
resp.form['url'] = 'http://remote.invalid/test.wcs'
|
||||
resp = resp.form.submit()
|
||||
assert 'Error loading form' in resp
|
||||
urlopen.side_effect = lambda *args: StringIO(formdef_xml.decode())
|
||||
resp.form['url'] = 'http://remote.invalid/test.wcs'
|
||||
resp = resp.form.submit()
|
||||
assert FormDef.count() == 1
|
||||
|
||||
|
||||
def test_form_qrcode(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from io import StringIO
|
||||
import mock
|
||||
import os
|
||||
import re
|
||||
|
||||
|
@ -12,6 +14,7 @@ import pytest
|
|||
from webtest import Upload
|
||||
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.qommon.errors import ConnectionError
|
||||
from wcs.roles import Role
|
||||
from wcs.workflows import (
|
||||
Workflow, WorkflowCriticalityLevel, DisplayMessageWorkflowStatusItem,
|
||||
|
@ -320,6 +323,36 @@ def test_workflows_export_import(pub):
|
|||
assert Workflow.count() == 2
|
||||
|
||||
|
||||
def test_workflows_import_from_url(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
workflow.add_status(name='baz')
|
||||
workflow.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/1/')
|
||||
resp = resp.click('Export')
|
||||
assert resp.content_type == 'application/x-wcs-form'
|
||||
wf_export = resp.body
|
||||
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
resp = resp.click('Import')
|
||||
resp = resp.form.submit()
|
||||
assert 'You have to enter a file or a URL' in resp
|
||||
|
||||
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
|
||||
urlopen.side_effect = ConnectionError('...')
|
||||
resp.form['url'] = 'http://remote.invalid/test.wcs'
|
||||
resp = resp.form.submit()
|
||||
assert 'Error loading form' in resp
|
||||
urlopen.side_effect = lambda *args: StringIO(wf_export.decode())
|
||||
resp.form['url'] = 'http://remote.invalid/test.wcs'
|
||||
resp = resp.form.submit()
|
||||
assert Workflow.count() == 2
|
||||
|
||||
|
||||
def test_workflows_export_import_create_role(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
|
|
Loading…
Reference in New Issue