summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2011-09-25 22:51:55 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2011-10-04 14:44:34 +0000
commit6e5f2d88e630540b0ab121cd9949289d2fc0cd67 (patch)
tree1da9cb982a4452025e75c68a1cafb7aeed32c9b3 /nova/tests
parent3837f09ee0b7b0da23e1caa185f58610d30bffe6 (diff)
Add support for header version parameter to specify API version.
bug 844905 The 1.1 API specifies that the API version can be determined by URL path (eg /v1.1/tenant/servers/detail), Content-Type header (eg application/json;version=1.1) or Accept header (eg application/json;q=0.8;version=1.1, application/xml;q=0.2;version=1.1). Change-Id: I01220cf1eebc0f759d66563ec67ef2f697c6d310
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/fakes.py2
-rw-r--r--nova/tests/api/openstack/test_urlmap.py111
-rw-r--r--nova/tests/api/openstack/test_versions.py98
3 files changed, 190 insertions, 21 deletions
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index e0176c9a3..81eee216e 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -17,7 +17,6 @@
import webob
import webob.dec
-from paste import urlmap
from glance import client as glance_client
@@ -32,6 +31,7 @@ from nova.api.openstack import auth
from nova.api.openstack import extensions
from nova.api.openstack import versions
from nova.api.openstack import limits
+from nova.api.openstack import urlmap
from nova.auth.manager import User, Project
import nova.image.fake
from nova.tests.glance import stubs as glance_stubs
diff --git a/nova/tests/api/openstack/test_urlmap.py b/nova/tests/api/openstack/test_urlmap.py
new file mode 100644
index 000000000..9e7cdda75
--- /dev/null
+++ b/nova/tests/api/openstack/test_urlmap.py
@@ -0,0 +1,111 @@
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import json
+import webob
+
+from nova import test
+from nova import log as logging
+from nova.tests.api.openstack import fakes
+
+LOG = logging.getLogger('nova.tests.api.openstack.test_urlmap')
+
+
+class UrlmapTest(test.TestCase):
+ def setUp(self):
+ super(UrlmapTest, self).setUp()
+ fakes.stub_out_rate_limiting(self.stubs)
+
+ def test_path_version_v1_0(self):
+ """Test URL path specifying v1.0 returns v1.0 content."""
+ req = webob.Request.blank('/v1.0/')
+ req.accept = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['version']['id'], 'v1.0')
+
+ def test_path_version_v1_1(self):
+ """Test URL path specifying v1.1 returns v1.1 content."""
+ req = webob.Request.blank('/v1.1/')
+ req.accept = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['version']['id'], 'v1.1')
+
+ def test_content_type_version_v1_0(self):
+ """Test Content-Type specifying v1.0 returns v1.0 content."""
+ req = webob.Request.blank('/')
+ req.content_type = "application/json;version=1.0"
+ req.accept = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['version']['id'], 'v1.0')
+
+ def test_content_type_version_v1_1(self):
+ """Test Content-Type specifying v1.1 returns v1.1 content."""
+ req = webob.Request.blank('/')
+ req.content_type = "application/json;version=1.1"
+ req.accept = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['version']['id'], 'v1.1')
+
+ def test_accept_version_v1_0(self):
+ """Test Accept header specifying v1.0 returns v1.0 content."""
+ req = webob.Request.blank('/')
+ req.accept = "application/json;version=1.0"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['version']['id'], 'v1.0')
+
+ def test_accept_version_v1_1(self):
+ """Test Accept header specifying v1.1 returns v1.1 content."""
+ req = webob.Request.blank('/')
+ req.accept = "application/json;version=1.1"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['version']['id'], 'v1.1')
+
+ def test_path_content_type(self):
+ """Test URL path specifying JSON returns JSON content."""
+ req = webob.Request.blank('/v1.1/foobar/images/1.json')
+ req.accept = "application/xml"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['image']['id'], '1')
+
+ def test_accept_content_type(self):
+ """Test Accept header specifying JSON returns JSON content."""
+ req = webob.Request.blank('/v1.1/foobar/images/1')
+ req.accept = "application/xml;q=0.8, application/json"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ body = json.loads(res.body)
+ self.assertEqual(body['image']['id'], '1')
diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/test_versions.py
index 1ae3789d9..375470a64 100644
--- a/nova/tests/api/openstack/test_versions.py
+++ b/nova/tests/api/openstack/test_versions.py
@@ -56,11 +56,11 @@ VERSIONS = {
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.0+xml",
+ "type": "application/vnd.openstack.compute+xml;version=1.0",
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.0+json",
+ "type": "application/vnd.openstack.compute+json;version=1.0",
},
],
},
@@ -85,11 +85,11 @@ VERSIONS = {
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.1+xml",
+ "type": "application/vnd.openstack.compute+xml;version=1.1",
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.1+json",
+ "type": "application/vnd.openstack.compute+json;version=1.1",
},
],
},
@@ -175,12 +175,12 @@ class VersionsTest(test.TestCase):
{
"base": "application/xml",
"type": "application/"
- "vnd.openstack.compute-v1.0+xml",
+ "vnd.openstack.compute+xml;version=1.0",
},
{
"base": "application/json",
"type": "application/"
- "vnd.openstack.compute-v1.0+json",
+ "vnd.openstack.compute+json;version=1.0",
},
],
},
@@ -221,12 +221,58 @@ class VersionsTest(test.TestCase):
{
"base": "application/xml",
"type": "application/"
- "vnd.openstack.compute-v1.1+xml",
+ "vnd.openstack.compute+xml;version=1.1",
},
{
"base": "application/json",
"type": "application/"
- "vnd.openstack.compute-v1.1+json",
+ "vnd.openstack.compute+json;version=1.1",
+ },
+ ],
+ },
+ }
+ self.assertEqual(expected, version)
+
+ def test_get_version_1_1_detail_content_type(self):
+ req = webob.Request.blank('/')
+ req.accept = "application/json;version=1.1"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, "application/json")
+ version = json.loads(res.body)
+ expected = {
+ "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+xml;version=1.1",
+ },
+ {
+ "base": "application/json",
+ "type": "application/"
+ "vnd.openstack.compute+json;version=1.1",
},
],
},
@@ -445,11 +491,13 @@ class VersionsTest(test.TestCase):
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.1+xml"
+ "type": "application/vnd.openstack.compute+xml"
+ ";version=1.1"
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.1+json"
+ "type": "application/vnd.openstack.compute+json"
+ ";version=1.1"
},
],
},
@@ -465,11 +513,13 @@ class VersionsTest(test.TestCase):
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.0+xml"
+ "type": "application/vnd.openstack.compute+xml"
+ ";version=1.0"
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.0+json"
+ "type": "application/vnd.openstack.compute+json"
+ ";version=1.0"
},
],
},
@@ -543,11 +593,13 @@ class VersionsTest(test.TestCase):
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.1+xml"
+ "type": "application/vnd.openstack.compute+xml"
+ ";version=1.1"
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.1+json"
+ "type": "application/vnd.openstack.compute+json"
+ ";version=1.1"
},
],
},
@@ -563,11 +615,13 @@ class VersionsTest(test.TestCase):
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.0+xml"
+ "type": "application/vnd.openstack.compute+xml"
+ ";version=1.0"
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.0+json"
+ "type": "application/vnd.openstack.compute+json"
+ ";version=1.0"
},
],
},
@@ -727,11 +781,13 @@ class VersionsSerializerTests(test.TestCase):
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.0+xml",
+ "type": "application/vnd.openstack.compute+xml"
+ ";version=1.0",
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.0+json",
+ "type": "application/vnd.openstack.compute+json"
+ ";version=1.0",
},
],
},
@@ -831,11 +887,13 @@ class VersionsSerializerTests(test.TestCase):
"media-types": [
{
"base": "application/xml",
- "type": "application/vnd.openstack.compute-v1.1+xml",
+ "type": "application/vnd.openstack.compute+xml"
+ ";version=1.1",
},
{
"base": "application/json",
- "type": "application/vnd.openstack.compute-v1.1+json",
+ "type": "application/vnd.openstack.compute+json"
+ ";version=1.1",
}
],
},