def test_xml_declaration(self): serializer = flavors.FlavorTemplate() fixture = { "flavor": { "id": "12", "name": "asdf", "ram": "256", "disk": "10", "vcpus": "", "links": [ { "rel": "self", "href": "http://localhost/v2/fake/flavors/12", }, { "rel": "bookmark", "href": "http://localhost/fake/flavors/12", }, ], }, } output = serializer.serialize(fixture) has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>") self.assertTrue(has_dec)
def test_show_handles_integers(self): serializer = flavors.FlavorTemplate() fixture = { "flavor": { "id": 12, "name": "asdf", "ram": 256, "disk": 10, "rxtx_factor": "1", "swap": "", "vcpus": "", "links": [ { "rel": "self", "href": "http://localhost/v2/fake/flavors/12", }, { "rel": "bookmark", "href": "http://localhost/fake/flavors/12", }, ], }, } output = serializer.serialize(fixture) print output root = etree.XML(output) xmlutil.validate_schema(root, 'flavor') flavor_dict = fixture['flavor'] for key in ['name', 'id', 'ram', 'disk']: self.assertEqual(root.get(key), str(flavor_dict[key])) link_nodes = root.findall('{0}link'.format(ATOMNS)) self.assertEqual(len(link_nodes), 2) for i, link in enumerate(flavor_dict['links']): for key, value in link.items(): self.assertEqual(link_nodes[i].get(key), value)