8 |
8 |
import time
|
9 |
9 |
import hashlib
|
10 |
10 |
import random
|
|
11 |
import urllib
|
11 |
12 |
import urlparse
|
12 |
13 |
import xml.etree.ElementTree as ET
|
13 |
14 |
import zipfile
|
... | ... | |
21 |
22 |
|
22 |
23 |
from quixote import cleanup, get_publisher
|
23 |
24 |
from qommon import ods
|
|
25 |
from wcs.api_utils import sign_url
|
24 |
26 |
from wcs.qommon import errors, sessions
|
25 |
27 |
from wcs.qommon.form import PicklableUpload
|
26 |
28 |
from qommon.ident.password_accounts import PasswordAccount
|
... | ... | |
61 |
63 |
pub.cfg['language'] = {'language': 'en'}
|
62 |
64 |
pub.write_cfg()
|
63 |
65 |
fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
|
|
66 |
fd.write('''
|
|
67 |
[api-secrets]
|
|
68 |
coucou = 1234
|
|
69 |
''')
|
64 |
70 |
fd.close()
|
65 |
71 |
|
66 |
72 |
return pub
|
... | ... | |
1541 |
1547 |
# check agent name is displayed next to pending submission
|
1542 |
1548 |
assert '(%s)' % user.display_name in resp.body
|
1543 |
1549 |
|
|
1550 |
def test_backoffice_submission_initiated_from_welco(pub, welco_url):
|
|
1551 |
user = create_user(pub)
|
|
1552 |
create_environment(pub)
|
|
1553 |
|
|
1554 |
app = login(get_app(pub))
|
|
1555 |
resp = app.get('/backoffice/')
|
|
1556 |
assert not 'Submission' in resp.body
|
|
1557 |
app.get('/backoffice/submission/', status=403)
|
|
1558 |
|
|
1559 |
formdef = FormDef.get_by_urlname('form-title')
|
|
1560 |
formdef.fields = [
|
|
1561 |
fields.PageField(id='0', label='1st PAGE', type='page',
|
|
1562 |
condition={'type': 'python', 'value': 'form_submission_channel != "counter" and is_in_backoffice'}),
|
|
1563 |
fields.StringField(id='1', label='Field on 1st page', type='string'),
|
|
1564 |
fields.PageField(id='2', label='2nd PAGE', type='page'),
|
|
1565 |
fields.StringField(id='3', label='Field on 2nd page', type='string'),
|
|
1566 |
]
|
|
1567 |
formdef.backoffice_submission_roles = user.roles[:]
|
|
1568 |
formdef.store()
|
|
1569 |
|
|
1570 |
def post_formdata():
|
|
1571 |
signed_url = sign_url('http://example.net/api/formdefs/form-title/submit' +
|
|
1572 |
'?format=json&orig=coucou&email=%s' % urllib.quote(user.email), '1234')
|
|
1573 |
url = signed_url[len('http://example.net'):]
|
|
1574 |
resp = get_app(pub).post_json(url, {
|
|
1575 |
'meta': {
|
|
1576 |
'draft': True,
|
|
1577 |
'backoffice-submission': True,
|
|
1578 |
},
|
|
1579 |
'data': {},
|
|
1580 |
'context': {
|
|
1581 |
'channel': 'counter'
|
|
1582 |
}
|
|
1583 |
})
|
|
1584 |
return resp.json['data']['id']
|
|
1585 |
|
|
1586 |
resp = app.get('/backoffice/management/form-title/%s/' % post_formdata())
|
|
1587 |
resp = resp.follow() # -> /backoffice/submission/form-title/XXX
|
|
1588 |
resp = resp.follow() # -> /backoffice/submission/form-title/?mt=XYZ
|
|
1589 |
|
|
1590 |
# second page should be shown
|
|
1591 |
pq = resp.pyquery.remove_namespaces()
|
|
1592 |
assert pq('#steps li.current .label').text() == '2nd PAGE'
|
|
1593 |
assert 'Field on 2nd page' in resp.body # and in fields
|
|
1594 |
|
|
1595 |
# reverse condition
|
|
1596 |
formdef.fields[0].condition['value'] = 'form_submission_channel == "counter" and is_in_backoffice'
|
|
1597 |
formdef.store()
|
|
1598 |
|
|
1599 |
resp = app.get('/backoffice/management/form-title/%s/' % post_formdata())
|
|
1600 |
resp = resp.follow() # -> /backoffice/submission/form-title/XXX
|
|
1601 |
resp = resp.follow() # -> /backoffice/submission/form-title/?mt=XYZ
|
|
1602 |
|
|
1603 |
pq = resp.pyquery.remove_namespaces()
|
|
1604 |
assert pq('#steps li.current .label').text() == '1st PAGE'
|
|
1605 |
assert 'Field on 1st page' in resp.body # and in fields
|
|
1606 |
|
1544 |
1607 |
def test_backoffice_parallel_submission(pub):
|
1545 |
1608 |
user = create_user(pub)
|
1546 |
1609 |
create_environment(pub)
|