def test_multi_choice_image_xml(self): req = webob.Request.blank('/images/1') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/xml") root = etree.XML(res.body) self.assertTrue(root.xpath('/ns:choices', namespaces=NS)) versions = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(versions), 1) version = versions[0] self.assertEqual(version.get('id'), 'v2.0') self.assertEqual(version.get('status'), 'CURRENT') media_types = version.xpath('ns:media-types/ns:media-type', namespaces=NS) self.assertTrue( common.compare_media_types(media_types, VERSIONS['v2.0']['media-types'])) links = version.xpath('atom:link', namespaces=NS) self.assertTrue( common.compare_links(links, [{ 'rel': 'self', 'href': 'http://localhost/v2/images/1' }]))
def test_get_version_list_xml(self): req = webob.Request.blank('/') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/xml") root = etree.XML(res.body) print res.body xmlutil.validate_schema(root, 'versions') self.assertTrue(root.xpath('/ns:versions', namespaces=NS)) versions = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(versions), 1) for i, v in enumerate(['v2.0']): version = versions[i] expected = VERSIONS[v] for key in ['id', 'status', 'updated']: self.assertEqual(version.get(key), expected[key]) (link, ) = version.xpath('atom:link', namespaces=NS) self.assertTrue( common.compare_links(link, [{ 'rel': 'self', 'href': 'http://localhost/%s/' % v }]))
def test_versions_multi_xml_serializer(self): versions_data = { 'choices': [ { "id": "2.7", "updated": "2011-07-18T11:30:00Z", "status": "DEPRECATED", "media-types": VERSIONS['v2.0']['media-types'], "links": [ { "rel": "self", "href": "http://test/v2/images", }, ], }, ] } serializer = versions.ChoicesTemplate() response = serializer.serialize(versions_data) root = etree.XML(response) self.assertTrue(root.xpath('/ns:choices', namespaces=NS)) (version, ) = root.xpath('ns:version', namespaces=NS) self.assertEqual(version.get('id'), versions_data['choices'][0]['id']) self.assertEqual(version.get('status'), versions_data['choices'][0]['status']) media_types = list(version)[0] self.assertEqual(media_types.tag.split('}')[1], "media-types") media_types = version.xpath('ns:media-types/ns:media-type', namespaces=NS) self.assertTrue( common.compare_media_types( media_types, versions_data['choices'][0]['media-types'])) (link, ) = version.xpath('atom:link', namespaces=NS) self.assertTrue( common.compare_links(link, versions_data['choices'][0]['links']))
def test_versions_multi_xml_serializer(self): versions_data = { 'choices': [ { "id": "2.7", "updated": "2011-07-18T11:30:00Z", "status": "DEPRECATED", "media-types": VERSIONS['v2.0']['media-types'], "links": [ { "rel": "self", "href": "http://test/v2/images", }, ], }, ] } serializer = versions.ChoicesTemplate() response = serializer.serialize(versions_data) root = etree.XML(response) self.assertTrue(root.xpath('/ns:choices', namespaces=NS)) (version,) = root.xpath('ns:version', namespaces=NS) self.assertEqual(version.get('id'), versions_data['choices'][0]['id']) self.assertEqual(version.get('status'), versions_data['choices'][0]['status']) media_types = list(version)[0] self.assertEqual(media_types.tag.split('}')[1], "media-types") media_types = version.xpath('ns:media-types/ns:media-type', namespaces=NS) self.assertTrue(common.compare_media_types(media_types, versions_data['choices'][0]['media-types'])) (link,) = version.xpath('atom:link', namespaces=NS) self.assertTrue(common.compare_links(link, versions_data['choices'][0]['links']))
def test_multi_choice_image_xml(self): req = webob.Request.blank('/images/1') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/xml") root = etree.XML(res.body) self.assertTrue(root.xpath('/ns:choices', namespaces=NS)) versions = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(versions), 1) version = versions[0] self.assertEqual(version.get('id'), 'v2.0') self.assertEqual(version.get('status'), 'CURRENT') media_types = version.xpath('ns:media-types/ns:media-type', namespaces=NS) self.assertTrue(common.compare_media_types(media_types, VERSIONS['v2.0']['media-types'])) links = version.xpath('atom:link', namespaces=NS) self.assertTrue(common.compare_links(links, [{'rel': 'self', 'href': 'http://localhost/v2/images/1'}]))
def test_get_version_2_detail_xml(self): req = webob.Request.blank('/v2/') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/xml") version = etree.XML(res.body) xmlutil.validate_schema(version, 'version') expected = VERSIONS['v2.0'] self.assertTrue(version.xpath('/ns:version', namespaces=NS)) media_types = version.xpath('ns:media-types/ns:media-type', namespaces=NS) self.assertTrue(common.compare_media_types(media_types, expected['media-types'])) for key in ['id', 'status', 'updated']: self.assertEqual(version.get(key), expected[key]) links = version.xpath('atom:link', namespaces=NS) self.assertTrue(common.compare_links(links, [{'rel': 'self', 'href': 'http://localhost/v2/'}] + expected['links']))
def test_versions_list_xml_serializer(self): versions_data = { 'versions': [ { "id": "2.7", "updated": "2011-07-18T11:30:00Z", "status": "DEPRECATED", "links": [ { "rel": "self", "href": "http://test/v2", }, ], }, ] } serializer = versions.VersionsTemplate() response = serializer.serialize(versions_data) root = etree.XML(response) xmlutil.validate_schema(root, 'versions') self.assertTrue(root.xpath('/ns:versions', namespaces=NS)) version_elems = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(version_elems), 1) version = version_elems[0] self.assertEqual(version.get('id'), versions_data['versions'][0]['id']) self.assertEqual(version.get('status'), versions_data['versions'][0]['status']) (link, ) = version.xpath('atom:link', namespaces=NS) self.assertTrue( common.compare_links(link, [{ 'rel': 'self', 'href': 'http://test/v2', 'type': 'application/atom+xml' }]))
def test_get_version_list_xml(self): req = webob.Request.blank('/') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/xml") root = etree.XML(res.body) print res.body xmlutil.validate_schema(root, 'versions') self.assertTrue(root.xpath('/ns:versions', namespaces=NS)) versions = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(versions), 1) for i, v in enumerate(['v2.0']): version = versions[i] expected = VERSIONS[v] for key in ['id', 'status', 'updated']: self.assertEqual(version.get(key), expected[key]) (link,) = version.xpath('atom:link', namespaces=NS) self.assertTrue(common.compare_links(link, [{'rel': 'self', 'href': 'http://localhost/%s/' % v}]))
def test_get_version_2_detail_xml(self): req = webob.Request.blank('/v2/') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/xml") version = etree.XML(res.body) xmlutil.validate_schema(version, 'version') expected = VERSIONS['v2.0'] self.assertTrue(version.xpath('/ns:version', namespaces=NS)) media_types = version.xpath('ns:media-types/ns:media-type', namespaces=NS) self.assertTrue( common.compare_media_types(media_types, expected['media-types'])) for key in ['id', 'status', 'updated']: self.assertEqual(version.get(key), expected[key]) links = version.xpath('atom:link', namespaces=NS) self.assertTrue( common.compare_links(links, [{ 'rel': 'self', 'href': 'http://localhost/v2/' }] + expected['links']))
def test_versions_list_xml_serializer(self): versions_data = { 'versions': [ { "id": "2.7", "updated": "2011-07-18T11:30:00Z", "status": "DEPRECATED", "links": [ { "rel": "self", "href": "http://test/v2", }, ], }, ] } serializer = versions.VersionsTemplate() response = serializer.serialize(versions_data) root = etree.XML(response) xmlutil.validate_schema(root, 'versions') self.assertTrue(root.xpath('/ns:versions', namespaces=NS)) version_elems = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(version_elems), 1) version = version_elems[0] self.assertEqual(version.get('id'), versions_data['versions'][0]['id']) self.assertEqual(version.get('status'), versions_data['versions'][0]['status']) (link,) = version.xpath('atom:link', namespaces=NS) self.assertTrue(common.compare_links(link, [{ 'rel': 'self', 'href': 'http://test/v2', 'type': 'application/atom+xml'}]))