Projet

Général

Profil

0003-axel-accept-XMLSchemaValidationError-on-encode-or-de.patch

Nicolas Roche, 11 mars 2022 13:00

Télécharger (3,45 ko)

Voir les différences:

Subject: [PATCH 3/9] axel: accept XMLSchemaValidationError on encode or decode
 (#62631)

 tests/test_caluire_axel_schema.py  |  7 +++++--
 tests/test_toulouse_axel_schema.py | 11 ++++++-----
 2 files changed, 11 insertions(+), 7 deletions(-)
tests/test_caluire_axel_schema.py
64 64
        </xsd:sequence>
65 65
    </xsd:complexType>
66 66
    <xsd:element name="PORTAIL" type="PORTAILType"/>
67 67
</xsd:schema>""".format(
68 68
        path=XSD_BASE_DIR, bool_type=bool_type
69 69
    )
70 70

  
71 71
    schema = CaluireAxelSchema(xsd, 'PORTAIL')
72
    xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
73
    assert xml_data.find('BOOL').text == expected
74 72

  
75 73
    if py_expected is None:
76 74
        with pytest.raises(xmlschema.XMLSchemaValidationError):
75
            xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
76
            assert xml_data.find('BOOL').text == expected
77 77
            schema.decode(xml_data)
78 78
    else:
79
        xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
80
        assert xml_data.find('BOOL').text == expected
81
        schema.decode(xml_data)
79 82
        json_data = schema.decode(xml_data)
80 83
        assert json_data['BOOL'] is py_expected
tests/test_toulouse_axel_schema.py
43 43

  
44 44
    schema = AxelSchema(xsd, 'PORTAIL')
45 45
    xml_data = schema.encode({'PORTAIL': {'DATE': '2019-12-12'}})
46 46
    assert xml_data.find('DATE').text == '12/12/2019'
47 47

  
48 48
    json_data = schema.decode(xml_data)
49 49
    assert json_data['DATE'] == '2019-12-12'
50 50

  
51
    xml_data = schema.encode({'PORTAIL': {'DATE': 'foobar'}})
52
    assert xml_data.find('DATE').text == 'foobar'
53

  
54 51
    with pytest.raises(xmlschema.XMLSchemaValidationError):
52
        xml_data = schema.encode({'PORTAIL': {'DATE': 'foobar'}})
53
        assert xml_data.find('DATE').text == 'foobar'
55 54
        schema.decode(xml_data)
56 55

  
57 56
    if date_type == 'DATEType':
58 57
        xml_data = schema.encode({'PORTAIL': {'DATE': ''}})
59 58
        assert xml_data.find('DATE').text == ''
60 59

  
61 60
        json_data = schema.decode(xml_data)
62 61
        assert json_data['DATE'] is None
......
102 101
        </xsd:sequence>
103 102
    </xsd:complexType>
104 103
    <xsd:element name="PORTAIL" type="PORTAILType"/>
105 104
</xsd:schema>""".format(
106 105
        path=XSD_BASE_DIR, bool_type=bool_type
107 106
    )
108 107

  
109 108
    schema = AxelSchema(xsd, 'PORTAIL')
110
    xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
111
    assert xml_data.find('BOOL').text == expected
112 109

  
113 110
    if py_expected is None:
114 111
        with pytest.raises(xmlschema.XMLSchemaValidationError):
112
            xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
113
            assert xml_data.find('BOOL').text == expected
115 114
            schema.decode(xml_data)
116 115
    else:
116
        xml_data = schema.encode({'PORTAIL': {'BOOL': value}})
117
        assert xml_data.find('BOOL').text == expected
117 118
        json_data = schema.decode(xml_data)
118 119
        assert json_data['BOOL'] is py_expected
119
-