Add EndpointData.__str__ for debugging
It is useful to be able to dump the contents of an EndpointData for debugging purposes. This change adds a __str__ method that joins up all the public attributes/properties. Change-Id: Ib8985f0fa48a613ab8fca7faffbdf60c19c7cd22
This commit is contained in:
parent
f388eb9e23
commit
5ac9cde591
@ -735,6 +735,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
|
||||||
|
@ -949,3 +949,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