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

This commit is contained in:
Zuul 2019-07-04 11:17:24 +00:00 committed by Gerrit Code Review
commit 4989670e21
2 changed files with 17 additions and 12 deletions

View File

@ -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')

View File

@ -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):