Beispiel #1
0
    def test_atom_serializer(self):
        versions_data = {
            'versions': [
                {
                    "id": "2.9.8",
                    "updated": "2011-07-20T11:40:00Z",
                    "status": "CURRENT",
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://test/2.9.8",
                        },
                    ],
                },
            ]
        }

        expected = """
            <feed xmlns="http://www.w3.org/2005/Atom">
                <title type="text">
                    Available API Versions
                </title>
                <updated>
                    2011-07-20T11:40:00Z
                </updated>
                <id>
                    http://test/
                </id>
                <author>
                    <name>
                        Rackspace
                    </name>
                    <uri>
                        http://www.rackspace.com/
                    </uri>
                </author>
                <link href="http://test/" rel="self"/>
                <entry>
                    <id>
                        http://test/2.9.8
                    </id>
                    <title type="text">
                        Version 2.9.8
                    </title>
                    <updated>
                        2011-07-20T11:40:00Z
                    </updated>
                    <link href="http://test/2.9.8" rel="self"/>
                    <content type="text">
                        Version 2.9.8 CURRENT (2011-07-20T11:40:00Z)
                    </content>
                </entry>
            </feed>""".replace("  ", "").replace("\n", "")

        serializer = versions.VersionsAtomSerializer()
        response = serializer.default(versions_data)
        print response
        response = response.replace("  ", "").replace("\n", "")
        self.assertEqual(expected, response)
Beispiel #2
0
    def test_versions_list_atom_serializer(self):
        versions_data = {
            'versions': [
                {
                    "id": "2.9.8",
                    "updated": "2011-07-20T11:40:00Z",
                    "status": "CURRENT",
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://test/2.9.8",
                        },
                    ],
                },
            ]
        }

        serializer = versions.VersionsAtomSerializer()
        response = serializer.index(versions_data)
        f = feedparser.parse(response)

        self.assertEqual(f.feed.title, 'Available API Versions')
        self.assertEqual(f.feed.updated, '2011-07-20T11:40:00Z')
        self.assertEqual(f.feed.id, 'http://test/')
        self.assertEqual(f.feed.author, 'Rackspace')
        self.assertEqual(f.feed.author_detail.href,
                         'http://www.rackspace.com/')
        self.assertEqual(f.feed.links[0]['href'], 'http://test/')
        self.assertEqual(f.feed.links[0]['rel'], 'self')

        self.assertEqual(len(f.entries), 1)
        entry = f.entries[0]
        self.assertEqual(entry.id, 'http://test/2.9.8')
        self.assertEqual(entry.title, 'Version 2.9.8')
        self.assertEqual(entry.updated, '2011-07-20T11:40:00Z')
        self.assertEqual(len(entry.content), 1)
        self.assertEqual(entry.content[0].value,
            'Version 2.9.8 CURRENT (2011-07-20T11:40:00Z)')
        self.assertEqual(len(entry.links), 1)
        self.assertEqual(entry.links[0]['href'], 'http://test/2.9.8')
        self.assertEqual(entry.links[0]['rel'], 'self')
Beispiel #3
0
    def test_version_detail_atom_serializer(self):
        versions_data = {
            "version": {
                "id":
                "v1.1",
                "status":
                "CURRENT",
                "updated":
                "2011-01-21T11:33:21Z",
                "links": [
                    {
                        "rel": "self",
                        "href": "http://localhost/v1.1/",
                    },
                    {
                        "rel":
                        "describedby",
                        "type":
                        "application/pdf",
                        "href":
                        "http://docs.rackspacecloud.com/"
                        "servers/api/v1.1/cs-devguide-20110125.pdf",
                    },
                    {
                        "rel":
                        "describedby",
                        "type":
                        "application/vnd.sun.wadl+xml",
                        "href":
                        "http://docs.rackspacecloud.com/"
                        "servers/api/v1.1/application.wadl",
                    },
                ],
                "media-types": [{
                    "base":
                    "application/xml",
                    "type":
                    "application/vnd.openstack.compute-v1.1+xml",
                }, {
                    "base":
                    "application/json",
                    "type":
                    "application/vnd.openstack.compute-v1.1+json",
                }],
            },
        }

        serializer = versions.VersionsAtomSerializer()
        response = serializer.show(versions_data)

        root = xml.etree.ElementTree.XML(response)
        self.assertEqual(root.tag.split('}')[1], "feed")
        self.assertEqual(
            root.tag.split('}')[0].strip('{'), "http://www.w3.org/2005/Atom")

        children = list(root)
        title = children[0]
        updated = children[1]
        id = children[2]
        author = children[3]
        link = children[4]
        entry = children[5]

        self.assertEqual(root.tag.split('}')[1], 'feed')
        self.assertEqual(title.tag.split('}')[1], 'title')
        self.assertEqual(title.text, 'About This Version')
        self.assertEqual(updated.tag.split('}')[1], 'updated')
        self.assertEqual(updated.text, '2011-01-21T11:33:21Z')
        self.assertEqual(id.tag.split('}')[1], 'id')
        self.assertEqual(id.text, 'http://localhost/v1.1/')

        self.assertEqual(author.tag.split('}')[1], 'author')
        author_name = list(author)[0]
        author_uri = list(author)[1]
        self.assertEqual(author_name.tag.split('}')[1], 'name')
        self.assertEqual(author_name.text, 'Rackspace')
        self.assertEqual(author_uri.tag.split('}')[1], 'uri')
        self.assertEqual(author_uri.text, 'http://www.rackspace.com/')

        self.assertEqual(link.get('href'), 'http://localhost/v1.1/')
        self.assertEqual(link.get('rel'), 'self')

        self.assertEqual(entry.tag.split('}')[1], 'entry')
        entry_children = list(entry)
        entry_id = entry_children[0]
        entry_title = entry_children[1]
        entry_updated = entry_children[2]
        entry_links = (entry_children[3], entry_children[4], entry_children[5])
        entry_content = entry_children[6]

        self.assertEqual(entry_id.tag.split('}')[1], "id")
        self.assertEqual(entry_id.text, "http://localhost/v1.1/")
        self.assertEqual(entry_title.tag.split('}')[1], "title")
        self.assertEqual(entry_title.get('type'), "text")
        self.assertEqual(entry_title.text, "Version v1.1")
        self.assertEqual(entry_updated.tag.split('}')[1], "updated")
        self.assertEqual(entry_updated.text, "2011-01-21T11:33:21Z")

        for i, link in enumerate(versions_data["version"]["links"]):
            self.assertEqual(entry_links[i].tag.split('}')[1], "link")
            for key, val in versions_data["version"]["links"][i].items():
                self.assertEqual(entry_links[i].get(key), val)

        self.assertEqual(entry_content.tag.split('}')[1], "content")
        self.assertEqual(entry_content.get('type'), "text")
        self.assertEqual(entry_content.text,
                         "Version v1.1 CURRENT (2011-01-21T11:33:21Z)")
Beispiel #4
0
    def test_versions_list_atom_serializer(self):
        versions_data = {
            'versions': [
                {
                    "id": "2.9.8",
                    "updated": "2011-07-20T11:40:00Z",
                    "status": "CURRENT",
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://test/2.9.8",
                        },
                    ],
                },
            ]
        }

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

        root = xml.etree.ElementTree.XML(response)
        self.assertEqual(root.tag.split('}')[1], "feed")
        self.assertEqual(
            root.tag.split('}')[0].strip('{'), "http://www.w3.org/2005/Atom")

        children = list(root)
        title = children[0]
        updated = children[1]
        id = children[2]
        author = children[3]
        link = children[4]
        entry = children[5]

        self.assertEqual(title.tag.split('}')[1], 'title')
        self.assertEqual(title.text, 'Available API Versions')
        self.assertEqual(updated.tag.split('}')[1], 'updated')
        self.assertEqual(updated.text, '2011-07-20T11:40:00Z')
        self.assertEqual(id.tag.split('}')[1], 'id')
        self.assertEqual(id.text, 'http://test/')

        self.assertEqual(author.tag.split('}')[1], 'author')
        author_name = list(author)[0]
        author_uri = list(author)[1]
        self.assertEqual(author_name.tag.split('}')[1], 'name')
        self.assertEqual(author_name.text, 'Rackspace')
        self.assertEqual(author_uri.tag.split('}')[1], 'uri')
        self.assertEqual(author_uri.text, 'http://www.rackspace.com/')

        self.assertEqual(link.get('href'), 'http://test/')
        self.assertEqual(link.get('rel'), 'self')

        self.assertEqual(entry.tag.split('}')[1], 'entry')
        entry_children = list(entry)
        entry_id = entry_children[0]
        entry_title = entry_children[1]
        entry_updated = entry_children[2]
        entry_link = entry_children[3]
        entry_content = entry_children[4]
        self.assertEqual(entry_id.tag.split('}')[1], "id")
        self.assertEqual(entry_id.text, "http://test/2.9.8")
        self.assertEqual(entry_title.tag.split('}')[1], "title")
        self.assertEqual(entry_title.get('type'), "text")
        self.assertEqual(entry_title.text, "Version 2.9.8")
        self.assertEqual(entry_updated.tag.split('}')[1], "updated")
        self.assertEqual(entry_updated.text, "2011-07-20T11:40:00Z")
        self.assertEqual(entry_link.tag.split('}')[1], "link")
        self.assertEqual(entry_link.get('href'), "http://test/2.9.8")
        self.assertEqual(entry_link.get('rel'), "self")
        self.assertEqual(entry_content.tag.split('}')[1], "content")
        self.assertEqual(entry_content.get('type'), "text")
        self.assertEqual(entry_content.text,
                         "Version 2.9.8 CURRENT (2011-07-20T11:40:00Z)")
Beispiel #5
0
    def test_version_detail_atom_serializer(self):
        versions_data = {
            "version": {
                "id": "v1.1",
                "status": "CURRENT",
                "updated": "2011-01-21T11:33:21Z",
                "links": [
                    {
                        "rel": "self",
                        "href": "http://localhost/v1.1/",
                    },
                    {
                        "rel": "describedby",
                        "type": "application/pdf",
                        "href": "http://docs.rackspacecloud.com/"
                                "servers/api/v1.1/cs-devguide-20110125.pdf",
                    },
                    {
                        "rel": "describedby",
                        "type": "application/vnd.sun.wadl+xml",
                        "href": "http://docs.rackspacecloud.com/"
                                "servers/api/v1.1/application.wadl",
                    },
                ],
                "media-types": [
                    {
                        "base": "application/xml",
                        "type": "application/vnd.openstack.compute-v1.1+xml",
                    },
                    {
                        "base": "application/json",
                        "type": "application/vnd.openstack.compute-v1.1+json",
                    }
                ],
            },
        }

        serializer = versions.VersionsAtomSerializer()
        response = serializer.show(versions_data)
        f = feedparser.parse(response)

        self.assertEqual(f.feed.title, 'About This Version')
        self.assertEqual(f.feed.updated, '2011-01-21T11:33:21Z')
        self.assertEqual(f.feed.id, 'http://localhost/v1.1/')
        self.assertEqual(f.feed.author, 'Rackspace')
        self.assertEqual(f.feed.author_detail.href,
                         'http://www.rackspace.com/')
        self.assertEqual(f.feed.links[0]['href'], 'http://localhost/v1.1/')
        self.assertEqual(f.feed.links[0]['rel'], 'self')

        self.assertEqual(len(f.entries), 1)
        entry = f.entries[0]
        self.assertEqual(entry.id, 'http://localhost/v1.1/')
        self.assertEqual(entry.title, 'Version v1.1')
        self.assertEqual(entry.updated, '2011-01-21T11:33:21Z')
        self.assertEqual(len(entry.content), 1)
        self.assertEqual(entry.content[0].value,
             'Version v1.1 CURRENT (2011-01-21T11:33:21Z)')
        self.assertEqual(len(entry.links), 3)
        self.assertEqual(entry.links[0]['href'], 'http://localhost/v1.1/')
        self.assertEqual(entry.links[0]['rel'], 'self')
        self.assertEqual(entry.links[1], {
            'rel': 'describedby',
            'type': 'application/pdf',
            'href': 'http://docs.rackspacecloud.com/'
                    'servers/api/v1.1/cs-devguide-20110125.pdf'})
        self.assertEqual(entry.links[2], {
            'rel': 'describedby',
            'type': 'application/vnd.sun.wadl+xml',
            'href': 'http://docs.rackspacecloud.com/'
                    'servers/api/v1.1/application.wadl',
        })