1
# Copyright 2011 OpenStack LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
19
from nova import log as logging
21
from nova.tests.api.openstack import fakes
23
LOG = logging.getLogger('nova.tests.api.openstack.v2.test_urlmap')
26
class UrlmapTest(test.TestCase):
28
super(UrlmapTest, self).setUp()
29
fakes.stub_out_rate_limiting(self.stubs)
31
def test_path_version_v1_1(self):
32
"""Test URL path specifying v1.1 returns v2 content."""
33
req = webob.Request.blank('/v1.1/')
34
req.accept = "application/json"
35
res = req.get_response(fakes.wsgi_app())
36
self.assertEqual(res.status_int, 200)
37
self.assertEqual(res.content_type, "application/json")
38
body = json.loads(res.body)
39
self.assertEqual(body['version']['id'], 'v2.0')
41
def test_content_type_version_v1_1(self):
42
"""Test Content-Type specifying v1.1 returns v2 content."""
43
req = webob.Request.blank('/')
44
req.content_type = "application/json;version=1.1"
45
req.accept = "application/json"
46
res = req.get_response(fakes.wsgi_app())
47
self.assertEqual(res.status_int, 200)
48
self.assertEqual(res.content_type, "application/json")
49
body = json.loads(res.body)
50
self.assertEqual(body['version']['id'], 'v2.0')
52
def test_accept_version_v1_1(self):
53
"""Test Accept header specifying v1.1 returns v2 content."""
54
req = webob.Request.blank('/')
55
req.accept = "application/json;version=1.1"
56
res = req.get_response(fakes.wsgi_app())
57
self.assertEqual(res.status_int, 200)
58
self.assertEqual(res.content_type, "application/json")
59
body = json.loads(res.body)
60
self.assertEqual(body['version']['id'], 'v2.0')
62
def test_path_version_v2(self):
63
"""Test URL path specifying v2 returns v2 content."""
64
req = webob.Request.blank('/v2/')
65
req.accept = "application/json"
66
res = req.get_response(fakes.wsgi_app())
67
self.assertEqual(res.status_int, 200)
68
self.assertEqual(res.content_type, "application/json")
69
body = json.loads(res.body)
70
self.assertEqual(body['version']['id'], 'v2.0')
72
def test_content_type_version_v2(self):
73
"""Test Content-Type specifying v2 returns v2 content."""
74
req = webob.Request.blank('/')
75
req.content_type = "application/json;version=2"
76
req.accept = "application/json"
77
res = req.get_response(fakes.wsgi_app())
78
self.assertEqual(res.status_int, 200)
79
self.assertEqual(res.content_type, "application/json")
80
body = json.loads(res.body)
81
self.assertEqual(body['version']['id'], 'v2.0')
83
def test_accept_version_v2(self):
84
"""Test Accept header specifying v2 returns v2 content."""
85
req = webob.Request.blank('/')
86
req.accept = "application/json;version=2"
87
res = req.get_response(fakes.wsgi_app())
88
self.assertEqual(res.status_int, 200)
89
self.assertEqual(res.content_type, "application/json")
90
body = json.loads(res.body)
91
self.assertEqual(body['version']['id'], 'v2.0')
93
def test_path_content_type(self):
94
"""Test URL path specifying JSON returns JSON content."""
95
url = '/v2/foobar/images/cedef40a-ed67-4d10-800e-17455edce175.json'
96
req = webob.Request.blank(url)
97
req.accept = "application/xml"
98
res = req.get_response(fakes.wsgi_app())
99
self.assertEqual(res.status_int, 200)
100
self.assertEqual(res.content_type, "application/json")
101
body = json.loads(res.body)
102
self.assertEqual(body['image']['id'],
103
'cedef40a-ed67-4d10-800e-17455edce175')
105
def test_accept_content_type(self):
106
"""Test Accept header specifying JSON returns JSON content."""
107
url = '/v2/foobar/images/cedef40a-ed67-4d10-800e-17455edce175'
108
req = webob.Request.blank(url)
109
req.accept = "application/xml;q=0.8, application/json"
110
res = req.get_response(fakes.wsgi_app())
111
self.assertEqual(res.status_int, 200)
112
self.assertEqual(res.content_type, "application/json")
113
body = json.loads(res.body)
114
self.assertEqual(body['image']['id'],
115
'cedef40a-ed67-4d10-800e-17455edce175')