Projet

Général

Profil

0002-fields-don-t-crash-exporting-incomplete-post-conditi.patch

Frédéric Péters, 01 novembre 2016 15:51

Télécharger (2,18 ko)

Voir les différences:

Subject: [PATCH 2/2] fields: don't crash exporting incomplete post-condition
 (#13815)

 tests/test_formdef_import.py | 11 +++++++++++
 wcs/fields.py                |  4 ++--
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/test_formdef_import.py
310 310
    assert fd2.fields[0].type == 'page'
311 311
    assert fd2.fields[0].post_conditions == formdef.fields[0].post_conditions
312 312

  
313
    # test incomplete post condition (not allowed anymore but old formdefs may
314
    # have this)
315
    formdef.fields = [
316
        fields.PageField(id='1', type='page',
317
            post_conditions=[{'condition': 'blah', 'error_message': None}]),
318
    ]
319
    formdef_xml = formdef.export_to_xml(include_id=True)
320
    fd2 = FormDef.import_from_xml_tree(formdef_xml, include_id=True)
321
    assert fd2.fields[0].post_conditions[0]['condition'] == 'blah'
322
    assert fd2.fields[0].post_conditions[0]['error_message'] == ''
323

  
313 324
def test_workflow_roles():
314 325
    Role.wipe()
315 326
    role = Role(name='blah')
wcs/fields.py
1463 1463
        for post_condition in self.post_conditions:
1464 1464
            condition_node = ET.SubElement(conditions_node, 'post_condition')
1465 1465
            ET.SubElement(condition_node, 'condition').text = unicode(
1466
                    post_condition['condition'], charset, 'replace')
1466
                    post_condition['condition'] or '', charset, 'replace')
1467 1467
            ET.SubElement(condition_node, 'error_message').text = unicode(
1468
                    post_condition['error_message'], charset, 'replace')
1468
                    post_condition['error_message'] or '', charset, 'replace')
1469 1469

  
1470 1470
    def fill_admin_form(self, form):
1471 1471
        form.add(StringWidget, 'label', title = _('Label'), value = self.label,
1472
-