summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-07-20 16:47:17 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-07-20 16:47:17 -0400
commit148b4095a5f18f192ae243b02b4070af384c1152 (patch)
tree140c31bf0f64302a0ded654616d8df933679d6f5
parenta35a70fbaef0ef6634213308d5a68ee60bd714f2 (diff)
added versions list atom test and it passes
-rw-r--r--nova/api/openstack/versions.py68
-rw-r--r--nova/api/openstack/views/versions.py2
-rw-r--r--nova/tests/api/openstack/test_versions.py36
3 files changed, 64 insertions, 42 deletions
diff --git a/nova/api/openstack/versions.py b/nova/api/openstack/versions.py
index a83472e15..49633df88 100644
--- a/nova/api/openstack/versions.py
+++ b/nova/api/openstack/versions.py
@@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+from datetime import datetime
import webob
import webob.dec
from xml.dom import minidom
@@ -58,7 +59,7 @@ class Versions(wsgi.Resource):
"id": "v1.1",
"status": "CURRENT",
#TODO(wwolf) get correct value for these
- "updated": "2011-7-18T11:30:00Z",
+ "updated": "2011-07-18T11:30:00Z",
},
{
"id": "v1.0",
@@ -117,60 +118,81 @@ class VersionsAtomSerializer(wsgi.XMLDictSerializer):
elem.appendChild(elem_text)
return elem
- def _create_meta(self, root):
+ def _get_most_recent_update(self, versions):
+ recent = None
+ for version in versions:
+ updated = datetime.strptime(version['updated'],'%Y-%m-%dT%H:%M:%SZ')
+ if not recent:
+ recent = updated
+ elif updated > recent:
+ recent = updated
+
+ return recent.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ def _get_base_url(self, link_href):
+ # Make sure no trailing /
+ link_href = link_href.rstrip('/')
+ return link_href.rsplit('/',1)[0] + '/'
+
+ def _create_meta(self, root, versions):
title = self._create_text_elem('title', 'Available API Versions',
type='text')
- #TODO(wwolf): what should updated be?
- updated = self._create_text_elem('updated', '2010-12-12T18:30:02.25Z')
- #TODO(wwolf): get URI
- id = self._create_text_elem('id', '')
- #TODO(wwolf): get link info
+ # Set this updated to the most recently updated version
+ recent = self._get_most_recent_update(versions)
+ updated = self._create_text_elem('updated', recent)
+
+ base_url = self._get_base_url(versions[0]['links'][0]['href'])
+ id = self._create_text_elem('id', base_url)
link = self._xml_doc.createElement('link')
- link.setAttribute('rel', 'rel')
- link.setAttribute('href', 'href')
+ link.setAttribute('rel', 'self')
+ link.setAttribute('href', base_url)
author = self._xml_doc.createElement('author')
author_name = self._create_text_elem('name', 'Rackspace')
- author_uri = self._create_text_elem('uri', 'http://www.rackspace.com')
+ author_uri = self._create_text_elem('uri', 'http://www.rackspace.com/')
author.appendChild(author_name)
author.appendChild(author_uri)
root.appendChild(title)
root.appendChild(updated)
root.appendChild(id)
- root.appendChild(link)
root.appendChild(author)
+ root.appendChild(link)
def _create_version_entries(self, root, versions):
for version in versions:
entry = self._xml_doc.createElement('entry')
- #TODO(wwolf) GET URI
- id = self._create_text_elem('id', 'URI')
+
+ id = self._create_text_elem('id', version['links'][0]['href'])
title = self._create_text_elem('title',
'Version %s' % version['id'],
type='text')
updated = self._create_text_elem('updated', version['updated'])
- #TODO(wwolf): get link info
- link = self._xml_doc.createElement('link')
- link.setAttribute('rel', 'rel')
- link.setAttribute('href', 'href')
+
+ entry.appendChild(id)
+ entry.appendChild(title)
+ entry.appendChild(updated)
+
+ for link in version['links']:
+ link_node = self._xml_doc.createElement('link')
+ link_node.setAttribute('rel', link['rel'])
+ link_node.setAttribute('href', link['href'])
+ entry.appendChild(link_node)
+
content = self._create_text_elem('content',
'Version %s %s (%s)' %
(version['id'],
version['status'],
- version['updated']))
+ version['updated']),
+ type='text')
- entry.appendChild(id)
- entry.appendChild(title)
- entry.appendChild(updated)
- entry.appendChild(link)
entry.appendChild(content)
root.appendChild(entry)
def default(self, data):
self._xml_doc = minidom.Document()
node = self._xml_doc.createElementNS(self.xmlns, 'feed')
- self._create_meta(node)
+ self._create_meta(node, data['versions'])
self._create_version_entries(node, data['versions'])
return self.to_xml_string(node)
diff --git a/nova/api/openstack/views/versions.py b/nova/api/openstack/views/versions.py
index e815974f1..9fa8f49dc 100644
--- a/nova/api/openstack/views/versions.py
+++ b/nova/api/openstack/views/versions.py
@@ -57,4 +57,4 @@ class ViewBuilder(object):
def generate_href(self, version_number):
"""Create an url that refers to a specific version_number."""
- return os.path.join(self.base_url, version_number)
+ return os.path.join(self.base_url, version_number) + '/'
diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/test_versions.py
index 275cfa9ef..471afec94 100644
--- a/nova/tests/api/openstack/test_versions.py
+++ b/nova/tests/api/openstack/test_versions.py
@@ -43,7 +43,7 @@ class VersionsTest(test.TestCase):
{
"id": "v1.1",
"status": "CURRENT",
- "updated": "2011-7-18T11:30:00Z",
+ "updated": "2011-07-18T11:30:00Z",
"links": [
{
"rel": "self",
@@ -71,7 +71,7 @@ class VersionsTest(test.TestCase):
self.assertEqual(res.content_type, "application/xml")
expected = """<versions>
- <version id="v1.1" status="CURRENT" updated="2011-7-18T11:30:00Z">
+ <version id="v1.1" status="CURRENT" updated="2011-07-18T11:30:00Z">
<atom:link href="http://localhost/v1.1" rel="self"/>
</version>
<version id="v1.0" status="DEPRECATED"
@@ -94,35 +94,35 @@ class VersionsTest(test.TestCase):
expected = """
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Available API Versions</title>
- <updated>2010-12-12T18:30:02.25Z</updated>
- <id>http://servers.api.openstack.org/</id>
+ <updated>2011-07-18T11:30:00Z</updated>
+ <id>http://localhost/</id>
<author>
<name>Rackspace</name>
<uri>http://www.rackspace.com/</uri>
</author>
- <link rel="self" href="http://servers.api.openstack.org/"/>
+ <link href="http://localhost/" rel="self"/>
<entry>
- <id>http://servers.api.openstack.org/v1.1/</id>
+ <id>http://localhost/v1.1/</id>
<title type="text">Version v1.1</title>
- <updated>2010-12-12T18:30:02.25Z</updated>
- <link rel="self" href="http://servers.api.openstack.org/v1.1/"/>
+ <updated>2011-07-18T11:30:00Z</updated>
+ <link href="http://localhost/v1.1/" rel="self"/>
<content type="text">
- Version v1.1 CURRENT (2010-12-12T18:30:02.25Z)
+ Version v1.1 CURRENT (2011-07-18T11:30:00Z)
</content>
</entry>
<entry>
- <id>http://servers.api.openstack.org/v1.0/</id>
+ <id>http://localhost/v1.0/</id>
<title type="text">Version v1.0</title>
- <updated>2009-10-09T11:30:00Z</updated>
- <link rel="self" href="http://servers.api.openstack.org/v1.0/"/>
+ <updated>2010-10-09T11:30:00Z</updated>
+ <link href="http://localhost/v1.0/" rel="self"/>
<content type="text">
- Version v1.0 DEPRECATED (2009-10-09T11:30:00Z)
+ Version v1.0 DEPRECATED (2010-10-09T11:30:00Z)
</content>
</entry>
- </feed>
- """.replace(" ", "").replace("\n", "")
+ </feed>
+ """.replace(" ", "").replace("\n", "").replace("\t", "")
- actual = res.body.replace(" ", "").replace("\n", "")
+ actual = res.body.replace(" ", "").replace("\n", "").replace("\t","")
self.assertEqual(expected, actual)
@@ -132,13 +132,13 @@ class VersionsTest(test.TestCase):
version_data = {
"id": "3.2.1",
"status": "CURRENT",
- "updated": "2011-7-18T11:30:00Z"
+ "updated": "2011-07-18T11:30:00Z"
}
expected = {
"id": "3.2.1",
"status": "CURRENT",
- "updated": "2011-7-18T11:30:00Z",
+ "updated": "2011-07-18T11:30:00Z",
"links": [
{
"rel": "self",