Coverage for manila/tests/api/views/test_quota_sets.py: 100%

49 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright (c) 2017 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. 

15 

16import ddt 

17 

18from manila.api.openstack import api_version_request as api_version 

19from manila.api.views import quota_sets 

20from manila import test 

21from manila.tests.api import fakes 

22 

23 

24@ddt.ddt 

25class ViewBuilderTestCase(test.TestCase): 

26 

27 def setUp(self): 

28 super(ViewBuilderTestCase, self).setUp() 

29 self.builder = quota_sets.ViewBuilder() 

30 

31 def test__collection_name(self): 

32 self.assertEqual('quota_set', self.builder._collection_name) 

33 

34 @ddt.data( 

35 ('fake_project_id', 'fake_share_type_id', "2.40"), 

36 (None, 'fake_share_type_id', "2.40"), 

37 ('fake_project_id', None, "2.40"), 

38 (None, None, "2.40"), 

39 ('fake_project_id', 'fake_share_type_id', "2.39"), 

40 (None, 'fake_share_type_id', "2.39"), 

41 ('fake_project_id', None, "2.39"), 

42 (None, None, "2.39"), 

43 (None, 'fake_share_type_id', "2.53"), 

44 ('fake_project_id', None, "2.53"), 

45 (None, None, "2.53"), 

46 (None, 'fake_share_type_id', "2.62"), 

47 ('fake_project_id', None, "2.62"), 

48 (None, None, "2.62"), 

49 ('fake_project_id', None, "2.80"), 

50 (None, None, "2.80"), 

51 ('fake_project_id', None, "2.90"), 

52 (None, None, "2.90"), 

53 ) 

54 @ddt.unpack 

55 def test_detail_list_with_share_type(self, project_id, share_type, 

56 microversion): 

57 req = fakes.HTTPRequest.blank('/quota-sets', version=microversion) 

58 quota_set = { 

59 "shares": 13, 

60 "gigabytes": 31, 

61 "snapshots": 14, 

62 "snapshot_gigabytes": 41, 

63 "share_groups": 15, 

64 "share_group_snapshots": 51, 

65 "share_networks": 16, 

66 } 

67 expected = {self.builder._collection_name: { 

68 "shares": quota_set["shares"], 

69 "gigabytes": quota_set["gigabytes"], 

70 "snapshots": quota_set["snapshots"], 

71 "snapshot_gigabytes": quota_set["snapshot_gigabytes"], 

72 }} 

73 if project_id: 

74 expected[self.builder._collection_name]['id'] = project_id 

75 if not share_type: 

76 expected[self.builder._collection_name][ 

77 "share_networks"] = quota_set["share_networks"] 

78 if (api_version.APIVersionRequest(microversion) >= ( 

79 api_version.APIVersionRequest("2.40"))): 

80 expected[self.builder._collection_name][ 

81 "share_groups"] = quota_set["share_groups"] 

82 expected[self.builder._collection_name][ 

83 "share_group_snapshots"] = quota_set[ 

84 "share_group_snapshots"] 

85 

86 if req.api_version_request >= api_version.APIVersionRequest("2.53"): 

87 fake_share_replicas_value = 46 

88 fake_replica_gigabytes_value = 100 

89 expected[self.builder._collection_name]["share_replicas"] = ( 

90 fake_share_replicas_value) 

91 expected[self.builder._collection_name][ 

92 "replica_gigabytes"] = fake_replica_gigabytes_value 

93 quota_set['share_replicas'] = fake_share_replicas_value 

94 quota_set['replica_gigabytes'] = fake_replica_gigabytes_value 

95 

96 if req.api_version_request >= api_version.APIVersionRequest("2.62"): 

97 fake_per_share_gigabytes = 10 

98 expected[self.builder._collection_name]["per_share_gigabytes"] = ( 

99 fake_per_share_gigabytes) 

100 quota_set['per_share_gigabytes'] = fake_per_share_gigabytes 

101 

102 if req.api_version_request >= api_version.APIVersionRequest("2.80"): 

103 fake_share_backups_value = 46 

104 fake_backup_gigabytes_value = 100 

105 expected[self.builder._collection_name]["backups"] = ( 

106 fake_share_backups_value) 

107 expected[self.builder._collection_name][ 

108 "backup_gigabytes"] = fake_backup_gigabytes_value 

109 quota_set['backups'] = fake_share_backups_value 

110 quota_set['backup_gigabytes'] = fake_backup_gigabytes_value 

111 

112 if req.api_version_request >= api_version.APIVersionRequest("2.90"): 

113 fake_encryption_keys = 10 

114 expected[self.builder._collection_name][ 

115 "encryption_keys"] = ( 

116 fake_per_share_gigabytes) 

117 quota_set['encryption_keys'] = fake_encryption_keys 

118 

119 result = self.builder.detail_list( 

120 req, quota_set, project_id=project_id, share_type=share_type) 

121 

122 self.assertEqual(expected, result)