diff options
| author | xiexs <xiexs@cn.fujitsu.com> | 2015-11-04 10:22:39 -0500 |
|---|---|---|
| committer | xiexs <xiexs@cn.fujitsu.com> | 2015-11-04 10:22:46 -0500 |
| commit | 7d8bb331a0ab516aaa3721b9b200a388214a22cb (patch) | |
| tree | d36f2c465e4ee90e6c2c4baa7588018d9dc059e0 /openstackclient/tests/common | |
| parent | 266ecf57f508b7dab2e005aecff9dc66bb81a6d1 (diff) | |
| download | python-openstackclient-7d8bb331a0ab516aaa3721b9b200a388214a22cb.tar.gz | |
Add project-name/-id validation for the OSC "openstack quota set"
The quota info would be set into DB, even though the project actually
does not exist.
This patch tried to add a validation to forbid this undesirable behavior.
Change-Id: Ia2d8c96527820e25b074e6486d3f39c5ad7eae60
Closes-Bug: #1512638
Diffstat (limited to 'openstackclient/tests/common')
| -rw-r--r-- | openstackclient/tests/common/test_quota.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/openstackclient/tests/common/test_quota.py b/openstackclient/tests/common/test_quota.py index b6ad1566..047ef343 100644 --- a/openstackclient/tests/common/test_quota.py +++ b/openstackclient/tests/common/test_quota.py @@ -17,6 +17,7 @@ import mock from openstackclient.common import quota from openstackclient.tests.compute.v2 import fakes as compute_fakes from openstackclient.tests import fakes +from openstackclient.tests.identity.v2_0 import fakes as identity_fakes class FakeQuotaResource(fakes.FakeResource): @@ -45,6 +46,8 @@ class TestQuota(compute_fakes.TestComputev2): self.app.client_manager.volume = volume_mock self.volume_quotas_mock = volume_mock.quotas self.volume_quotas_mock.reset_mock() + self.projects_mock = self.app.client_manager.identity.projects + self.projects_mock.reset_mock() class TestQuotaSet(TestQuota): @@ -76,6 +79,12 @@ class TestQuotaSet(TestQuota): loaded=True, ) + self.projects_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(identity_fakes.PROJECT), + loaded=True, + ) + self.cmd = quota.SetQuota(self.app, None) def test_quota_set(self): @@ -84,14 +93,14 @@ class TestQuotaSet(TestQuota): '--fixed-ips', str(compute_fakes.fix_ip_num), '--injected-files', str(compute_fakes.injected_file_num), '--key-pairs', str(compute_fakes.key_pair_num), - compute_fakes.project_name, + identity_fakes.project_name, ] verifylist = [ ('floating_ips', compute_fakes.floating_ip_num), ('fixed_ips', compute_fakes.fix_ip_num), ('injected_files', compute_fakes.injected_file_num), ('key_pairs', compute_fakes.key_pair_num), - ('project', compute_fakes.project_name), + ('project', identity_fakes.project_name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -105,14 +114,17 @@ class TestQuotaSet(TestQuota): 'key_pairs': compute_fakes.key_pair_num, } - self.quotas_mock.update.assert_called_with('project_test', **kwargs) + self.quotas_mock.update.assert_called_with( + identity_fakes.project_id, + **kwargs + ) def test_quota_set_volume(self): arglist = [ '--gigabytes', str(compute_fakes.floating_ip_num), '--snapshots', str(compute_fakes.fix_ip_num), '--volumes', str(compute_fakes.injected_file_num), - compute_fakes.project_name, + identity_fakes.project_name, ] verifylist = [ ('gigabytes', compute_fakes.floating_ip_num), @@ -130,5 +142,7 @@ class TestQuotaSet(TestQuota): 'volumes': compute_fakes.injected_file_num, } - self.volume_quotas_mock.update.assert_called_with('project_test', - **kwargs) + self.volume_quotas_mock.update.assert_called_with( + identity_fakes.project_id, + **kwargs + ) |
