示例#1
0
    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), 2)

        version = versions[0]
        self.assertEqual(version.get('id'), 'v1.1')
        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['v1.1']['media-types']))
        links = version.xpath('atom:link', namespaces=NS)
        self.assertTrue(common.compare_links(links,
            [{'rel': 'self', 'href': 'http://localhost/v1.1/images/1'}]))

        version = versions[1]
        self.assertEqual(version.get('id'), 'v1.0')
        self.assertEqual(version.get('status'), 'DEPRECATED')
        media_types = version.xpath('ns:media-types/ns:media-type',
                                    namespaces=NS)
        self.assertTrue(common.compare_media_types(media_types,
                                             VERSIONS['v1.0']['media-types']))
        links = version.xpath('atom:link', namespaces=NS)
        self.assertTrue(common.compare_links(links,
            [{'rel': 'self', 'href': 'http://localhost/v1.0/images/1'}]))
示例#2
0
    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), 2)

        version = versions[1]
        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, EXP_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"}]))

        version = versions[0]
        self.assertEqual(version.get("id"), "v3.0")
        self.assertEqual(version.get("status"), "EXPERIMENTAL")
        media_types = version.xpath("ns:media-types/ns:media-type", namespaces=NS)
        self.assertTrue(common.compare_media_types(media_types, EXP_VERSIONS["v3.0"]["media-types"]))

        links = version.xpath("atom:link", namespaces=NS)
        self.assertTrue(common.compare_links(links, [{"rel": "self", "href": "http://localhost/v3/images/1"}]))
示例#3
0
    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), 2)

        version = versions[0]
        self.assertEqual(version.get('id'), 'v1.1')
        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['v1.1']['media-types']))
        links = version.xpath('atom:link', namespaces=NS)
        self.assertTrue(common.compare_links(links,
            [{'rel': 'self', 'href': 'http://localhost/v1.1/images/1'}]))

        version = versions[1]
        self.assertEqual(version.get('id'), 'v1.0')
        self.assertEqual(version.get('status'), 'DEPRECATED')
        media_types = version.xpath('ns:media-types/ns:media-type',
                                    namespaces=NS)
        self.assertTrue(common.compare_media_types(media_types,
                                             VERSIONS['v1.0']['media-types']))
        links = version.xpath('atom:link', namespaces=NS)
        self.assertTrue(common.compare_links(links,
            [{'rel': 'self', 'href': 'http://localhost/v1.0/images/1'}]))
示例#4
0
    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
                }]))
示例#5
0
    def test_versions_multi_xml_serializer(self):
        versions_data = {
            "choices": [
                {
                    "id": "2.7",
                    "updated": "2011-07-18T11:30:00Z",
                    "status": "DEPRECATED",
                    "media-types": EXP_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"]))
示例#6
0
    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"}])
        )
示例#7
0
    def test_versions_list_xml_serializer(self):
        versions_data = {
            'versions': [
                {
                    "id": "2.7.1",
                    "updated": "2011-07-18T11:30:00Z",
                    "status": "DEPRECATED",
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://test/2.7.1",
                        },
                    ],
                },
            ]
        }

        serializer = versions.VersionsXMLSerializer()
        response = serializer.index(versions_data)

        root = etree.XML(response)
        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/2.7.1',
            'type': 'application/atom+xml'}]))
示例#8
0
    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']))
示例#9
0
    def test_get_version_3_detail_xml(self):
        req = webob.Request.blank("/v3/")
        req.accept = "application/xml"
        res = req.get_response(fakes.wsgi_app_v3())
        self.assertEqual(res.status_int, 200)
        self.assertEqual(res.content_type, "application/xml")

        version = etree.XML(res.body)
        xmlutil.validate_schema(version, "version")

        expected = EXP_VERSIONS["v3.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/v3/"}] + expected["links"])
        )
示例#10
0
    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)
        self.assertTrue(root.xpath('/ns:versions', namespaces=NS))
        versions = root.xpath('ns:version', namespaces=NS)
        self.assertEqual(len(versions), 2)

        for i, v in enumerate(['v1.0', 'v1.1']):
            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}]))
示例#11
0
    def test_get_version_1_1_detail_xml(self):
        req = webob.Request.blank('/v1.1/')
        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)
        expected = VERSIONS['v1.1']
        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/v1.1/'}]
            + expected['links']))
示例#12
0
    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)
        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 = EXP_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}]))
示例#13
0
    def test_versions_multi_xml_serializer(self):
        versions_data = {
            'choices': [
                {
                    "id": "2.7.1",
                    "updated": "2011-07-18T11:30:00Z",
                    "status": "DEPRECATED",
                    "media-types": VERSIONS['v1.1']['media-types'],
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://test/2.7.1/images",
                        },
                    ],
                },
            ]
        }

        serializer = versions.VersionsXMLSerializer()
        response = serializer.multi(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]
        media_type_nodes = list(media_types)
        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']))