@@ -1524,6 +1524,60 @@ def test_single_account_single_role_device_code_fallback(
15241524 ],
15251525 )
15261526
1527+ def test_account_list_sorted_by_name (self ):
1528+ selected_account = {
1529+ 'accountId' : self .account_id ,
1530+ 'emailAddress' : 'account@example.com' ,
1531+ }
1532+ first_account = {
1533+ 'accountId' : '1111111111' ,
1534+ 'accountName' : 'alpha' ,
1535+ 'emailAddress' : 'alpha@example.com'
1536+ }
1537+ second_account = {
1538+ 'accountId' : '2222222222' ,
1539+ 'accountName' : 'Bravo' ,
1540+ 'emailAddress' : 'Bravo@example.com'
1541+ }
1542+ third_account = {
1543+ 'accountId' : '3333333333' ,
1544+ 'emailAddress' : 'charlie@example.com'
1545+ }
1546+ accounts = [selected_account , second_account ,
1547+ third_account , first_account ]
1548+ expected_accounts = [first_account ,
1549+ second_account , selected_account , third_account ]
1550+ self ._add_prompt_responses ()
1551+ self ._add_list_accounts_response (accounts )
1552+ self ._add_list_account_roles_response ([{'roleName' : self .role_name }])
1553+ self .selector .side_effect = [selected_account ]
1554+ with self .sso_stub :
1555+ self .configure_sso (args = [], parsed_globals = self .global_args )
1556+ printed_accounts = self .selector .call_args [0 ][0 ]
1557+ self .assertEqual (printed_accounts , expected_accounts )
1558+
1559+ def test_role_list_sorted_by_name (self ):
1560+ selected_account = {
1561+ 'accountId' : self .account_id ,
1562+ 'emailAddress' : 'account@example.com' ,
1563+ }
1564+ first_role = {'roleName' : 'AdministratorAccess' ,
1565+ 'accountId' : self .account_id }
1566+ second_role = {'roleName' : 'DataScientist' ,
1567+ 'accountId' : self .account_id }
1568+ third_role = {'roleName' : 'SystemAdministrator' ,
1569+ 'accountId' : self .account_id }
1570+ roles = [second_role , third_role , first_role ]
1571+ expected_roles = [first_role ['roleName' ],
1572+ second_role ['roleName' ], third_role ['roleName' ]]
1573+ self ._add_prompt_responses ()
1574+ self ._add_list_accounts_response ([selected_account ])
1575+ self ._add_list_account_roles_response (roles )
1576+ self .selector .side_effect = [selected_account ]
1577+ with self .sso_stub :
1578+ self .configure_sso (args = [], parsed_globals = self .global_args )
1579+ printed_roles = self .selector .call_args [0 ][0 ]
1580+ self .assertEqual (printed_roles , expected_roles )
15271581
15281582class TestPrintConclusion :
15291583 def test_print_conclusion_default_profile_with_credentials (
@@ -2059,65 +2113,12 @@ def passes_validator(validator, text):
20592113 (ScopesValidator , "value-1, value-2 value3" , None , False ),
20602114 ],
20612115)
2116+
2117+
20622118def test_validators (validator_cls , input_value , default , is_valid ):
20632119 validator = validator_cls (default )
20642120 assert passes_validator (validator , input_value ) == is_valid
20652121
2066- def test_account_list_sorted_by_name (self ):
2067- selected_account = {
2068- 'accountId' : self .account_id ,
2069- 'emailAddress' : 'account@example.com' ,
2070- }
2071- first_account = {
2072- 'accountId' : '1111111111' ,
2073- 'accountName' : 'alpha' ,
2074- 'emailAddress' : 'alpha@example.com'
2075- }
2076- second_account = {
2077- 'accountId' : '2222222222' ,
2078- 'accountName' : 'Bravo' ,
2079- 'emailAddress' : 'Bravo@example.com'
2080- }
2081- third_account = {
2082- 'accountId' : '3333333333' ,
2083- 'emailAddress' : 'charlie@example.com'
2084- }
2085- accounts = [selected_account , second_account ,
2086- third_account , first_account ]
2087- expected_accounts = [first_account ,
2088- second_account , selected_account , third_account ]
2089- self ._add_prompt_responses ()
2090- self ._add_list_accounts_response (accounts )
2091- self ._add_list_account_roles_response ([{'roleName' : self .role_name }])
2092- self .selector .side_effect = [selected_account ]
2093- with self .sso_stub :
2094- self .configure_sso (args = [], parsed_globals = self .global_args )
2095- printed_accounts = self .selector .call_args [0 ][0 ]
2096- self .assertEqual (printed_accounts , expected_accounts )
2097-
2098- def test_role_list_sorted_by_name (self ):
2099- selected_account = {
2100- 'accountId' : self .account_id ,
2101- 'emailAddress' : 'account@example.com' ,
2102- }
2103- first_role = {'roleName' : 'AdministratorAccess' ,
2104- 'accountId' : self .account_id }
2105- second_role = {'roleName' : 'DataScientist' ,
2106- 'accountId' : self .account_id }
2107- third_role = {'roleName' : 'SystemAdministrator' ,
2108- 'accountId' : self .account_id }
2109- roles = [second_role , third_role , first_role ]
2110- expected_roles = [first_role ['roleName' ],
2111- second_role ['roleName' ], third_role ['roleName' ]]
2112- self ._add_prompt_responses ()
2113- self ._add_list_accounts_response ([selected_account ])
2114- self ._add_list_account_roles_response (roles )
2115- self .selector .side_effect = [selected_account ]
2116- with self .sso_stub :
2117- self .configure_sso (args = [], parsed_globals = self .global_args )
2118- printed_roles = self .selector .call_args [0 ][0 ]
2119- self .assertEqual (printed_roles , expected_roles )
2120-
21212122
21222123class TestDisplayAccount (unittest .TestCase ):
21232124 def setUp (self ):
0 commit comments