Coverage for manila/tests/api/views/test_shares.py: 100%
53 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) 2015 Mirantis, Inc.
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.
16import copy
17import ddt
19from manila.api.views import shares
20from manila.common import constants
21from manila import test
22from manila.tests.api.contrib import stubs
23from manila.tests.api import fakes
26@ddt.ddt
27class ViewBuilderTestCase(test.TestCase):
29 def setUp(self):
30 super(ViewBuilderTestCase, self).setUp()
31 self.builder = shares.ViewBuilder()
32 self.fake_share = self._get_fake_share()
34 def _get_fake_share(self):
36 fake_share = {
37 'share_type_id': 'fake_share_type_id',
38 'share_type': {
39 'name': 'fake_share_type_name',
40 },
41 'export_location': 'fake_export_location',
42 'export_locations': ['fake_export_location'],
43 'access_rules_status': 'fake_rule_status',
44 'instance': {
45 'share_type': {
46 'name': 'fake_share_type_name',
47 },
48 'share_type_id': 'fake_share_type_id',
49 'progress': '100%',
50 },
51 'replication_type': 'fake_replication_type',
52 'has_replicas': False,
53 'user_id': 'fake_userid',
54 'snapshot_support': True,
55 'create_share_from_snapshot_support': True,
56 'revert_to_snapshot_support': True,
57 'progress': '100%',
58 'scheduled_to_be_deleted_at': 'fake_datetime',
59 }
60 return stubs.stub_share('fake_id', **fake_share)
62 def test__collection_name(self):
63 self.assertEqual('shares', self.builder._collection_name)
65 @ddt.data('2.6', '2.9', '2.10', '2.11', '2.16',
66 '2.24', '2.27', '2.54', '2.69')
67 def test_detail(self, microversion):
68 req = fakes.HTTPRequest.blank('/shares', version=microversion)
70 result = self.builder.detail(req, self.fake_share)
72 expected = {
73 'id': self.fake_share['id'],
74 'share_type': self.fake_share['share_type_id'],
75 'share_type_name': self.fake_share['share_type']['name'],
76 'export_location': 'fake_export_location',
77 'export_locations': ['fake_export_location'],
78 'snapshot_support': True,
79 }
80 if self.is_microversion_ge(microversion, '2.9'):
81 expected.pop('export_location')
82 expected.pop('export_locations')
83 if self.is_microversion_ge(microversion, '2.10'):
84 expected['access_rules_status'] = 'fake_rule_status'
85 if self.is_microversion_ge(microversion, '2.11'):
86 expected['replication_type'] = 'fake_replication_type'
87 expected['has_replicas'] = False
88 if self.is_microversion_ge(microversion, '2.16'):
89 expected['user_id'] = 'fake_userid'
90 if self.is_microversion_ge(microversion, '2.24'):
91 expected['create_share_from_snapshot_support'] = True
92 if self.is_microversion_ge(microversion, '2.27'):
93 expected['revert_to_snapshot_support'] = True
94 if self.is_microversion_ge(microversion, '2.54'):
95 expected['progress'] = '100%'
96 if self.is_microversion_ge(microversion, '2.69'):
97 expected['scheduled_to_be_deleted_at'] = 'fake_datetime'
99 self.assertSubDictMatch(expected, result['share'])
101 @ddt.data('1.0', '2.51', '2.54')
102 def test_detail_translate_creating_from_snapshot_status(self,
103 microversion):
104 req = fakes.HTTPRequest.blank('/shares', version=microversion)
105 new_share_status = constants.STATUS_CREATING_FROM_SNAPSHOT
107 fake_shr = copy.deepcopy(self.fake_share)
108 fake_shr.update(
109 {'status': new_share_status})
110 result = self.builder.detail(req, fake_shr)
112 expected = {
113 'status': constants.STATUS_CREATING,
114 }
115 if self.is_microversion_ge(microversion, '2.54'):
116 expected['status'] = new_share_status
118 self.assertSubDictMatch(expected, result['share'])