Exemple #1
0
def test_get_xml_field_no_data_field():
    with patch.object(api_xml, 'lxml_to_dict') as xmltodict:
        xmltodict.parse.return_value = {
            'Response': {
                'myfield': 'myfield-value'
            }
        }
        res = api_xml._get_xml_field('any_xml', 'myfield')
        assert_equal(res, 'myfield-value')
def test_get_xml_field_with_data_field():
    with patch.object(api_xml, 'xmltodict') as xmltodict:
        xmltodict.parse.return_value = {
            'Response': {
                'Success': {
                    'myfield': {
                        'mydata': 'mydata-value'
                    }
                }
            }
        }
        res = api_xml._get_xml_field('any_xml', 'myfield', 'mydata')
        assert_equal(res, 'mydata-value')
Exemple #3
0
def test_get_xml_field_ExpatError_returns_empty_dict():
    with patch.object(lxml_to_dict, "parse") as parse:
        # Inject dummy values into XMLSyntaxError constructor
        parse.side_effect = XMLSyntaxError(*list(range(5)))
        actual = api_xml._get_xml_field('any_xml', 'myfield')
        assert_equal(actual, {})
Exemple #4
0
def test_get_xml_field_with_KeyError():
    with patch.object(api_xml, 'lxml_to_dict') as xmltodict:
        xmltodict.parse.return_value = {}
        res = api_xml._get_xml_field('any_xml', 'myfield')
        assert_equal(res, {})
def test_get_xml_field_ExpatError_returns_empty_dict():
    with patch.object(xmltodict, "parse") as parse:
        parse.side_effect = xmltodict.expat.ExpatError
        actual = api_xml._get_xml_field('any_xml', 'myfield')
        assert_equal(actual, {})