IATI / pyIATI

pyIATI - a developer's toolkit for IATI - Deprecated - No longer supported
MIT License
5 stars 5 forks source link

Improve help text for validation error `err-not-iati-xml-missing-required-element` #250

Open dalepotter opened 6 years ago

dalepotter commented 6 years ago

In our work to use pyIATI in the test runner for the v2.03 IATI schema work, we test that failing files fail for an expected reason.

The failing file here tests that an non-permitted child element fails schema validation. This creates the following iati.validator.ValidationError object:

(Pdb) error_log = iati.validator.validate_is_iati_xml(dataset, activity_schema)
(Pdb) len(error_log)
1
(Pdb) error_log[0]
<iati.validator.ValidationError object at 0x1044c8048>
(Pdb) error_log[0].name
'err-not-iati-xml-missing-required-element'
(Pdb) error_log[0].info
"<string>:26:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'unexpected-element': This element is not expected. Expected is ( ##other* )."
(Pdb) error_log[0].name
'err-not-iati-xml-missing-required-element'
(Pdb) error_log[0].help
'There are a number of mandatory elements that an IATI data file must contain. Additionally, these must occur in the required order.\nFor more information about what an XML element is, see https://www.w3schools.com/xml/xml_elements.asp'

The generated error err-not-iati-xml-missing-required-element seems unintuitive given that the info attribute states Element 'unexpected-element': This element is not expected. Expected is ( ##other* )..

Is ti worth adding a new mapping to this to generate a new error, for example err-not-iati-xml-unexpected-element ?

hayfield commented 6 years ago

err-not-iati-xml-missing-required-element is created based on the lxml error SCHEMAV_ELEMENT_CONTENT.

The current test for this error related only to missing elements. I would expect that mis-ordered elements will also cause this error, though it is not tested - this seems to be something that should be added.

The description and help attributes should provide useful information, with info being there for completeness sake. This may feed into #231.