Let KeystoneCredentials.to_dict() method to return a dictionary.

Change-Id: I6246cf455af8b34ad86831e614340c031428d188
changes/41/668941/3
Federico Ressi 4 years ago
parent 9e36e39c17
commit e6b794aadd

@ -60,10 +60,9 @@ class KeystoneCredentials(collections.namedtuple(
'trust_id'])):
def to_dict(self):
return collections.OrderedDict(
(k, v)
for k, v in self._asdict().items()
if v is not None)
return {k: v
for k, v in self._asdict().items()
if v is not None}
def __repr__(self):
params = self.to_dict()
@ -71,7 +70,7 @@ class KeystoneCredentials(collections.namedtuple(
params['password'] = '***'
return 'keystone_credentials({!s})'.format(
", ".join("{!s}={!r}".format(k, v)
for k, v in params.items()))
for k, v in sorted(params.items())))
required_params = ('auth_url', 'username', 'password', 'project_name')

@ -77,9 +77,12 @@ class KeystoneCredentialsTest(openstack.OpenstackTest):
credentials.validate()
self.assertEqual(V2_PARAMS, credentials.to_dict())
self.assertEqual(
"keystone_credentials(api_version=2, "
"auth_url='http://10.0.0.1:5678/v2.0', username='demo', "
"password='***', project_name='demo')",
"keystone_credentials("
"api_version=2, "
"auth_url='http://10.0.0.1:5678/v2.0', "
"password='***', "
"project_name='demo', "
"username='demo')",
repr(credentials))
def test_validate_from_params_v3(self):
@ -87,11 +90,14 @@ class KeystoneCredentialsTest(openstack.OpenstackTest):
credentials.validate()
self.assertEqual(V3_PARAMS, credentials.to_dict())
self.assertEqual(
"keystone_credentials(api_version=3, "
"auth_url='http://10.0.0.1:5678/v3', username='demo', "
"password='***', project_name='demo', "
"keystone_credentials("
"api_version=3, "
"auth_url='http://10.0.0.1:5678/v3', "
"password='***', "
"project_domain_name='Default', "
"project_name='demo', "
"user_domain_name='Default', "
"project_domain_name='Default')",
"username='demo')",
repr(credentials))
def test_validate_without_auth_url(self):

Loading…
Cancel
Save