improve unstable unit tests and fix whitespace
The unstable unit tests affected by list order were fixed by comparing the sorted region lists. Additionally, a whitespace fix was implemented. Change-Id: I2c67f7405a3f533d25111d7c3920ca31380de35a
This commit is contained in:
parent
d94662f374
commit
5bfac0a352
|
@ -372,7 +372,7 @@ options:
|
||||||
value will be capped to 4 workers unless this configuration option
|
value will be capped to 4 workers unless this configuration option
|
||||||
is set.
|
is set.
|
||||||
api-result-limit:
|
api-result-limit:
|
||||||
type: int
|
type: int
|
||||||
default:
|
default:
|
||||||
description: |
|
description: |
|
||||||
The maximum number of objects (e.g. Swift objects or Glance images) to
|
The maximum number of objects (e.g. Swift objects or Glance images) to
|
||||||
|
|
|
@ -19,6 +19,7 @@ from mock import MagicMock, patch
|
||||||
import hooks.horizon_contexts as horizon_contexts
|
import hooks.horizon_contexts as horizon_contexts
|
||||||
|
|
||||||
from unit_tests.test_utils import CharmTestCase
|
from unit_tests.test_utils import CharmTestCase
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
TO_PATCH = [
|
TO_PATCH = [
|
||||||
'config',
|
'config',
|
||||||
|
@ -52,6 +53,19 @@ def patch_open():
|
||||||
yield mock_open, mock_file
|
yield mock_open, mock_file
|
||||||
|
|
||||||
|
|
||||||
|
def with_regions_sorted(identity_service_context, by='title'):
|
||||||
|
"""Helper method to sort regions in Identity Service Context response.
|
||||||
|
|
||||||
|
:param identity_service_context: callable identity service context
|
||||||
|
:param by: regions sorting field name
|
||||||
|
|
||||||
|
:returns: identity service context with sorted regions
|
||||||
|
"""
|
||||||
|
value = identity_service_context()
|
||||||
|
value['regions'] = sorted(value['regions'], key=itemgetter(by))
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class TestHorizonContexts(CharmTestCase):
|
class TestHorizonContexts(CharmTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -784,19 +798,20 @@ class TestHorizonContexts(CharmTestCase):
|
||||||
'internal_host': 'bar', 'internal_port': 5001,
|
'internal_host': 'bar', 'internal_port': 5001,
|
||||||
'region': 'regionOne regionTwo'})
|
'region': 'regionOne regionTwo'})
|
||||||
self.context_complete.return_value = True
|
self.context_complete.return_value = True
|
||||||
self.assertEqual(horizon_contexts.IdentityServiceContext()(),
|
self.assertEqual(
|
||||||
{'service_host': 'foo', 'service_port': 5000,
|
with_regions_sorted(horizon_contexts.IdentityServiceContext()),
|
||||||
'service_protocol': 'http', 'api_version': '2',
|
{'service_host': 'foo', 'service_port': 5000,
|
||||||
'internal_host': 'bar', 'internal_port': 5001,
|
'service_protocol': 'http', 'api_version': '2',
|
||||||
'internal_protocol': 'http',
|
'internal_host': 'bar', 'internal_port': 5001,
|
||||||
'ks_host': 'foo', 'ks_port': 5000,
|
'internal_protocol': 'http',
|
||||||
'ks_protocol': 'http',
|
'ks_host': 'foo', 'ks_port': 5000,
|
||||||
'ks_endpoint_path': 'v2.0',
|
'ks_protocol': 'http',
|
||||||
'default_role': 'member',
|
'ks_endpoint_path': 'v2.0',
|
||||||
'regions': [{'endpoint': 'http://foo:5000/v2.0',
|
'default_role': 'member',
|
||||||
'title': 'regionOne'},
|
'regions': [{'endpoint': 'http://foo:5000/v2.0',
|
||||||
{'endpoint': 'http://foo:5000/v2.0',
|
'title': 'regionOne'},
|
||||||
'title': 'regionTwo'}]})
|
{'endpoint': 'http://foo:5000/v2.0',
|
||||||
|
'title': 'regionTwo'}]})
|
||||||
|
|
||||||
@patch("hooks.horizon_contexts.format_ipv6_addr")
|
@patch("hooks.horizon_contexts.format_ipv6_addr")
|
||||||
def test_IdentityServiceContext_multi_region_v3(self,
|
def test_IdentityServiceContext_multi_region_v3(self,
|
||||||
|
@ -811,20 +826,21 @@ class TestHorizonContexts(CharmTestCase):
|
||||||
'api_version': '3',
|
'api_version': '3',
|
||||||
'admin_domain_id': 'admindomainid'})
|
'admin_domain_id': 'admindomainid'})
|
||||||
self.context_complete.return_value = True
|
self.context_complete.return_value = True
|
||||||
self.assertEqual(horizon_contexts.IdentityServiceContext()(),
|
self.assertEqual(
|
||||||
{'admin_domain_id': 'admindomainid',
|
with_regions_sorted(horizon_contexts.IdentityServiceContext()),
|
||||||
'service_host': 'foo', 'service_port': 5000,
|
{'admin_domain_id': 'admindomainid',
|
||||||
'service_protocol': 'http', 'api_version': '3',
|
'service_host': 'foo', 'service_port': 5000,
|
||||||
'internal_host': 'bar', 'internal_port': 5001,
|
'service_protocol': 'http', 'api_version': '3',
|
||||||
'internal_protocol': 'http',
|
'internal_host': 'bar', 'internal_port': 5001,
|
||||||
'ks_host': 'foo', 'ks_port': 5000,
|
'internal_protocol': 'http',
|
||||||
'ks_protocol': 'http',
|
'ks_host': 'foo', 'ks_port': 5000,
|
||||||
'ks_endpoint_path': 'v3',
|
'ks_protocol': 'http',
|
||||||
'default_role': 'member',
|
'ks_endpoint_path': 'v3',
|
||||||
'regions': [{'endpoint': 'http://foo:5000/v3',
|
'default_role': 'member',
|
||||||
'title': 'regionOne'},
|
'regions': [{'endpoint': 'http://foo:5000/v3',
|
||||||
{'endpoint': 'http://foo:5000/v3',
|
'title': 'regionOne'},
|
||||||
'title': 'regionTwo'}]})
|
{'endpoint': 'http://foo:5000/v3',
|
||||||
|
'title': 'regionTwo'}]})
|
||||||
|
|
||||||
@patch("hooks.horizon_contexts.format_ipv6_addr")
|
@patch("hooks.horizon_contexts.format_ipv6_addr")
|
||||||
def test_IdentityServiceContext_api3(self, mock_format_ipv6_addr):
|
def test_IdentityServiceContext_api3(self, mock_format_ipv6_addr):
|
||||||
|
@ -983,20 +999,21 @@ class TestHorizonContexts(CharmTestCase):
|
||||||
self.test_config.set('use-internal-endpoints', True)
|
self.test_config.set('use-internal-endpoints', True)
|
||||||
self.context_complete.return_value = True
|
self.context_complete.return_value = True
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
self.assertEqual(horizon_contexts.IdentityServiceContext()(),
|
self.assertEqual(
|
||||||
{'service_host': 'foo', 'service_port': 5000,
|
with_regions_sorted(horizon_contexts.IdentityServiceContext()),
|
||||||
'service_protocol': 'http',
|
{'service_host': 'foo', 'service_port': 5000,
|
||||||
'internal_host': None, 'internal_port': None,
|
'service_protocol': 'http',
|
||||||
'internal_protocol': 'http',
|
'internal_host': None, 'internal_port': None,
|
||||||
'ks_host': 'foo', 'ks_port': 5000,
|
'internal_protocol': 'http',
|
||||||
'ks_endpoint_path': 'v2.0',
|
'ks_host': 'foo', 'ks_port': 5000,
|
||||||
'ks_protocol': 'http',
|
'ks_endpoint_path': 'v2.0',
|
||||||
'api_version': '2',
|
'ks_protocol': 'http',
|
||||||
'default_role': 'member',
|
'api_version': '2',
|
||||||
'regions': [{'endpoint': 'http://foo:5000/v2.0',
|
'default_role': 'member',
|
||||||
'title': 'regionOne'},
|
'regions': [{'endpoint': 'http://foo:5000/v2.0',
|
||||||
{'endpoint': 'http://foo:5000/v2.0',
|
'title': 'regionOne'},
|
||||||
'title': 'regionTwo'}]})
|
{'endpoint': 'http://foo:5000/v2.0',
|
||||||
|
'title': 'regionTwo'}]})
|
||||||
|
|
||||||
def test_HorizonHAProxyContext_no_cluster(self):
|
def test_HorizonHAProxyContext_no_cluster(self):
|
||||||
self.relation_ids.return_value = []
|
self.relation_ids.return_value = []
|
||||||
|
|
Loading…
Reference in New Issue