From 4a2745b0df3ee3f13e52e31de944e70559970f68 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Fri, 11 Mar 2022 10:22:30 +0100 Subject: [PATCH] axel: accept XMLSchemaValidationError on encode or decode (#62631) --- tests/test_caluire_axel_schema.py | 6 ++++-- tests/test_toulouse_axel_schema.py | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/test_caluire_axel_schema.py b/tests/test_caluire_axel_schema.py index 2c392bfd..01d2d2e3 100644 --- a/tests/test_caluire_axel_schema.py +++ b/tests/test_caluire_axel_schema.py @@ -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 diff --git a/tests/test_toulouse_axel_schema.py b/tests/test_toulouse_axel_schema.py index 67c8e1ae..d955559f 100644 --- a/tests/test_toulouse_axel_schema.py +++ b/tests/test_toulouse_axel_schema.py @@ -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