Merge "Add EndpointData.__str__ for debugging"
This commit is contained in:
commit
44c8b50a55
@ -734,6 +734,16 @@ class EndpointData(object):
|
|||||||
new_data._saved_project_id = self._saved_project_id
|
new_data._saved_project_id = self._saved_project_id
|
||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Produce a string like EndpointData{key=val, ...}, for debugging."""
|
||||||
|
str_attrs = (
|
||||||
|
'api_version', 'catalog_url', 'endpoint_id', 'interface',
|
||||||
|
'major_version', 'max_microversion', 'min_microversion',
|
||||||
|
'next_min_version', 'not_before', 'raw_endpoint', 'region_name',
|
||||||
|
'service_id', 'service_name', 'service_type', 'service_url', 'url')
|
||||||
|
return "%s{%s}" % (self.__class__.__name__, ', '.join(
|
||||||
|
["%s=%s" % (attr, getattr(self, attr)) for attr in str_attrs]))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return self.service_url or self.catalog_url
|
return self.service_url or self.catalog_url
|
||||||
|
@ -1073,3 +1073,20 @@ class EndpointDataTests(utils.TestCase):
|
|||||||
mock_get_disc.assert_has_calls(
|
mock_get_disc.assert_has_calls(
|
||||||
[mock.call('sess', url, cache='cache', authenticated=False)
|
[mock.call('sess', url, cache='cache', authenticated=False)
|
||||||
for url in ('url1', 'url2', 'url3')])
|
for url in ('url1', 'url2', 'url3')])
|
||||||
|
|
||||||
|
def test_endpoint_data_str(self):
|
||||||
|
"""Validate EndpointData.__str__."""
|
||||||
|
# Populate a few fields to make sure they come through.
|
||||||
|
epd = discover.EndpointData(catalog_url='abc', service_type='123',
|
||||||
|
api_version=(2, 3))
|
||||||
|
exp = (
|
||||||
|
'EndpointData{api_version=(2, 3), catalog_url=abc,'
|
||||||
|
' endpoint_id=None, interface=None, major_version=None,'
|
||||||
|
' max_microversion=None, min_microversion=None,'
|
||||||
|
' next_min_version=None, not_before=None, raw_endpoint=None,'
|
||||||
|
' region_name=None, service_id=None, service_name=None,'
|
||||||
|
' service_type=123, service_url=None, url=abc}')
|
||||||
|
# Works with str()
|
||||||
|
self.assertEqual(exp, str(epd))
|
||||||
|
# Works with implicit stringification
|
||||||
|
self.assertEqual(exp, "%s" % epd)
|
||||||
|
Loading…
Reference in New Issue
Block a user