summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-07-25 15:28:06 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-07-25 15:28:06 -0400
commit810d4b89cbbfa9388fb61f9069ea0104a7d77752 (patch)
tree421c2782f265d2d40658d1555118396dd5283410
parent99bc14f16bce9f125715fbe436b7fc0969b62420 (diff)
removed prints, got versions detail tests passing, still need to do xml/atom
-rw-r--r--nova/api/openstack/__init__.py2
-rw-r--r--nova/api/openstack/versions.py96
-rw-r--r--nova/tests/api/openstack/test_versions.py295
3 files changed, 292 insertions, 101 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index fb6f5515e..a6a8b4595 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -118,7 +118,7 @@ class APIRouter(base_wsgi.Router):
mapper.connect("versions", "/",
controller=versions.create_resource(version),
- action="index")
+ action="detail")
mapper.resource("console", "consoles",
controller=consoles.create_resource(),
diff --git a/nova/api/openstack/versions.py b/nova/api/openstack/versions.py
index 445a14372..5655edcfc 100644
--- a/nova/api/openstack/versions.py
+++ b/nova/api/openstack/versions.py
@@ -88,6 +88,7 @@ class Versions(wsgi.Resource):
return dict(versions=versions)
def _versions_multi_choice(self, request):
+ #TODO
version_objs = [
{
"id": "v1.1",
@@ -109,18 +110,87 @@ class Versions(wsgi.Resource):
class VersionV10(object):
- def index(self, req):
- return "test index 1.0"
+ def detail(self, req):
+ #TODO
+ return {
+ "version" : {
+ "id": "v1.0",
+ "status": "CURRENT",
+ "updated": "2011-01-21T11:33:21-06:00",
+ "links": [
+ {
+ "rel": "self",
+ "href": "http://servers.api.openstack.org/v1.0/"
+ },
+ {
+ "rel": "describedby",
+ "type": "application/pdf",
+ "href": "http://docs.rackspacecloud.com/"
+ "servers/api/v1.0/cs-devguide-20110125.pdf"
+ },
+ {
+ "rel": "describedby",
+ "type": "application/vnd.sun.wadl+xml",
+ "href": "http://docs.rackspacecloud.com/"
+ "servers/api/v1.0/application.wadl"
+ },
+ ],
+ "media-types": [
+ {
+ "base" : "application/xml",
+ "type" : "application/vnd.openstack.compute-v1.0+xml"
+ },
+ {
+ "base" : "application/json",
+ "type" : "application/vnd.openstack.compute-v1.0+json"
+ }
+ ],
+ },
+ }
class VersionV11(object):
- def index(self, req):
- return "test index 1.1"
+ def detail(self, req):
+ return {
+ "version" : {
+ "id": "v1.1",
+ "status": "CURRENT",
+ "updated": "2011-01-21T11:33:21-06:00",
+ "links": [
+ {
+ "rel": "self",
+ "href": "http://servers.api.openstack.org/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"
+ }
+ ],
+ },
+ }
+
class VersionsRequestDeserializer(wsgi.RequestDeserializer):
def get_action_args(self, request_environment):
"""Parse dictionary created by routes library."""
-
args = {}
if request_environment['PATH_INFO'] == '/':
args['action'] = 'index'
@@ -129,6 +199,7 @@ class VersionsRequestDeserializer(wsgi.RequestDeserializer):
return args
+
class VersionsXMLSerializer(wsgi.XMLDictSerializer):
def _versions_to_xml(self, versions):
root = self._xml_doc.createElement('versions')
@@ -158,6 +229,9 @@ class VersionsXMLSerializer(wsgi.XMLDictSerializer):
return self.to_xml_string(node)
+ def detail(self,data):
+ return "<xml></xml>"
+
def multi(self, data):
self._xml_doc = minidom.Document()
node = self._versions_to_xml(data['versions'])
@@ -167,6 +241,7 @@ class VersionsXMLSerializer(wsgi.XMLDictSerializer):
class VersionsAtomSerializer(wsgi.XMLDictSerializer):
def __init__(self, metadata=None, xmlns=None):
+ self.metadata = metadata or {}
if not xmlns:
self.xmlns = ATOM_XMLNS
else:
@@ -260,14 +335,9 @@ class VersionsAtomSerializer(wsgi.XMLDictSerializer):
return self.to_xml_string(node)
- def multi(self, data):
- self._xml_doc = minidom.Document()
- node = self._xml_doc.createElementNS(self.xmlns, 'feed')
- self._create_meta(node, data['versions'])
- self._create_version_entries(node, data['versions'])
-
- return self.to_xml_string(node)
-
+ def detail(self, data):
+ #TODO
+ pass
def create_resource(version='1.0'):
controller = {
diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/test_versions.py
index b2896a780..9c4af0787 100644
--- a/nova/tests/api/openstack/test_versions.py
+++ b/nova/tests/api/openstack/test_versions.py
@@ -72,99 +72,132 @@ class VersionsTest(test.TestCase):
req = webob.Request.blank('/v1.0/')
req.accept = "application/json"
res = req.get_response(fakes.wsgi_app())
- print res.body
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
- versions = json.loads(res.body)["versions"]
- expected = [
- {
- "version" : {
- "id" : "v1.0",
- "status" : "CURRENT",
- "updated" : "2011-01-21T11:33:21-06:00",
- "links": [
- {
- "rel" : "self",
- "href" : "http://servers.api.openstack.org/v1.0/"
- },
- {
- "rel" : "describedby",
- "type" : "application/pdf",
- "href" : "http://docs.rackspacecloud.com/"
- "servers/api/v1.0/cs-devguide-20110125.pdf"
- },
- {
- "rel" : "describedby",
- "type" : "application/vnd.sun.wadl+xml",
- "href" : "http://docs.rackspacecloud.com/"
- "servers/api/v1.0/application.wadl"
- }
- ],
- "media-types": [
- {
- "base" : "application/xml",
- "type" : "application/"
- "vnd.openstack.compute-v1.0+xml"
- },
- {
- "base" : "application/json",
- "type" : "application/"
- "vnd.openstack.compute-v1.0+json"
- }
- ]
- }
+ version = json.loads(res.body)
+ expected = {
+ "version" : {
+ "id" : "v1.0",
+ "status" : "CURRENT",
+ "updated" : "2011-01-21T11:33:21-06:00",
+ "links": [
+ {
+ "rel" : "self",
+ "href" : "http://servers.api.openstack.org/v1.0/"
+ },
+ {
+ "rel" : "describedby",
+ "type" : "application/pdf",
+ "href" : "http://docs.rackspacecloud.com/"
+ "servers/api/v1.0/cs-devguide-20110125.pdf"
+ },
+ {
+ "rel" : "describedby",
+ "type" : "application/vnd.sun.wadl+xml",
+ "href" : "http://docs.rackspacecloud.com/"
+ "servers/api/v1.0/application.wadl"
+ }
+ ],
+ "media-types": [
+ {
+ "base" : "application/xml",
+ "type" : "application/"
+ "vnd.openstack.compute-v1.0+xml"
+ },
+ {
+ "base" : "application/json",
+ "type" : "application/"
+ "vnd.openstack.compute-v1.0+json"
+ }
+ ]
}
- ]
- self.assertEqual(versions, expected)
+ }
+ self.assertEqual(expected, version)
def test_get_version_1_1_detail(self):
req = webob.Request.blank('/v1.1/')
req.accept = "application/json"
res = req.get_response(fakes.wsgi_app())
- print res.body
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
- versions = json.loads(res.body)["versions"]
- expected = [
- {
- "version" : {
- "id" : "v1.1",
- "status" : "CURRENT",
- "updated" : "2011-01-21T11:33:21-06:00",
- "links": [
- {
- "rel" : "self",
- "href" : "http://servers.api.openstack.org/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"
- }
- ]
- }
+ version = json.loads(res.body)
+ expected = {
+ "version" : {
+ "id" : "v1.1",
+ "status" : "CURRENT",
+ "updated" : "2011-01-21T11:33:21-06:00",
+ "links": [
+ {
+ "rel" : "self",
+ "href" : "http://servers.api.openstack.org/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"
+ }
+ ]
}
- ]
- self.assertEqual(versions, expected)
+ }
+ self.assertEqual(expected, version)
+
+ def test_get_version_1_0_detail_xml(self):
+ pass
+
+ 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")
+ expected = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <version xmlns="http://docs.openstack.org/common/api/v1.0"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ id="v1.1" status="CURRENT" updated="2011-01-21T11:33:21-06:00">
+
+ <media-types>
+ <media-type base="application/xml"
+ type="application/vnd.openstack.compute-v1.1+xml"/>
+ <media-type base="application/json"
+ type="application/vnd.openstack.compute-v1.1+json"/>
+ </media-types>
+
+ <atom:link rel="self"
+ href="http://servers.api.openstack.org/v1.0/"/>
+
+ <atom:link rel="describedby"
+ type="application/pdf"
+ href="http://docs.rackspacecloud.com/
+ servers/api/v1.1/cs-devguide-20110125.pdf" />
+
+ <atom:link rel="describedby"
+ type="application/vnd.sun.wadl+xml"
+ href="http://docs.rackspacecloud.com/
+ servers/api/v1.1/application.wadl" />
+ </version>""".replace(" ", "").replace("\n", "")
+
+ actual = res.body.replace(" ", "").replace("\n", "")
+ self.assertEqual(expected, actual)
def test_get_version_list_xml(self):
req = webob.Request.blank('/')
@@ -265,7 +298,37 @@ class VersionsTest(test.TestCase):
self.assertEqual(actual, expected)
- def test_xml_serializer(self):
+ 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",
+ }
+ ],
+ },
+ ]
+ }
+
+ expected = """
+ <versions>
+ <version id="2.7.1" status="DEPRECATED"
+ updated="2011-07-18T11:30:00Z">
+ <atom:link href="http://test/2.7.1" rel="self"/>
+ </version>
+ </versions>""".replace(" ", "").replace("\n", "")
+
+ serializer = versions.VersionsXMLSerializer()
+ response = serializer.index(versions_data)
+ response = response.replace(" ", "").replace("\n", "")
+ self.assertEqual(expected, response)
+
+ def test_versions_detail_xml_serializer(self):
versions_data = {
'versions': [
{
@@ -291,11 +354,70 @@ class VersionsTest(test.TestCase):
</versions>""".replace(" ", "").replace("\n", "")
serializer = versions.VersionsXMLSerializer()
- response = serializer.default(versions_data)
+ response = serializer.index(versions_data)
+ response = response.replace(" ", "").replace("\n", "")
+ self.assertEqual(expected, response)
+
+ 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",
+ }
+ ],
+ },
+ ]
+ }
+
+ 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.index(versions_data)
response = response.replace(" ", "").replace("\n", "")
self.assertEqual(expected, response)
- def test_atom_serializer(self):
+ def test_version_detail_atom_serializer(self):
versions_data = {
'versions': [
{
@@ -350,7 +472,6 @@ class VersionsTest(test.TestCase):
</feed>""".replace(" ", "").replace("\n", "")
serializer = versions.VersionsAtomSerializer()
- response = serializer.default(versions_data)
- print response
+ response = serializer.index(versions_data)
response = response.replace(" ", "").replace("\n", "")
self.assertEqual(expected, response)