~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/volume/test_snapshots.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import webob
18
18
 
19
19
from nova.api.openstack.volume import snapshots
 
20
from nova import db
20
21
from nova import exception
21
22
from nova import flags
22
23
from nova.openstack.common import log as logging
63
64
    return param
64
65
 
65
66
 
66
 
def stub_snapshot_get_all(self, context):
 
67
def stub_snapshot_get_all(self, context, search_opts=None):
67
68
    param = _get_default_snapshot_param()
68
69
    return [param]
69
70
 
73
74
        super(SnapshotApiTest, self).setUp()
74
75
        self.controller = snapshots.SnapshotsController()
75
76
 
76
 
        self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
77
 
        self.stubs.Set(volume.api.API, "get_all_snapshots",
78
 
            stub_snapshot_get_all)
 
77
        self.stubs.Set(db, 'snapshot_get_all_by_project',
 
78
                       fakes.stub_snapshot_get_all_by_project)
 
79
        self.stubs.Set(db, 'snapshot_get_all',
 
80
                      fakes.stub_snapshot_get_all)
79
81
 
80
82
    def test_snapshot_create(self):
81
83
        self.stubs.Set(volume.api.API, "create_snapshot", stub_snapshot_create)
113
115
                        snapshot['display_description'])
114
116
 
115
117
    def test_snapshot_delete(self):
 
118
        self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
116
119
        self.stubs.Set(volume.api.API, "delete_snapshot", stub_snapshot_delete)
117
120
 
118
121
        snapshot_id = 123
130
133
                          snapshot_id)
131
134
 
132
135
    def test_snapshot_show(self):
 
136
        self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
133
137
        req = fakes.HTTPRequest.blank('/v1/snapshots/123')
134
138
        resp_dict = self.controller.show(req, 123)
135
139
 
145
149
                          snapshot_id)
146
150
 
147
151
    def test_snapshot_detail(self):
 
152
        self.stubs.Set(volume.api.API, "get_all_snapshots",
 
153
                      stub_snapshot_get_all)
148
154
        req = fakes.HTTPRequest.blank('/v1/snapshots/detail')
149
155
        resp_dict = self.controller.detail(req)
150
156
 
155
161
        resp_snapshot = resp_snapshots.pop()
156
162
        self.assertEqual(resp_snapshot['id'], '123')
157
163
 
 
164
    def test_admin_list_snapshots_limited_to_project(self):
 
165
        req = fakes.HTTPRequest.blank('/v1/fake/snapshots',
 
166
                                      use_admin_context=True)
 
167
        res = self.controller.index(req)
 
168
 
 
169
        self.assertTrue('snapshots' in res)
 
170
        self.assertEqual(1, len(res['snapshots']))
 
171
 
 
172
    def test_admin_list_snapshots_all_tenants(self):
 
173
        req = fakes.HTTPRequest.blank('/v2/fake/snapshots?all_tenants=1',
 
174
                                      use_admin_context=True)
 
175
        res = self.controller.index(req)
 
176
        self.assertTrue('snapshots' in res)
 
177
        self.assertEqual(3, len(res['snapshots']))
 
178
 
 
179
    def test_all_tenants_non_admin_gets_all_tenants(self):
 
180
        req = fakes.HTTPRequest.blank('/v2/fake/snapshots?all_tenants=1')
 
181
        res = self.controller.index(req)
 
182
        self.assertTrue('snapshots' in res)
 
183
        self.assertEqual(1, len(res['snapshots']))
 
184
 
 
185
    def test_non_admin_get_by_project(self):
 
186
        req = fakes.HTTPRequest.blank('/v2/fake/snapshots')
 
187
        res = self.controller.index(req)
 
188
        self.assertTrue('snapshots' in res)
 
189
        self.assertEqual(1, len(res['snapshots']))
 
190
 
158
191
 
159
192
class SnapshotSerializerTest(test.TestCase):
160
193
    def _verify_snapshot(self, snap, tree):