blob: 1561931803d22f07dd70b078b18bc17c638324e0 [file] [log] [blame]
Ann Kamyshnikovaf6bd5782014-01-13 14:08:04 +04001# Copyright 2013 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14from lxml import etree
15
Matthew Treinish28f164c2014-03-04 18:55:06 +000016from tempest.common import xml_utils as common
Ann Kamyshnikovaf6bd5782014-01-13 14:08:04 +040017from tempest.tests import base
18
19
20class TestXMLParser(base.TestCase):
21
22 def test_xml_to_json_parser_bool_value(self):
23 node = etree.fromstring('''<health_monitor
24 xmlns="http://openstack.org/quantum/api/v2.0"
25 xmlns:quantum="http://openstack.org/quantum/api/v2.0"
26 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
27 <admin_state_up quantum:type="bool">False</admin_state_up>
28 <fake_state_up quantum:type="bool">True</fake_state_up>
29 </health_monitor>''')
30 body = common.xml_to_json(node)
31 self.assertEqual(body['admin_state_up'], False)
32 self.assertEqual(body['fake_state_up'], True)
33
34 def test_xml_to_json_parser_int_value(self):
35 node = etree.fromstring('''<health_monitor
36 xmlns="http://openstack.org/quantum/api/v2.0"
37 xmlns:quantum="http://openstack.org/quantum/api/v2.0"
38 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
39 <delay quantum:type="long">4</delay>
40 <max_retries quantum:type="int">3</max_retries>
41 </health_monitor>''')
42 body = common.xml_to_json(node)
43 self.assertEqual(body['delay'], 4L)
44 self.assertEqual(body['max_retries'], 3)
45
46 def test_xml_to_json_parser_text_value(self):
47 node = etree.fromstring('''<health_monitor
48 xmlns="http://openstack.org/quantum/api/v2.0"
49 xmlns:quantum="http://openstack.org/quantum/api/v2.0"
50 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
51 <status>ACTIVE</status>
52 </health_monitor>''')
53 body = common.xml_to_json(node)
54 self.assertEqual(body['status'], 'ACTIVE')
55
56 def test_xml_to_json_parser_list_as_value(self):
57 node = etree.fromstring('''<health_monitor
58 xmlns="http://openstack.org/quantum/api/v2.0"
59 xmlns:quantum="http://openstack.org/quantum/api/v2.0"
60 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
61 <elements>
62 <element>first_element</element>
63 <element>second_element</element>
64 </elements>
65 </health_monitor>''')
66 body = common.xml_to_json(node, 'elements')
67 self.assertEqual(body['elements'], ['first_element', 'second_element'])