Unit tests of quota command refactor
Do refactor for quota command related unit tests, remove useless code, add new tests to cover '--volume-type' and '--class' option in "quota set" command and add the volume quota fake object. Change-Id: Iaf214740e98db1bfb4c739e810bac1c5ba6e9625
This commit is contained in:
parent
d2273ecea5
commit
4e71e9da6b
@ -18,6 +18,7 @@ from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
|||||||
from openstackclient.tests.unit import fakes
|
from openstackclient.tests.unit import fakes
|
||||||
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
|
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
|
||||||
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
|
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
|
||||||
|
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||||
|
|
||||||
|
|
||||||
class FakeQuotaResource(fakes.FakeResource):
|
class FakeQuotaResource(fakes.FakeResource):
|
||||||
@ -43,10 +44,7 @@ class TestQuota(compute_fakes.TestComputev2):
|
|||||||
self.quotas_mock.reset_mock()
|
self.quotas_mock.reset_mock()
|
||||||
self.quotas_class_mock = self.app.client_manager.compute.quota_classes
|
self.quotas_class_mock = self.app.client_manager.compute.quota_classes
|
||||||
self.quotas_class_mock.reset_mock()
|
self.quotas_class_mock.reset_mock()
|
||||||
volume_mock = mock.Mock()
|
self.volume_quotas_mock = self.app.client_manager.volume.quotas
|
||||||
volume_mock.quotas = mock.Mock()
|
|
||||||
self.app.client_manager.volume = volume_mock
|
|
||||||
self.volume_quotas_mock = volume_mock.quotas
|
|
||||||
self.volume_quotas_mock.reset_mock()
|
self.volume_quotas_mock.reset_mock()
|
||||||
self.volume_quotas_class_mock = \
|
self.volume_quotas_class_mock = \
|
||||||
self.app.client_manager.volume.quota_classes
|
self.app.client_manager.volume.quota_classes
|
||||||
@ -66,24 +64,12 @@ class TestQuotaSet(TestQuota):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestQuotaSet, self).setUp()
|
super(TestQuotaSet, self).setUp()
|
||||||
|
|
||||||
self.quotas_mock.find.return_value = FakeQuotaResource(
|
|
||||||
None,
|
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
|
||||||
loaded=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.quotas_mock.update.return_value = FakeQuotaResource(
|
self.quotas_mock.update.return_value = FakeQuotaResource(
|
||||||
None,
|
None,
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
copy.deepcopy(compute_fakes.QUOTA),
|
||||||
loaded=True,
|
loaded=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.volume_quotas_mock.find.return_value = FakeQuotaResource(
|
|
||||||
None,
|
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
|
||||||
loaded=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.volume_quotas_mock.update.return_value = FakeQuotaResource(
|
self.volume_quotas_mock.update.return_value = FakeQuotaResource(
|
||||||
None,
|
None,
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
copy.deepcopy(compute_fakes.QUOTA),
|
||||||
@ -141,7 +127,7 @@ class TestQuotaSet(TestQuota):
|
|||||||
self.app.client_manager.network_endpoint_enabled = False
|
self.app.client_manager.network_endpoint_enabled = False
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'floating_ips': compute_fakes.floating_ip_num,
|
'floating_ips': compute_fakes.floating_ip_num,
|
||||||
@ -161,39 +147,73 @@ class TestQuotaSet(TestQuota):
|
|||||||
'server_group_members': compute_fakes.servgroup_members_num,
|
'server_group_members': compute_fakes.servgroup_members_num,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.quotas_mock.update.assert_called_with(
|
self.quotas_mock.update.assert_called_once_with(
|
||||||
identity_fakes.project_id,
|
identity_fakes.project_id,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_quota_set_volume(self):
|
def test_quota_set_volume(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--gigabytes', str(compute_fakes.floating_ip_num),
|
'--gigabytes', str(volume_fakes.QUOTA['gigabytes']),
|
||||||
'--snapshots', str(compute_fakes.fix_ip_num),
|
'--snapshots', str(volume_fakes.QUOTA['snapshots']),
|
||||||
'--volumes', str(compute_fakes.injected_file_num),
|
'--volumes', str(volume_fakes.QUOTA['volumes']),
|
||||||
identity_fakes.project_name,
|
identity_fakes.project_name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('gigabytes', compute_fakes.floating_ip_num),
|
('gigabytes', volume_fakes.QUOTA['gigabytes']),
|
||||||
('snapshots', compute_fakes.fix_ip_num),
|
('snapshots', volume_fakes.QUOTA['snapshots']),
|
||||||
('volumes', compute_fakes.injected_file_num),
|
('volumes', volume_fakes.QUOTA['volumes']),
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'gigabytes': compute_fakes.floating_ip_num,
|
'gigabytes': volume_fakes.QUOTA['gigabytes'],
|
||||||
'snapshots': compute_fakes.fix_ip_num,
|
'snapshots': volume_fakes.QUOTA['snapshots'],
|
||||||
'volumes': compute_fakes.injected_file_num,
|
'volumes': volume_fakes.QUOTA['volumes'],
|
||||||
}
|
}
|
||||||
|
|
||||||
self.volume_quotas_mock.update.assert_called_with(
|
self.volume_quotas_mock.update.assert_called_once_with(
|
||||||
identity_fakes.project_id,
|
identity_fakes.project_id,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_quota_set_volume_with_volume_type(self):
|
||||||
|
arglist = [
|
||||||
|
'--gigabytes', str(volume_fakes.QUOTA['gigabytes']),
|
||||||
|
'--snapshots', str(volume_fakes.QUOTA['snapshots']),
|
||||||
|
'--volumes', str(volume_fakes.QUOTA['volumes']),
|
||||||
|
'--volume-type', 'volume_type_backend',
|
||||||
|
identity_fakes.project_name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('gigabytes', volume_fakes.QUOTA['gigabytes']),
|
||||||
|
('snapshots', volume_fakes.QUOTA['snapshots']),
|
||||||
|
('volumes', volume_fakes.QUOTA['volumes']),
|
||||||
|
('volume_type', 'volume_type_backend'),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
kwargs = {
|
||||||
|
'gigabytes_volume_type_backend': volume_fakes.QUOTA['gigabytes'],
|
||||||
|
'snapshots_volume_type_backend': volume_fakes.QUOTA['snapshots'],
|
||||||
|
'volumes_volume_type_backend': volume_fakes.QUOTA['volumes'],
|
||||||
|
}
|
||||||
|
|
||||||
|
self.volume_quotas_mock.update.assert_called_once_with(
|
||||||
|
identity_fakes.project_id,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_quota_set_network(self):
|
def test_quota_set_network(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--subnets', str(network_fakes.QUOTA['subnet']),
|
'--subnets', str(network_fakes.QUOTA['subnet']),
|
||||||
@ -228,7 +248,7 @@ class TestQuotaSet(TestQuota):
|
|||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'subnet': network_fakes.QUOTA['subnet'],
|
'subnet': network_fakes.QUOTA['subnet'],
|
||||||
'network': network_fakes.QUOTA['network'],
|
'network': network_fakes.QUOTA['network'],
|
||||||
@ -244,10 +264,38 @@ class TestQuotaSet(TestQuota):
|
|||||||
'member': network_fakes.QUOTA['member'],
|
'member': network_fakes.QUOTA['member'],
|
||||||
'health_monitor': network_fakes.QUOTA['health_monitor'],
|
'health_monitor': network_fakes.QUOTA['health_monitor'],
|
||||||
}
|
}
|
||||||
self.network_mock.update_quota.assert_called_with(
|
self.network_mock.update_quota.assert_called_once_with(
|
||||||
identity_fakes.project_id,
|
identity_fakes.project_id,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_quota_set_with_class(self):
|
||||||
|
arglist = [
|
||||||
|
'--instances', str(compute_fakes.instance_num),
|
||||||
|
'--volumes', str(volume_fakes.QUOTA['volumes']),
|
||||||
|
'--network', str(network_fakes.QUOTA['network']),
|
||||||
|
'--class',
|
||||||
|
identity_fakes.project_name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('instances', compute_fakes.instance_num),
|
||||||
|
('volumes', volume_fakes.QUOTA['volumes']),
|
||||||
|
('network', network_fakes.QUOTA['network']),
|
||||||
|
('quota_class', True),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
self.quotas_class_mock.update.assert_called_once_with(
|
||||||
|
identity_fakes.project_id,
|
||||||
|
**{'instances': compute_fakes.instance_num}
|
||||||
|
)
|
||||||
|
self.volume_quotas_class_mock.update.assert_called_once_with(
|
||||||
|
identity_fakes.project_id,
|
||||||
|
**{'volumes': volume_fakes.QUOTA['volumes']}
|
||||||
|
)
|
||||||
|
self.assertNotCalled(self.network_mock.update_quota)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
class TestQuotaShow(TestQuota):
|
class TestQuotaShow(TestQuota):
|
||||||
@ -269,13 +317,13 @@ class TestQuotaShow(TestQuota):
|
|||||||
|
|
||||||
self.volume_quotas_mock.get.return_value = FakeQuotaResource(
|
self.volume_quotas_mock.get.return_value = FakeQuotaResource(
|
||||||
None,
|
None,
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
copy.deepcopy(volume_fakes.QUOTA),
|
||||||
loaded=True,
|
loaded=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.volume_quotas_mock.defaults.return_value = FakeQuotaResource(
|
self.volume_quotas_mock.defaults.return_value = FakeQuotaResource(
|
||||||
None,
|
None,
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
copy.deepcopy(volume_fakes.QUOTA),
|
||||||
loaded=True,
|
loaded=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -297,7 +345,7 @@ class TestQuotaShow(TestQuota):
|
|||||||
|
|
||||||
self.volume_quotas_class_mock.get.return_value = FakeQuotaResource(
|
self.volume_quotas_class_mock.get.return_value = FakeQuotaResource(
|
||||||
None,
|
None,
|
||||||
copy.deepcopy(compute_fakes.QUOTA),
|
copy.deepcopy(volume_fakes.QUOTA),
|
||||||
loaded=True,
|
loaded=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -328,10 +376,11 @@ class TestQuotaShow(TestQuota):
|
|||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.quotas_mock.get.assert_called_with(identity_fakes.project_id)
|
self.quotas_mock.get.assert_called_once_with(identity_fakes.project_id)
|
||||||
self.volume_quotas_mock.get.assert_called_with(
|
self.volume_quotas_mock.get.assert_called_once_with(
|
||||||
|
identity_fakes.project_id)
|
||||||
|
self.network.get_quota.assert_called_once_with(
|
||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
self.network.get_quota.assert_called_with(identity_fakes.project_id)
|
|
||||||
|
|
||||||
def test_quota_show_with_default(self):
|
def test_quota_show_with_default(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
@ -347,8 +396,9 @@ class TestQuotaShow(TestQuota):
|
|||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.quotas_mock.defaults.assert_called_with(identity_fakes.project_id)
|
self.quotas_mock.defaults.assert_called_once_with(
|
||||||
self.volume_quotas_mock.defaults.assert_called_with(
|
identity_fakes.project_id)
|
||||||
|
self.volume_quotas_mock.defaults.assert_called_once_with(
|
||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
|
|
||||||
def test_quota_show_with_class(self):
|
def test_quota_show_with_class(self):
|
||||||
@ -365,9 +415,9 @@ class TestQuotaShow(TestQuota):
|
|||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.quotas_class_mock.get.assert_called_with(
|
self.quotas_class_mock.get.assert_called_once_with(
|
||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
self.volume_quotas_class_mock.get.assert_called_with(
|
self.volume_quotas_class_mock.get.assert_called_once_with(
|
||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
|
|
||||||
def test_quota_show_no_project(self):
|
def test_quota_show_no_project(self):
|
||||||
@ -375,7 +425,8 @@ class TestQuotaShow(TestQuota):
|
|||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.quotas_mock.get.assert_called_with(identity_fakes.project_id)
|
self.quotas_mock.get.assert_called_once_with(identity_fakes.project_id)
|
||||||
self.volume_quotas_mock.get.assert_called_with(
|
self.volume_quotas_mock.get.assert_called_once_with(
|
||||||
|
identity_fakes.project_id)
|
||||||
|
self.network.get_quota.assert_called_once_with(
|
||||||
identity_fakes.project_id)
|
identity_fakes.project_id)
|
||||||
self.network.get_quota.assert_called_with(identity_fakes.project_id)
|
|
||||||
|
@ -25,6 +25,19 @@ from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
|||||||
from openstackclient.tests.unit import utils
|
from openstackclient.tests.unit import utils
|
||||||
|
|
||||||
|
|
||||||
|
QUOTA = {
|
||||||
|
"gigabytes": 1000,
|
||||||
|
"volumes": 11,
|
||||||
|
"snapshots": 10,
|
||||||
|
"backups": 10,
|
||||||
|
"backup_gigabytes": 1000,
|
||||||
|
"per_volume_gigabytes": -1,
|
||||||
|
"gigabytes_volume_type_backend": -1,
|
||||||
|
"volumes_volume_type_backend": -1,
|
||||||
|
"snapshots_volume_type_backend": -1,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class FakeTransfer(object):
|
class FakeTransfer(object):
|
||||||
"""Fake one or more Transfer."""
|
"""Fake one or more Transfer."""
|
||||||
|
|
||||||
@ -207,6 +220,10 @@ class FakeVolumeClient(object):
|
|||||||
self.transfers.resource_class = fakes.FakeResource(None, {})
|
self.transfers.resource_class = fakes.FakeResource(None, {})
|
||||||
self.services = mock.Mock()
|
self.services = mock.Mock()
|
||||||
self.services.resource_class = fakes.FakeResource(None, {})
|
self.services.resource_class = fakes.FakeResource(None, {})
|
||||||
|
self.quotas = mock.Mock()
|
||||||
|
self.quotas.resource_class = fakes.FakeResource(None, {})
|
||||||
|
self.quota_classes = mock.Mock()
|
||||||
|
self.quota_classes.resource_class = fakes.FakeResource(None, {})
|
||||||
self.auth_token = kwargs['token']
|
self.auth_token = kwargs['token']
|
||||||
self.management_url = kwargs['endpoint']
|
self.management_url = kwargs['endpoint']
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user