Coverage for manila/tests/api/v2/test_share_snapshot_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_export_locations as export_locations
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 ShareSnapshotExportLocationsAPITest(test.TestCase):
33 def _get_request(self, version="2.32", use_admin_context=True):
34 req = fakes.HTTPRequest.blank(
35 '/v2/fake/snapshots/%s/export-locations' % self.snapshot['id'],
36 version=version, use_admin_context=use_admin_context)
37 return req
39 def setUp(self):
40 super(ShareSnapshotExportLocationsAPITest, self).setUp()
41 self.controller = (
42 export_locations.ShareSnapshotExportLocationController())
44 self.share = db_utils.create_share()
45 self.snapshot = db_utils.create_snapshot(
46 status=constants.STATUS_AVAILABLE,
47 share_id=self.share['id'])
48 self.snapshot_instance = db_utils.create_snapshot_instance(
49 status=constants.STATUS_AVAILABLE,
50 share_instance_id=self.share['instance']['id'],
51 snapshot_id=self.snapshot['id'])
53 self.values = {
54 'share_snapshot_instance_id': self.snapshot_instance['id'],
55 'path': 'fake/user_path',
56 'is_admin_only': True,
57 }
59 self.exp_loc = db_api.share_snapshot_instance_export_location_create(
60 context.get_admin_context(), self.values)
62 self.req = self._get_request()
64 def test_index(self):
65 self.mock_object(
66 db_api, 'share_snapshot_instance_export_locations_get_all',
67 mock.Mock(return_value=[self.exp_loc]))
68 out = self.controller.index(self._get_request('2.32'),
69 self.snapshot['id'])
71 values = {
72 'share_snapshot_export_locations': [{
73 'share_snapshot_instance_id': self.snapshot_instance['id'],
74 'path': 'fake/user_path',
75 'is_admin_only': True,
76 'id': self.exp_loc['id'],
77 'links': [{
78 'href': 'http://localhost/share/v2/fake/'
79 'share_snapshot_export_locations/' +
80 self.exp_loc['id'],
81 'rel': 'self'
82 }, {
83 'href': 'http://localhost/share/fake/'
84 'share_snapshot_export_locations/' +
85 self.exp_loc['id'],
86 'rel': 'bookmark'
87 }],
89 }]
90 }
91 self.assertSubDictMatch(values, out)
93 def test_show(self):
94 out = self.controller.show(self._get_request('2.32'),
95 self.snapshot['id'], self.exp_loc['id'])
97 self.assertSubDictMatch(
98 {'share_snapshot_export_location': self.values}, out)
100 @ddt.data('1.0', '2.0', '2.5', '2.8', '2.31')
101 def test_list_with_unsupported_version(self, version):
102 self.assertRaises(
103 exception.VersionNotFoundForAPIMethod,
104 self.controller.index,
105 self._get_request(version),
106 self.snapshot_instance['id'],
107 )
109 @ddt.data('1.0', '2.0', '2.5', '2.8', '2.31')
110 def test_show_with_unsupported_version(self, version):
111 self.assertRaises(
112 exception.VersionNotFoundForAPIMethod,
113 self.controller.show,
114 self._get_request(version),
115 self.snapshot['id'],
116 self.exp_loc['id']
117 )