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

47 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_class_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_class_sets.ViewBuilder() 

30 

31 def test__collection_name(self): 

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

33 

34 @ddt.data( 

35 ("fake_quota_class", "2.40"), (None, "2.40"), 

36 ("fake_quota_class", "2.39"), (None, "2.39"), 

37 ("fake_quota_class", "2.53"), (None, "2.53"), 

38 ("fake_quota_class", "2.62"), (None, "2.62"), 

39 ("fake_quota_class", "2.80"), (None, "2.80"), 

40 ("fake_quota_class", "2.90"), (None, "2.90"), 

41 ) 

42 @ddt.unpack 

43 def test_detail_list_with_share_type(self, quota_class, microversion): 

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

45 quota_class_set = { 

46 "shares": 13, 

47 "gigabytes": 31, 

48 "snapshots": 14, 

49 "snapshot_gigabytes": 41, 

50 "share_groups": 15, 

51 "share_group_snapshots": 51, 

52 "share_networks": 16, 

53 } 

54 expected = {self.builder._collection_name: { 

55 "shares": quota_class_set["shares"], 

56 "gigabytes": quota_class_set["gigabytes"], 

57 "snapshots": quota_class_set["snapshots"], 

58 "snapshot_gigabytes": quota_class_set["snapshot_gigabytes"], 

59 "share_networks": quota_class_set["share_networks"], 

60 }} 

61 if quota_class: 

62 expected[self.builder._collection_name]['id'] = quota_class 

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

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

65 expected[self.builder._collection_name][ 

66 "share_groups"] = quota_class_set["share_groups"] 

67 expected[self.builder._collection_name][ 

68 "share_group_snapshots"] = quota_class_set[ 

69 "share_group_snapshots"] 

70 

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

72 fake_share_replicas_value = 46 

73 fake_replica_gigabytes_value = 100 

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

75 fake_share_replicas_value) 

76 expected[self.builder._collection_name][ 

77 "replica_gigabytes"] = fake_replica_gigabytes_value 

78 quota_class_set['share_replicas'] = fake_share_replicas_value 

79 quota_class_set['replica_gigabytes'] = fake_replica_gigabytes_value 

80 

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

82 fake_per_share_gigabytes = 10 

83 expected[self.builder._collection_name][ 

84 "per_share_gigabytes"] = fake_per_share_gigabytes 

85 quota_class_set['per_share_gigabytes'] = fake_per_share_gigabytes 

86 

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

88 fake_share_backups_value = 46 

89 fake_backup_gigabytes_value = 100 

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

91 fake_share_backups_value) 

92 expected[self.builder._collection_name][ 

93 "backup_gigabytes"] = fake_backup_gigabytes_value 

94 quota_class_set['backups'] = fake_share_backups_value 

95 quota_class_set['backup_gigabytes'] = fake_backup_gigabytes_value 

96 

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

98 fake_encryption_keys = 10 

99 expected[self.builder._collection_name][ 

100 "encryption_keys"] = fake_encryption_keys 

101 quota_class_set['encryption_keys'] = ( 

102 fake_encryption_keys) 

103 

104 result = self.builder.detail_list( 

105 req, quota_class_set, quota_class=quota_class) 

106 

107 self.assertEqual(expected, result)