How to use list_account_aliases method in localstack

Best Python code snippet using localstack_python

test_account_alias.py

Source:test_account_alias.py Github

copy

Full Screen

1"""2Tests the account alias configuration lambda3"""4import unittest5import boto36from botocore.stub import Stubber7from botocore.exceptions import ClientError8from mock import Mock9from aws_xray_sdk import global_sdk_config10from ..configure_account_alias import (11 create_account_alias,12 ensure_account_has_alias,13)14global_sdk_config.set_sdk_enabled(False)15class SuccessTestCase(unittest.TestCase):16 @staticmethod17 def test_account_alias_exists_already():18 test_account = {"account_id": 123456789012, "alias": "MyCoolAlias"}19 iam_client = Mock()20 iam_client.list_account_aliases.return_value = {21 "AccountAliases": ["MyCoolAlias"],22 }23 ensure_account_has_alias(test_account, iam_client)24 iam_client.list_account_aliases.assert_called_once_with()25 iam_client.delete_account_alias.assert_not_called()26 iam_client.create_account_alias.assert_not_called()27 @staticmethod28 def test_account_alias_another_alias_exists():29 test_account = {"account_id": 123456789012, "alias": "MyCoolAlias"}30 iam_client = Mock()31 iam_client.list_account_aliases.return_value = {32 "AccountAliases": ["AnotherCoolAlias"],33 }34 ensure_account_has_alias(test_account, iam_client)35 iam_client.list_account_aliases.assert_called_once_with()36 iam_client.delete_account_alias.assert_called_once_with(37 AccountAlias='AnotherCoolAlias',38 )39 iam_client.create_account_alias.assert_called_once_with(40 AccountAlias='MyCoolAlias',41 )42 @staticmethod43 def test_account_alias_no_aliases_yet():44 test_account = {"account_id": 123456789012, "alias": "MyCoolAlias"}45 iam_client = Mock()46 iam_client.list_account_aliases.return_value = {47 "AccountAliases": [],48 }49 ensure_account_has_alias(test_account, iam_client)50 iam_client.list_account_aliases.assert_called_once_with()51 iam_client.delete_account_alias.assert_not_called()52 iam_client.create_account_alias.assert_called_once_with(53 AccountAlias='MyCoolAlias',54 )55class FailureTestCase(unittest.TestCase):56 # pylint: disable=W010657 def test_account_alias_when_nonunique(self):58 test_account = {"account_id": 123456789012, "alias": "nonunique"}59 iam_client = boto3.client("iam")60 stubber = Stubber(iam_client)61 stubber.add_client_error(62 'create_account_alias',63 'EntityAlreadyExistsException',64 f"An error occurred (EntityAlreadyExists) when calling the CreateAccountAlias operation: The account alias {test_account.get('alias')} already exists."65 )66 stubber.activate()67 with self.assertRaises(ClientError) as _error:68 create_account_alias(test_account, iam_client)69 self.assertRegex(70 str(_error.exception),71 r'.*The account alias nonunique already exists.*'...

Full Screen

Full Screen

list_account_aliases.py

Source:list_account_aliases.py Github

copy

Full Screen

1# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License. 13# snippet-start:[iam.python.list_account_aliases.complete]14import boto31516# Create IAM client17iam = boto3.client('iam')1819# List account aliases through the pagination interface20paginator = iam.get_paginator('list_account_aliases')21for response in paginator.paginate():22 print(response['AccountAliases'])2324# snippet-end:[iam.python.list_account_aliases.complete]25# snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]26# snippet-sourcedescription:[list_account_aliases.py demonstrates how to list your IAM account aliases.]27# snippet-keyword:[Python]28# snippet-keyword:[AWS SDK for Python (Boto3)]29# snippet-keyword:[Code Sample]30# snippet-keyword:[AWS Identity and Access Management (IAM)]31# snippet-service:[iam]32# snippet-sourcetype:[full-example]33# snippet-sourcedate:[2018-12-26] ...

Full Screen

Full Screen

test_iam_account_aliases.py

Source:test_iam_account_aliases.py Github

copy

Full Screen

...4@mock_iam()5def test_account_aliases():6 client = boto3.client("iam", region_name="us-east-1")7 alias = "my-account-name"8 aliases = client.list_account_aliases()9 aliases.should.have.key("AccountAliases").which.should.equal([])10 client.create_account_alias(AccountAlias=alias)11 aliases = client.list_account_aliases()12 aliases.should.have.key("AccountAliases").which.should.equal([alias])13 client.delete_account_alias(AccountAlias=alias)14 aliases = client.list_account_aliases()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful