1
# Copyright 2011 Denali Systems, Inc.
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
17
from nova.api.openstack import volume
18
from nova.api.openstack.volume import snapshots
19
from nova.api.openstack.volume import versions
20
from nova.api.openstack.volume import volumes
21
from nova.api.openstack import wsgi
22
from nova import flags
23
from nova.openstack.common import log as logging
25
from nova.tests.api.openstack import fakes
29
LOG = logging.getLogger(__name__)
32
class FakeController(object):
33
def __init__(self, ext_mgr=None):
34
self.ext_mgr = ext_mgr
39
def detail(self, req):
43
def create_resource(ext_mgr):
44
return wsgi.Resource(FakeController(ext_mgr))
47
def create_volume_resource(ext_mgr):
48
return wsgi.Resource(FakeController(ext_mgr))
51
class VolumeRouterTestCase(test.TestCase):
53
super(VolumeRouterTestCase, self).setUp()
54
# NOTE(vish): versions is just returning text so, no need to stub.
55
self.stubs.Set(snapshots, 'create_resource', create_resource)
56
self.stubs.Set(volumes, 'create_resource', create_volume_resource)
57
self.app = volume.APIRouter()
59
def test_versions(self):
60
req = fakes.HTTPRequest.blank('')
62
req.content_type = 'application/json'
63
response = req.get_response(self.app)
64
self.assertEqual(302, response.status_int)
65
req = fakes.HTTPRequest.blank('/')
67
req.content_type = 'application/json'
68
response = req.get_response(self.app)
69
self.assertEqual(200, response.status_int)
71
def test_versions_dispatch(self):
72
req = fakes.HTTPRequest.blank('/')
74
req.content_type = 'application/json'
75
resource = versions.Versions()
76
result = resource.dispatch(resource.index, req, {})
77
self.assertTrue(result)
79
def test_volumes(self):
80
req = fakes.HTTPRequest.blank('/fake/volumes')
82
req.content_type = 'application/json'
83
response = req.get_response(self.app)
84
self.assertEqual(200, response.status_int)
86
def test_volumes_detail(self):
87
req = fakes.HTTPRequest.blank('/fake/volumes/detail')
89
req.content_type = 'application/json'
90
response = req.get_response(self.app)
91
self.assertEqual(200, response.status_int)
94
req = fakes.HTTPRequest.blank('/fake/types')
96
req.content_type = 'application/json'
97
response = req.get_response(self.app)
98
self.assertEqual(200, response.status_int)
100
def test_snapshots(self):
101
req = fakes.HTTPRequest.blank('/fake/snapshots')
103
req.content_type = 'application/json'
104
response = req.get_response(self.app)
105
self.assertEqual(200, response.status_int)
107
def test_snapshots_detail(self):
108
req = fakes.HTTPRequest.blank('/fake/snapshots/detail')
110
req.content_type = 'application/json'
111
response = req.get_response(self.app)
112
self.assertEqual(200, response.status_int)