def test_index(self): serializer = flavors.MinimalFlavorsTemplate() fixture = { "flavors": [ next(self.flavors), next(self.flavors), ], } output = serializer.serialize(fixture) root = etree.XML(output) xmlutil.validate_schema(root, 'flavors_index') flavor_elems = root.findall('{0}flavor'.format(NS)) self.assertEqual(len(flavor_elems), 2) for i, flavor_elem in enumerate(flavor_elems): flavor_dict = fixture['flavors'][i] for key in ['name', 'id']: self.assertEqual(flavor_elem.get(key), str(flavor_dict[key])) link_nodes = flavor_elem.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)
def test_index_empty(self): serializer = flavors.MinimalFlavorsTemplate() fixture = { "flavors": [], } output = serializer.serialize(fixture) root = etree.XML(output) xmlutil.validate_schema(root, 'flavors_index') flavor_elems = root.findall('{0}flavor'.format(NS)) self.assertEqual(len(flavor_elems), 0)