def test_serialize_extensions(self):
    serializer = base_extensions.ExtensionsTemplate()
    data = {'extensions': [{'name': 'Public Image Extension', 'namespace': 'http://foo.com/api/ext/pie/v1.0', 'alias': 'RS-PIE', 'updated': '2011-01-22T13:25:27-06:00', 'description': 'Adds the capability to share an image.', 'links': [{'rel': 'describedby', 'type': 'application/pdf', 'type': 'application/vnd.sun.wadl+xml', 'href': 'http://foo.com/api/ext/cs-pie.pdf'}, {'rel': 'describedby', 'type': 'application/vnd.sun.wadl+xml', 'href': 'http://foo.com/api/ext/cs-pie.wadl'}]}, {'name': 'Cloud Block Storage', 'namespace': 'http://foo.com/api/ext/cbs/v1.0', 'alias': 'RS-CBS', 'updated': '2011-01-12T11:22:33-06:00', 'description': 'Allows mounting cloud block storage.', 'links': [{'rel': 'describedby', 'type': 'application/pdf', 'href': 'http://foo.com/api/ext/cs-cbs.pdf'}, {'rel': 'describedby', 'type': 'application/vnd.sun.wadl+xml', 'href': 'http://foo.com/api/ext/cs-cbs.wadl'}]}]}
    xml = serializer.serialize(data)
    root = etree.XML(xml)
    ext_elems = root.findall('{0}extension'.format(NS))
    self.assertEqual(len(ext_elems), 2)
    for (i, ext_elem) in enumerate(ext_elems):
        ext_dict = data['extensions'][i]
        self.assertEqual(ext_elem.findtext('{0}description'.format(NS)), ext_dict['description'])
        for key in ['name', 'namespace', 'alias', 'updated']:
            self.assertEqual(ext_elem.get(key), ext_dict[key])
        link_nodes = ext_elem.findall('{0}link'.format(ATOMNS))
        self.assertEqual(len(link_nodes), 2)
        for (i, link) in enumerate(ext_dict['links']):
            for (key, value) in link.items():
                self.assertEqual(link_nodes[i].get(key), value)
    xmlutil.validate_schema(root, 'extensions')
def test_serialize_extensions(self):
    serializer = base_extensions.ExtensionsTemplate()
    data = {'extensions': [{'name': 'Public Image Extension', 'namespace': 'http://foo.com/api/ext/pie/v1.0', 'alias': 'RS-PIE', 'updated': '2011-01-22T13:25:27-06:00', 'description': 'Adds the capability to share an image.', 'links': [{'rel': 'describedby', 'type': 'application/pdf', 'type': 'application/vnd.sun.wadl+xml', 'href': 'http://foo.com/api/ext/cs-pie.pdf'}, {'rel': 'describedby', 'type': 'application/vnd.sun.wadl+xml', 'href': 'http://foo.com/api/ext/cs-pie.wadl'}]}, {'name': 'Cloud Block Storage', 'namespace': 'http://foo.com/api/ext/cbs/v1.0', 'alias': 'RS-CBS', 'updated': '2011-01-12T11:22:33-06:00', 'description': 'Allows mounting cloud block storage.', 'links': [{'rel': 'describedby', 'type': 'application/pdf', 'href': 'http://foo.com/api/ext/cs-cbs.pdf'}, {'rel': 'describedby', 'type': 'application/vnd.sun.wadl+xml', 'href': 'http://foo.com/api/ext/cs-cbs.wadl'}]}]}
    xml = serializer.serialize(data)
    root = etree.XML(xml)
    ext_elems = root.findall('{0}extension'.format(NS))
    self.assertEqual(len(ext_elems), 2)
    for (i, ext_elem) in enumerate(ext_elems):
        ext_dict = data['extensions'][i]
        self.assertEqual(ext_elem.findtext('{0}description'.format(NS)), ext_dict['description'])
        for key in ['name', 'namespace', 'alias', 'updated']:
            self.assertEqual(ext_elem.get(key), ext_dict[key])
        link_nodes = ext_elem.findall('{0}link'.format(ATOMNS))
        self.assertEqual(len(link_nodes), 2)
        for (i, link) in enumerate(ext_dict['links']):
            for (key, value) in link.items():
                self.assertEqual(link_nodes[i].get(key), value)
    xmlutil.validate_schema(root, 'extensions')