|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import copy |
| 14 | + |
| 15 | +from openstackclient.common import quota |
| 16 | +from openstackclient.tests.compute.v2 import fakes as compute_fakes |
| 17 | +from openstackclient.tests import fakes |
| 18 | + |
| 19 | + |
| 20 | +class FakeQuotaResource(fakes.FakeResource): |
| 21 | + |
| 22 | + _keys = {'property': 'value'} |
| 23 | + |
| 24 | + def set_keys(self, args): |
| 25 | + self._keys.update(args) |
| 26 | + |
| 27 | + def unset_keys(self, keys): |
| 28 | + for key in keys: |
| 29 | + self._keys.pop(key, None) |
| 30 | + |
| 31 | + def get_keys(self): |
| 32 | + return self._keys |
| 33 | + |
| 34 | + |
| 35 | +class TestQuota(compute_fakes.TestComputev2): |
| 36 | + |
| 37 | + def setUp(self): |
| 38 | + super(TestQuota, self).setUp() |
| 39 | + self.quotas_mock = self.app.client_manager.compute.quotas |
| 40 | + self.quotas_mock.reset_mock() |
| 41 | + |
| 42 | + |
| 43 | +class TestQuotaSet(TestQuota): |
| 44 | + |
| 45 | + def setUp(self): |
| 46 | + super(TestQuotaSet, self).setUp() |
| 47 | + |
| 48 | + self.quotas_mock.find.return_value = FakeQuotaResource( |
| 49 | + None, |
| 50 | + copy.deepcopy(compute_fakes.QUOTA), |
| 51 | + loaded=True, |
| 52 | + ) |
| 53 | + |
| 54 | + self.quotas_mock.update.return_value = FakeQuotaResource( |
| 55 | + None, |
| 56 | + copy.deepcopy(compute_fakes.QUOTA), |
| 57 | + loaded=True, |
| 58 | + ) |
| 59 | + |
| 60 | + self.cmd = quota.SetQuota(self.app, None) |
| 61 | + |
| 62 | + def test_quota_set(self): |
| 63 | + arglist = [ |
| 64 | + '--floating-ips', str(compute_fakes.floating_ip_num), |
| 65 | + '--fixed-ips', str(compute_fakes.fix_ip_num), |
| 66 | + '--injected-files', str(compute_fakes.injected_file_num), |
| 67 | + '--key-pairs', str(compute_fakes.key_pair_num), |
| 68 | + compute_fakes.project_name, |
| 69 | + ] |
| 70 | + verifylist = [ |
| 71 | + ('floating_ips', compute_fakes.floating_ip_num), |
| 72 | + ('fixed_ips', compute_fakes.fix_ip_num), |
| 73 | + ('injected_files', compute_fakes.injected_file_num), |
| 74 | + ('key_pairs', compute_fakes.key_pair_num), |
| 75 | + ('project', compute_fakes.project_name), |
| 76 | + ] |
| 77 | + |
| 78 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 79 | + |
| 80 | + self.cmd.take_action(parsed_args) |
| 81 | + |
| 82 | + kwargs = { |
| 83 | + 'floating_ips': compute_fakes.floating_ip_num, |
| 84 | + 'fixed_ips': compute_fakes.fix_ip_num, |
| 85 | + 'injected_files': compute_fakes.injected_file_num, |
| 86 | + 'key_pairs': compute_fakes.key_pair_num, |
| 87 | + } |
| 88 | + |
| 89 | + self.quotas_mock.update.assert_called_with('project_test', **kwargs) |
0 commit comments