axel: accept XMLSchemaValidationError on encode or decode (#62631)

This commit is contained in:
Nicolas Roche 2022-03-11 10:22:30 +01:00
parent b1b80e5fa3
commit 4a2745b0df
2 changed files with 10 additions and 7 deletions

View File

@ -69,12 +69,14 @@ def test_bool_mapping(bool_type, value, expected, py_expected):
)
schema = CaluireAxelSchema(xsd, 'PORTAIL')
xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
assert xml_data.find('BOOL').text == expected
if py_expected is None:
with pytest.raises(xmlschema.XMLSchemaValidationError):
xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
assert xml_data.find('BOOL').text == expected
schema.decode(xml_data)
else:
xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
assert xml_data.find('BOOL').text == expected
json_data = schema.decode(xml_data)
assert json_data['BOOL'] is py_expected

View File

@ -48,10 +48,9 @@ def test_date_mapping(date_type):
json_data = schema.decode(xml_data)
assert json_data['DATE'] == '2019-12-12'
xml_data = schema.encode({'PORTAIL': {'DATE': 'foobar'}})
assert xml_data.find('DATE').text == 'foobar'
with pytest.raises(xmlschema.XMLSchemaValidationError):
xml_data = schema.encode({'PORTAIL': {'DATE': 'foobar'}})
assert xml_data.find('DATE').text == 'foobar'
schema.decode(xml_data)
if date_type == 'DATEType':
@ -107,12 +106,14 @@ def test_bool_mapping(bool_type, value, expected, py_expected):
)
schema = AxelSchema(xsd, 'PORTAIL')
xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
assert xml_data.find('BOOL').text == expected
if py_expected is None:
with pytest.raises(xmlschema.XMLSchemaValidationError):
xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
assert xml_data.find('BOOL').text == expected
schema.decode(xml_data)
else:
xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
assert xml_data.find('BOOL').text == expected
json_data = schema.decode(xml_data)
assert json_data['BOOL'] is py_expected