From e6b794aadd9d7a8bf3e14066ce7a3347efc0f2fb Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 3 Jul 2019 17:53:31 +0200 Subject: [PATCH] Let KeystoneCredentials.to_dict() method to return a dictionary. Change-Id: I6246cf455af8b34ad86831e614340c031428d188 --- tobiko/openstack/keystone/_credentials.py | 9 ++++----- .../openstack/keystone/test_credentials.py | 20 ++++++++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/tobiko/openstack/keystone/_credentials.py b/tobiko/openstack/keystone/_credentials.py index fe36e4880..5f65b2552 100644 --- a/tobiko/openstack/keystone/_credentials.py +++ b/tobiko/openstack/keystone/_credentials.py @@ -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') diff --git a/tobiko/tests/unit/openstack/keystone/test_credentials.py b/tobiko/tests/unit/openstack/keystone/test_credentials.py index 649acb4fe..05dc7ecda 100644 --- a/tobiko/tests/unit/openstack/keystone/test_credentials.py +++ b/tobiko/tests/unit/openstack/keystone/test_credentials.py @@ -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):