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()
73
74
super(SnapshotApiTest, self).setUp()
74
75
self.controller = snapshots.SnapshotsController()
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)
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'])
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)
118
121
snapshot_id = 123
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)
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)
155
161
resp_snapshot = resp_snapshots.pop()
156
162
self.assertEqual(resp_snapshot['id'], '123')
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)
169
self.assertTrue('snapshots' in res)
170
self.assertEqual(1, len(res['snapshots']))
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']))
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']))
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']))
159
192
class SnapshotSerializerTest(test.TestCase):
160
193
def _verify_snapshot(self, snap, tree):