Project

General

Profile

0002-tests-check-the-json-export-has-no-value-for-fields-.patch

Frédéric Péters, 02 February 2016 12:43 PM

Download (4.65 KB)

View differences:

Subject: [PATCH 2/2] tests: check the json export has no value for fields from
 hidden pages

 tests/test_form_pages.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
tests/test_form_pages.py
458 458
    resp = resp.forms[0].submit('submit') # should go to second page
459 459
    assert 'f3' in resp.forms[0].fields
460 460

  
461
def test_form_multi_page_condition_json_check(pub):
462
    # make sure the json export has no value for fields from hidden pages
463
    formdef = create_formdef()
464
    formdef.fields = [fields.PageField(id='0', label='1st page', type='page'),
465
            fields.BoolField(id='1', label='checkbox', varname='checkbox'),
466
            fields.PageField(id='2', label='2nd page', type='page',
467
                condition='var_checkbox == "False"'),
468
            fields.StringField(id='3', label='string 2', varname='st2'),
469
            fields.PageField(id='4', label='3rd page', type='page',
470
                condition='var_checkbox == "True"'),
471
            fields.StringField(id='5', label='string 3', varname='st3'),
472
            ]
473
    formdef.store()
474
    resp = get_app(pub).get('/test/')
475
    formdef.data_class().wipe()
476
    resp.form['f1'].checked = True
477
    resp = resp.form.submit('submit') # should go straight to 3rd page
478
    assert 'f5' in resp.form.fields
479
    resp.form['f5'] = 'VALUE F5'
480
    resp = resp.form.submit('submit')
481
    assert 'Check values then click submit.' in resp.body
482
    assert resp.form['previous']
483
    resp = resp.form.submit('previous')
484
    resp = resp.form.submit('previous')
485

  
486
    # back to first page
487
    assert 'f1' in resp.form.fields
488
    resp.form['f1'].checked = False
489
    resp = resp.form.submit('submit') # should go to second page
490
    assert 'f3' in resp.form.fields
491
    resp.form['f3'] = 'VALUE F3'
492
    resp = resp.form.submit('submit')
493
    assert 'Check values then click submit.' in resp.body
494

  
495
    resp = resp.form.submit()
496

  
497
    assert len(formdef.data_class().select()) == 1
498
    json_dict = formdef.data_class().select()[0].get_json_export_dict()
499
    assert json_dict['fields']['st2'] == 'VALUE F3'
500
    assert json_dict['fields']['st3'] is None
501

  
502
def test_form_multi_page_condition_no_confirmation_json_check(pub):
503
    # same as above but without the confirmation page.
504
    formdef = create_formdef()
505
    formdef.confirmation = False
506
    formdef.fields = [fields.PageField(id='0', label='1st page', type='page'),
507
            fields.BoolField(id='1', label='checkbox', varname='checkbox'),
508
            fields.PageField(id='2', label='2nd page', type='page',
509
                condition='var_checkbox == "False"'),
510
            fields.StringField(id='3', label='string 2', varname='st2'),
511
            fields.PageField(id='4', label='3rd page', type='page',
512
                condition='var_checkbox == "True"'),
513
            fields.StringField(id='5', label='string 3', varname='st3'),
514
            fields.PageField(id='6', label='4th page', type='page'),
515
            fields.CommentField(id='7', label='Check values then click submit.',
516
                type='comment'),
517
            ]
518
    formdef.store()
519
    resp = get_app(pub).get('/test/')
520
    formdef.data_class().wipe()
521
    resp.form['f1'].checked = True
522
    resp = resp.form.submit('submit') # should go straight to 3rd page
523
    assert 'f5' in resp.form.fields
524
    resp.form['f5'] = 'VALUE F5'
525
    resp = resp.form.submit('submit')
526
    assert 'Check values then click submit.' in resp.body
527
    assert resp.form['previous']
528
    resp = resp.form.submit('previous')
529
    resp = resp.form.submit('previous')
530

  
531
    # back to first page
532
    assert 'f1' in resp.form.fields
533
    resp.form['f1'].checked = False
534
    resp = resp.form.submit('submit') # should go to second page
535
    assert 'f3' in resp.form.fields
536
    resp.form['f3'] = 'VALUE F3'
537
    resp = resp.form.submit('submit')
538
    assert 'Check values then click submit.' in resp.body
539

  
540
    resp = resp.form.submit('submit')
541

  
542
    assert len(formdef.data_class().select()) == 1
543
    json_dict = formdef.data_class().select()[0].get_json_export_dict()
544
    assert json_dict['fields']['st2'] == 'VALUE F3'
545
    assert json_dict['fields']['st3'] is None
546

  
461 547
def test_form_multi_page_condition_data_source(pub):
462 548
    formdef = create_formdef()
463 549
    formdef.fields = [fields.PageField(id='0', label='1st page', type='page'),
464
-