def test_secure_ssm_parameter_create():
    lambda_custom_resource.create(event, context)

    response = ssm.get_parameter('/parameter/store/test/key')

    assert (response['Parameter']) is not None
    assert response['Parameter']['Name'] == '/parameter/store/test/key'
    assert response['Parameter']['Value'] == 'test-value'
    assert response['Parameter']['Type'] == 'SecureString'
def test_s3ConsoleDeploy_create():
    s3_conn = boto3.resource('s3')
    s3_conn.create_bucket(Bucket='ConsoleBucket')
    s3_conn.create_bucket(Bucket='SrcBucket')
    
    file_path = os.path.join(os.path.dirname(__file__), "console-manifest.json")
    if not os.path.exists(file_path):
        open(file_path, 'w')
     
    lambda_custom_resource.create(event, context)
def test_secure_ssm_parameter_delete():
    lambda_custom_resource.create(event, context)

    response = ssm.get_parameter('/parameter/store/test/key')
    assert (response['Parameter']) is not None

    lambda_custom_resource.delete(event, context)

    # testing the exception after the parameter is deleted and we try _get_ function
    try:
        ssm.get_parameter('/parameter/store/test/key')
        raise RuntimeError(
            'As this parameter has been deleted, this should fail')
    except botocore.exceptions.ClientError as err:
        assert err.operation_name == 'GetParameter'
def test_no_empty_string_in_prefix_list_arns():
    arn_list = create(event_with_extra_comma, context)
    logger.info(arn_list)
    empty_string = ''
    for arn in arn_list[1].get('PrefixListArns'):
        logger.info(arn)
        assert empty_string != arn.split('/')[1]
def test_create_empty_get_prefix_list_arns():
    with pytest.raises(ValueError, match=r"STNO CFN Parameter Missing: You must"
                                         r" provide at least one valid prefix "
                                         r"list id."):
        create(event_no_values, context)
def test_create_get_prefix_list_arns():
    arn_list = create(event, context)
    logger.info(arn_list)
    for arn in arn_list[1].get('PrefixListArns'):
        logger.info(arn)
        assert arn.startswith('arn:aws:ec2')
def test_update_replace_accounts_with_org_id():
    lambda_custom_resource.create(event_with_accounts, context)
    lambda_custom_resource.update(event_replace_accounts_with_org_id, context)
def test_update_remove_account_as_principal_from_both():
    lambda_custom_resource.create(event_with_org_arn_and_account, context)
    lambda_custom_resource.update(event_remove_accounts_from_org_id, context)
def test_update_add_account_as_principal_to_org_id():
    lambda_custom_resource.create(event_with_org_arn, context)
    lambda_custom_resource.update(event_add_accounts_to_org_id, context)
def test_update_same_account_as_principal():
    lambda_custom_resource.create(event_with_accounts, context)
    lambda_custom_resource.update(event_same_accounts, context)
def test_create_delete_both_as_principal():
    lambda_custom_resource.create(event_with_org_arn_and_account, context)
    lambda_custom_resource.delete(event_with_org_arn_and_account, context)
def test_create_delete_org_id_as_principal():
    lambda_custom_resource.create(event_with_org_arn, context)
    lambda_custom_resource.delete(event_with_org_arn, context)
def test_create_delete_account_as_principal():
    lambda_custom_resource.create(event_with_accounts, context)
    lambda_custom_resource.delete(event_with_accounts, context)