def get_role(self): """ Prompt the user to choose a Role ARN if more than one is available """ if not self.all_roles: self.get_arns() if not self.all_roles: raise Exception("No roles found") # If I have more than one role, ask the user which one they want, # otherwise just proceed self.role_arn, self.principal_arn = user_role_prompt(self.all_roles)
def test_user_role_prompt(self): mock_stdout = StringIO() with patch('builtins.input', side_effect=['2']): with contextlib.redirect_stdout(mock_stdout): selected_role = user_role_prompt([ ('mock_role1', 'mock_principal_1'), ('mock_role2', 'mock_principal_2'), ('mock_role3', 'mock_principal_3') ]) self.assertEqual(('mock_role2', 'mock_principal_2'), selected_role) self.assertEqual("""[1] mock_role1 [2] mock_role2 [3] mock_role3 """, mock_stdout.getvalue())
def test_user_role_prompt_one_option(self): selected_role = user_role_prompt([ ('mock_role1', 'mock_principal_1'), ]) self.assertEqual(('mock_role1', 'mock_principal_1'), selected_role)