From 84355d453ca5afc789b2a096241a932b2fd8d5a0 Mon Sep 17 00:00:00 2001 From: Kieran Spear Date: Fri, 15 May 2020 11:22:57 +1000 Subject: [PATCH] Fix display of application credential roles On the application credentials index page the roles are displayed as a python list: "[b'_member']". This changes that to be properly comma-separated. Closes-bug: #1878741 Change-Id: Idfbba05091b563957162b6cb58c2475f9594b0c2 --- .../identity/application_credentials/tables.py | 7 ++++--- .../identity/application_credentials/tests.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/openstack_dashboard/dashboards/identity/application_credentials/tables.py b/openstack_dashboard/dashboards/identity/application_credentials/tables.py index b2ea49be81..27eae86d9b 100644 --- a/openstack_dashboard/dashboards/identity/application_credentials/tables.py +++ b/openstack_dashboard/dashboards/identity/application_credentials/tables.py @@ -59,8 +59,9 @@ class ApplicationCredentialFilterAction(tables.FilterAction): filter_choices = (("name", _("Application Credential Name ="), True)) -def _role_names(obj): - return [role['name'].encode('utf-8') for role in obj.roles] +def _render_roles(obj): + names = [role['name'] for role in obj.roles] + return ', '.join(names) class ApplicationCredentialsTable(tables.DataTable): @@ -73,7 +74,7 @@ class ApplicationCredentialsTable(tables.DataTable): expires_at = tables.Column('expires_at', verbose_name=_('Expiration')) id = tables.Column('id', verbose_name=_('ID')) - roles = tables.Column(_role_names, verbose_name=_('Roles')) + roles = tables.Column(_render_roles, verbose_name=_('Roles')) class Meta(object): name = "application_credentials" diff --git a/openstack_dashboard/dashboards/identity/application_credentials/tests.py b/openstack_dashboard/dashboards/identity/application_credentials/tests.py index 496e6a2e9a..7eeda484f5 100644 --- a/openstack_dashboard/dashboards/identity/application_credentials/tests.py +++ b/openstack_dashboard/dashboards/identity/application_credentials/tests.py @@ -65,6 +65,21 @@ class ApplicationCredentialViewTests(test.TestCase): mock_app_cred_create.assert_called_once_with(test.IsHttpRequest(), **api_data) + @mock.patch.object(api.keystone, 'application_credential_list') + def test_application_credential_detail_list(self, mock_app_cred_list): + app_creds = self.application_credentials.list() + mock_app_cred_list.return_value = app_creds + + res = self.client.get( + reverse('horizon:identity:application_credentials:index')) + + self.assertTemplateUsed( + res, 'identity/application_credentials/index.html') + self.assertListEqual(res.context['table'].data, app_creds) + self.assertContains(res, 'Member, admin') + mock_app_cred_list.assert_called_once_with(test.IsHttpRequest(), + filters={}) + @mock.patch.object(api.keystone, 'application_credential_get') def test_application_credential_detail_get(self, mock_app_cred_get): app_cred = self.application_credentials.list()[1]