Coverage for manila/tests/api/v2/test_share_snapshot_instance_export_locations.py: 100%
38 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2016 Hitachi Data Systems
2# All Rights Reserved.
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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
14# under the License.
16from unittest import mock
18import ddt
20from manila.api.v2 import share_snapshot_instance_export_locations as exp_loc
21from manila.common import constants
22from manila import context
23from manila.db.sqlalchemy import api as db_api
24from manila import exception
25from manila import test
26from manila.tests.api import fakes
27from manila.tests import db_utils
30@ddt.ddt
31class ShareSnapshotInstanceExportLocationsAPITest(test.TestCase):
33 def _get_request(self, version="2.32", use_admin_context=True):
34 req = fakes.HTTPRequest.blank(
35 '/v2/fake/snapshot-instances/%s/export-locations' %
36 self.snapshot_instance['id'],
37 version=version, use_admin_context=use_admin_context)
38 return req
40 def setUp(self):
41 super(ShareSnapshotInstanceExportLocationsAPITest, self).setUp()
42 self.controller = (
43 exp_loc.ShareSnapshotInstanceExportLocationController())
45 self.share = db_utils.create_share()
46 self.snapshot = db_utils.create_snapshot(
47 status=constants.STATUS_AVAILABLE,
48 share_id=self.share['id'])
49 self.snapshot_instance = db_utils.create_snapshot_instance(
50 'fake_snapshot_id_1',
51 status=constants.STATUS_CREATING,
52 share_instance_id=self.share['instance']['id'])
54 self.values = {
55 'share_snapshot_instance_id': self.snapshot_instance['id'],
56 'path': 'fake/user_path',
57 'is_admin_only': True,
58 }
59 self.el = db_api.share_snapshot_instance_export_location_create(
60 context.get_admin_context(), self.values)
61 self.req = self._get_request()
63 def test_index(self):
64 self.mock_object(
65 db_api, 'share_snapshot_instance_export_locations_get_all',
66 mock.Mock(return_value=[self.el]))
67 out = self.controller.index(self._get_request('2.32'),
68 self.snapshot_instance['id'])
70 values = {
71 'share_snapshot_export_locations': [{
72 'share_snapshot_instance_id': self.snapshot_instance['id'],
73 'path': 'fake/user_path',
74 'is_admin_only': True,
75 'id': self.el['id'],
76 'links': [{
77 'href': 'http://localhost/share/v2/fake/'
78 'share_snapshot_export_locations/' + self.el['id'],
79 'rel': 'self'
80 }, {
81 'href': 'http://localhost/share/fake/'
82 'share_snapshot_export_locations/' + self.el['id'],
83 'rel': 'bookmark'
84 }],
85 }]
86 }
87 self.assertSubDictMatch(values, out)
89 def test_show(self):
90 out = self.controller.show(self._get_request('2.32'),
91 self.snapshot_instance['id'],
92 self.el['id'])
94 self.assertSubDictMatch(
95 {'share_snapshot_export_location': self.values}, out)
97 @ddt.data('1.0', '2.0', '2.5', '2.8', '2.31')
98 def test_list_with_unsupported_version(self, version):
99 self.assertRaises(
100 exception.VersionNotFoundForAPIMethod,
101 self.controller.index,
102 self._get_request(version),
103 self.snapshot_instance['id'],
104 )
106 @ddt.data('1.0', '2.0', '2.5', '2.8', '2.31')
107 def test_show_with_unsupported_version(self, version):
108 self.assertRaises(
109 exception.VersionNotFoundForAPIMethod,
110 self.controller.show,
111 self._get_request(version),
112 self.snapshot['id'],
113 self.el['id']
114 )