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
This commit is contained in:
Kieran Spear 2020-05-15 11:22:57 +10:00
parent ed11d5bb2f
commit 84355d453c
2 changed files with 19 additions and 3 deletions

View File

@ -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"

View File

@ -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]