Refactor quota related unit tests
openstack_dashboard/dashboards/project/floating_ips/tests.py: The floating IP panel implementation calls openstack_dashboard.usage.quotas.tenant_quota_usages, but its unit test mocks functions called inside tenant_quota_usages. tenant_quota_usages itself should be mocked. openstack_dashboard/test/unit/usage/test_quotas.py: Mocked methods were not verified test_tenant_quota_usages_non_legacy. Verifications for called methods are added. Mocking floating_ip_supported is dropped as it is not called and there is no need to mock it. Change-Id: Iad66c882738fd90eb6dd6de3df96459c10a29aa2
This commit is contained in:
parent
abcbb0dea8
commit
b89c705164
@ -351,19 +351,13 @@ class FloatingIpViewTests(test.TestCase):
|
||||
)
|
||||
|
||||
@test.create_mocks({api.neutron: ('floating_ip_pools_list',
|
||||
'tenant_floating_ip_list',
|
||||
'is_extension_supported',
|
||||
'is_router_enabled',
|
||||
'tenant_quota_get'),
|
||||
api.base: ('is_service_enabled',)})
|
||||
'is_extension_supported'),
|
||||
quotas: ('tenant_quota_usages',)})
|
||||
@test.update_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
|
||||
def test_correct_quotas_displayed(self):
|
||||
self.mock_is_service_enabled.return_value = True
|
||||
self.mock_is_extension_supported.side_effect = [False, True, False]
|
||||
self.mock_is_router_enabled.return_value = True
|
||||
self.mock_tenant_quota_get.return_value = self.neutron_quotas.first()
|
||||
self.mock_tenant_floating_ip_list.return_value = \
|
||||
self.floating_ips.list()
|
||||
self.mock_tenant_quota_usages.return_value = \
|
||||
self.neutron_quota_usages.first()
|
||||
self.mock_floating_ip_pools_list.return_value = self.pools.list()
|
||||
|
||||
url = reverse('%s:allocate' % NAMESPACE)
|
||||
@ -371,19 +365,9 @@ class FloatingIpViewTests(test.TestCase):
|
||||
self.assertEqual(res.context['usages']['floatingip']['quota'],
|
||||
self.neutron_quotas.first().get('floatingip').limit)
|
||||
|
||||
self.mock_is_service_enabled.assert_called_once_with(
|
||||
test.IsHttpRequest(), 'network')
|
||||
self.assertEqual(3, self.mock_is_extension_supported.call_count)
|
||||
self.mock_is_extension_supported.assert_has_calls([
|
||||
mock.call(test.IsHttpRequest(), 'dns-integration'),
|
||||
mock.call(test.IsHttpRequest(), 'quotas'),
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
])
|
||||
self.mock_is_router_enabled.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_tenant_quota_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), self.tenant.id)
|
||||
self.mock_tenant_floating_ip_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_is_extension_supported.assert_called_once_with(
|
||||
test.IsHttpRequest(), 'dns-integration')
|
||||
self.mock_tenant_quota_usages.assert_called_once_with(
|
||||
test.IsHttpRequest(), targets=('floatingip',))
|
||||
self.mock_floating_ip_pools_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
|
@ -461,13 +461,13 @@ class QuotaTests(test.APITestCase):
|
||||
# quotas._get_tenant_network_usages)
|
||||
@test.create_mocks({api.base: ('is_service_enabled',),
|
||||
cinder: ('is_volume_service_enabled',),
|
||||
api.neutron: ('floating_ip_supported',
|
||||
'is_extension_supported',
|
||||
api.neutron: ('is_extension_supported',
|
||||
'is_quotas_extension_supported',
|
||||
'tenant_quota_detail_get')})
|
||||
def test_tenant_quota_usages_non_legacy(self):
|
||||
self._mock_service_enabled(network_enabled=True)
|
||||
self.mock_is_extension_supported.return_value = True
|
||||
self.mock_is_quotas_extension_supported.return_value = True
|
||||
|
||||
test_data = [
|
||||
("network", self.networks.list(), 10),
|
||||
@ -510,6 +510,39 @@ class QuotaTests(test.APITestCase):
|
||||
self.assertAvailableQuotasEqual(expected, quota_usages.usages,
|
||||
msg=msg)
|
||||
|
||||
self.assert_mock_multiple_calls_with_same_arguments(
|
||||
self.mock_is_service_enabled, len(test_data),
|
||||
mock.call(test.IsHttpRequest(), 'network'))
|
||||
# NOTE: is_volume_service_enabled() needs to be mocked
|
||||
# as _mock_service_enabled() requires it, but it is never called here.
|
||||
self.mock_is_volume_service_enabled.assert_not_called()
|
||||
self.mock_is_extension_supported.assert_has_calls([
|
||||
# network
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
# subnet
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
# port
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
# router
|
||||
mock.call(test.IsHttpRequest(), 'router'),
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
# floating IP
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
# security group
|
||||
mock.call(test.IsHttpRequest(), 'security-group'),
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
# security group rule
|
||||
mock.call(test.IsHttpRequest(), 'security-group'),
|
||||
mock.call(test.IsHttpRequest(), 'quota_details'),
|
||||
])
|
||||
self.assertEqual(10, self.mock_is_extension_supported.call_count)
|
||||
self.assert_mock_multiple_calls_with_same_arguments(
|
||||
self.mock_is_quotas_extension_supported, len(test_data),
|
||||
mock.call(test.IsHttpRequest()))
|
||||
self.assert_mock_multiple_calls_with_same_arguments(
|
||||
self.mock_tenant_quota_detail_get, len(test_data),
|
||||
mock.call(test.IsHttpRequest(), self.request.user.tenant_id))
|
||||
|
||||
@test.create_mocks({api.base: ('is_service_enabled',),
|
||||
cinder: ('is_volume_service_enabled',),
|
||||
api.neutron: ('floating_ip_supported',
|
||||
|
Loading…
Reference in New Issue
Block a user