def test_configure_env(mock_config, mock_env, setup_function): # Make sure we start with an empty environment assert dict(os.environ) == {} # fake_boto3 still required here because mock_iam has not yet # implemented the list_account_aliases() method yet, which is used # in aws.configure(). with patch('deployer.aws.boto3', fake_boto3): session = boto3.Session(profile_name='veracode-random') s3client = session.client('s3') s3client.create_bucket(Bucket="123456789012-myproj-data") aws.configure(mock_config) returned_env = dict(os.environ) assert returned_env == mock_env return
def test_configure_config_with_tags_no_version(mock_config_with_tags): # Make sure we start with an empty environment (os.environ,_env) = clear_env() assert dict(os.environ) == {} mock_config_with_tags['environment'].pop('version') expected_config = { "aws_profile" : "tests-random", "aws_region" : "us-east-1", "availability_zones" : [ 'us-east-1a', 'us-east-1b', 'us-east-1c', 'us-east-1d', 'us-east-1e', 'us-east-1f' ], "account_id" : "123456789012", "environment" : { "name" : "myenvname" }, "aws_region" : "us-east-1", "tags" : { "key1" : "value1", "key2" : "value2", "env_name" : "myenvname" }, "env_name" : "myenvname", "env_folder" : "myenvname", "tf_state" : "myenvname.tfstate", "tf_state_bucket" :"123456789012-myproj-tfstate", "project_config" : "123456789012-myproj-data", "project" : 'myproj', "route53_tld" : "my.toplevel.domain" } # fake_boto3 still required here because mock_iam has not yet # implemented the list_account_aliases() method yet, which is used # in aws.configure(). os.environ['AWS_ACCESS_KEY_ID'] = 'foo' os.environ['AWS_SECRET_ACCESS_KEY'] = 'bar' mock = mock_s3() mock.start() s3client = boto3.client('s3') s3client.create_bucket(Bucket=expected_config['project_config']) s3client.create_bucket(Bucket=expected_config['tf_state_bucket']) # We need to create the bucket since this is all in Moto's 'virtual' # AWS account with patch('deployer.aws.boto3', fake_boto3): returned_config = aws.configure(mock_config_with_tags) assert returned_config == expected_config reset_env() return
def test_configure_config_with_tags(mock_config_with_tags, setup_function): # Make sure we start with an empty environment assert dict(os.environ) == {} expected_config = { "aws_profile" : "veracode-random", "aws_region" : "us-east-1", "availability_zones" : [ 'us-east-1a', 'us-east-1b', 'us-east-1c' ], "account_id" : "123456789012", "environment" : { "name" : "myenvname", "version" : "a", }, "aws_region" : "us-east-1", "tags" : { "key1" : "value1", "key2" : "value2", "env_name" : "myenvname", "env_version" : "a" }, "env_name" : "myenvname-a", "env_folder" : "myenvname-a", "tf_state" : "myenvname-a.tfstate", "tf_state_bucket" :"123456789012-myproj-tfstate", "project_config" : "123456789012-myproj-data", "project" : 'myproj', "route53_tld" : "my.toplevel.domain" } # fake_boto3 still required here because mock_iam has not yet # implemented the list_account_aliases() method yet, which is used # in aws.configure(). s3client = boto3.client('s3') s3client.create_bucket(Bucket=expected_config['project_config']) s3client.create_bucket(Bucket=expected_config['tf_state_bucket']) with patch('deployer.aws.boto3', fake_boto3): # We need to create the bucket since this is all in Moto's 'virtual' # AWS account returned_config = aws.configure(mock_config_with_tags) assert returned_config == expected_config return