2424 application_credential as _application_credential ,
2525)
2626from openstack .identity .v3 import role as _role
27+ from openstack .identity .v3 import user as _user
2728from openstack .test import fakes as sdk_fakes
2829from openstackclient .identity .v3 import application_credential
2930from openstackclient .tests .unit .identity .v3 import fakes as identity_fakes
@@ -325,6 +326,31 @@ def setUp(self):
325326 self .identity_sdk_client .application_credentials .return_value = [
326327 self .application_credential
327328 ]
329+ self .user = sdk_fakes .generate_fake_resource (resource_type = _user .User )
330+ self .identity_sdk_client .find_user .return_value = self .user
331+
332+ self .columns = (
333+ 'ID' ,
334+ 'Name' ,
335+ 'Description' ,
336+ 'Project ID' ,
337+ 'Roles' ,
338+ 'Unrestricted' ,
339+ 'Access Rules' ,
340+ 'Expires At' ,
341+ )
342+ self .data = (
343+ (
344+ self .application_credential .id ,
345+ self .application_credential .name ,
346+ self .application_credential .description ,
347+ self .application_credential .project_id ,
348+ '' ,
349+ self .application_credential .unrestricted ,
350+ self .application_credential .access_rules ,
351+ self .application_credential .expires_at ,
352+ ),
353+ )
328354
329355 # Get the command object to test
330356 self .cmd = application_credential .ListApplicationCredential (
@@ -339,39 +365,35 @@ def test_application_credential_list(self):
339365 conn = self .app .client_manager .sdk_connection
340366 user_id = conn .config .get_auth ().get_user_id (conn .identity )
341367
342- # In base command class Lister in cliff, abstract method take_action()
343- # returns a tuple containing the column names and an iterable
344- # containing the data to be listed.
345368 columns , data = self .cmd .take_action (parsed_args )
346369
370+ self .assertEqual (self .columns , columns )
371+ self .assertEqual (self .data , tuple (data ))
372+
373+ self .identity_sdk_client .find_user .assert_not_called ()
347374 self .identity_sdk_client .application_credentials .assert_called_with (
348375 user = user_id
349376 )
350377
351- collist = (
352- 'ID' ,
353- 'Name' ,
354- 'Description' ,
355- 'Project ID' ,
356- 'Roles' ,
357- 'Unrestricted' ,
358- 'Access Rules' ,
359- 'Expires At' ,
378+ def test_application_credential_list_user (self ):
379+ arglist = ['--user' , self .user .name ]
380+ verifylist = []
381+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
382+
383+ conn = self .app .client_manager .sdk_connection
384+ conn .config .get_auth ().get_user_id (conn .identity )
385+
386+ columns , data = self .cmd .take_action (parsed_args )
387+
388+ self .assertEqual (self .columns , columns )
389+ self .assertEqual (self .data , tuple (data ))
390+
391+ self .identity_sdk_client .find_user .assert_called_once_with (
392+ name_or_id = self .user .name , ignore_missing = False
360393 )
361- self .assertEqual (collist , columns )
362- datalist = (
363- (
364- self .application_credential .id ,
365- self .application_credential .name ,
366- self .application_credential .description ,
367- self .application_credential .project_id ,
368- self .application_credential .roles ,
369- self .application_credential .unrestricted ,
370- self .application_credential .access_rules ,
371- self .application_credential .expires_at ,
372- ),
394+ self .identity_sdk_client .application_credentials .assert_called_with (
395+ user = self .user .id
373396 )
374- self .assertEqual (datalist , tuple (data ))
375397
376398
377399class TestApplicationCredentialShow (identity_fakes .TestIdentityv3 ):
0 commit comments