412 |
412 |
|
413 |
413 |
data_class.wipe()
|
414 |
414 |
|
|
415 |
|
|
416 |
def test_formdef_submit_with_varname(pub, local_user):
|
|
417 |
NamedDataSource.wipe()
|
|
418 |
data_source = NamedDataSource(name='foobar')
|
|
419 |
source = [{'id': '1', 'text': 'foo', 'more': 'XXX'},
|
|
420 |
{'id': '2', 'text': 'bar', 'more': 'YYY'}]
|
|
421 |
data_source.data_source = {'type': 'formula', 'value': repr(source)}
|
|
422 |
data_source.store()
|
|
423 |
|
|
424 |
data_source = NamedDataSource(name='foobar_jsonp')
|
|
425 |
data_source.data_source = {'type': 'formula', 'value': 'http://example.com/jsonp'}
|
|
426 |
data_source.store()
|
|
427 |
|
|
428 |
Role.wipe()
|
|
429 |
role = Role(name='test')
|
|
430 |
role.store()
|
|
431 |
local_user.roles = [role.id]
|
|
432 |
local_user.store()
|
|
433 |
|
|
434 |
FormDef.wipe()
|
|
435 |
formdef = FormDef()
|
|
436 |
formdef.name = 'test'
|
|
437 |
formdef.fields = [
|
|
438 |
fields.StringField(id='0', label='foobar0', varname='foobar0'),
|
|
439 |
fields.ItemField(id='1', label='foobar1', varname='foobar1',
|
|
440 |
data_source={'type': 'foobar'}),
|
|
441 |
fields.ItemField(id='2', label='foobar2', varname='foobar2',
|
|
442 |
data_source={'type': 'foobar_jsonp'}),
|
|
443 |
]
|
|
444 |
formdef.store()
|
|
445 |
data_class = formdef.data_class()
|
|
446 |
|
|
447 |
resp = get_app(pub).post_json('/api/formdefs/test/submit', {'data': {}}, status=403)
|
|
448 |
assert resp.json['err'] == 1
|
|
449 |
assert resp.json['err_desc'] == 'no user'
|
|
450 |
|
|
451 |
signed_url = sign_url('http://example.net/api/formdefs/test/submit' +
|
|
452 |
'?format=json&orig=coucou&email=%s' % urllib.quote(local_user.email), '1234')
|
|
453 |
url = signed_url[len('http://example.net'):]
|
|
454 |
resp = get_app(pub).post_json(url,
|
|
455 |
{'data':
|
|
456 |
{'foobar0': 'xxx',
|
|
457 |
'foobar1': '1',
|
|
458 |
'foobar1_structured': {
|
|
459 |
'id': '1',
|
|
460 |
'text': 'foo',
|
|
461 |
'more': 'XXX',
|
|
462 |
},
|
|
463 |
'foobar2': 'bar',
|
|
464 |
'foobar2_raw': '10',
|
|
465 |
}
|
|
466 |
})
|
|
467 |
assert resp.json['err'] == 0
|
|
468 |
assert data_class.get(resp.json['data']['id']).status == 'wf-new'
|
|
469 |
assert data_class.get(resp.json['data']['id']).user_id == str(local_user.id)
|
|
470 |
assert data_class.get(resp.json['data']['id']).tracking_code is None
|
|
471 |
assert data_class.get(resp.json['data']['id']).data['0'] == 'xxx'
|
|
472 |
assert data_class.get(resp.json['data']['id']).data['1'] == '1'
|
|
473 |
assert data_class.get(resp.json['data']['id']).data['1_structured'] == source[0]
|
|
474 |
assert data_class.get(resp.json['data']['id']).data['2'] == '10'
|
|
475 |
assert data_class.get(resp.json['data']['id']).data['2_display'] == 'bar'
|
|
476 |
|
|
477 |
data_class.wipe()
|
|
478 |
|
415 |
479 |
def test_categories(pub):
|
416 |
480 |
FormDef.wipe()
|
417 |
481 |
Category.wipe()
|