def test_deployment_account_found_with_ssm(logger, concur_mod_fn, wait_on_fn, ssm_client, org_client): account_id = "123456789012" given_account_id = "" account_name = "test-deployment-account" account_email = "*****@*****.**" cross_account_access_role_name = "some-role" ssm_client.exceptions.ParameterNotFound = ParameterNotFound org_client.exceptions.ConcurrentModificationException = \ ConcurrentModificationException ssm_client.get_parameter.return_value = { "Parameter": { "Value": account_id, } } returned_account_id, created = ensure_account( given_account_id, account_name, account_email, cross_account_access_role_name, ) assert returned_account_id != given_account_id assert returned_account_id == account_id assert not created logger.info.assert_not_called() concur_mod_fn.assert_not_called() wait_on_fn.assert_not_called() ssm_client.get_parameter.assert_called_once_with( Name="deployment_account_id", ) org_client.create_account.assert_not_called()
def test_deployment_account_create_failed_other(logger, concur_mod_fn, wait_on_fn, ssm_client, org_client): request_id = "random-request-id" account_id = "123456789012" given_account_id = "" account_name = "test-deployment-account" account_email = "*****@*****.**" cross_account_access_role_name = "some-role" correct_error_message = "Some other exception" ssm_client.exceptions.ParameterNotFound = ParameterNotFound org_client.exceptions.ConcurrentModificationException = \ ConcurrentModificationException ssm_client.get_parameter.side_effect = ParameterNotFound("Test") org_client.create_account.side_effect = \ OtherException(correct_error_message) with pytest.raises(OtherException) as excinfo: ensure_account( given_account_id, account_name, account_email, cross_account_access_role_name, ) error_message = str(excinfo.value) assert error_message.find(correct_error_message) >= 0 logger.info.assert_has_calls([ call("Creating account ..."), ]) concur_mod_fn.assert_not_called() wait_on_fn.assert_not_called() ssm_client.get_parameter.assert_called_once_with( Name="deployment_account_id", ) org_client.create_account.assert_called_once_with( Email=account_email, AccountName=account_name, RoleName=cross_account_access_role_name, IamUserAccessToBilling="ALLOW", )
def test_deployment_account_create_failed_concur(logger, concur_mod_fn, wait_on_fn, ssm_client, org_client): request_id = "random-request-id" account_id = "123456789012" given_account_id = "" account_name = "test-deployment-account" account_email = "*****@*****.**" cross_account_access_role_name = "some-role" ssm_client.exceptions.ParameterNotFound = ParameterNotFound org_client.exceptions.ConcurrentModificationException = \ ConcurrentModificationException ssm_client.get_parameter.side_effect = ParameterNotFound("Test") org_client.create_account.side_effect = ConcurrentModificationException( "Test", ) concur_mod_fn.return_value = (account_id, True) returned_account_id, created = ensure_account( given_account_id, account_name, account_email, cross_account_access_role_name, ) assert returned_account_id != given_account_id assert returned_account_id == account_id assert created logger.info.assert_has_calls([ call("Creating account ..."), ]) concur_mod_fn.assert_called_once_with( org_client.create_account.side_effect, given_account_id, account_name, account_email, cross_account_access_role_name, 1, ) wait_on_fn.assert_not_called() ssm_client.get_parameter.assert_called_once_with( Name="deployment_account_id", ) org_client.create_account.assert_called_once_with( Email=account_email, AccountName=account_name, RoleName=cross_account_access_role_name, IamUserAccessToBilling="ALLOW", )
def test_deployment_account_create_success(logger, concur_mod_fn, wait_on_fn, ssm_client, org_client): request_id = "random-request-id" account_id = "123456789012" given_account_id = "" account_name = "test-deployment-account" account_email = "*****@*****.**" cross_account_access_role_name = "some-role" ssm_client.exceptions.ParameterNotFound = ParameterNotFound org_client.exceptions.ConcurrentModificationException = \ ConcurrentModificationException ssm_client.get_parameter.side_effect = ParameterNotFound("Test") org_client.create_account.return_value = { 'CreateAccountStatus': { 'Id': request_id, } } wait_on_fn.return_value = (account_id, True) returned_account_id, created = ensure_account( given_account_id, account_name, account_email, cross_account_access_role_name, ) assert returned_account_id != given_account_id assert returned_account_id == account_id assert created logger.info.assert_has_calls([ call("Creating account ..."), call("Account creation requested, request ID: %s", request_id), ]) concur_mod_fn.assert_not_called() wait_on_fn.assert_called_once_with(request_id) ssm_client.get_parameter.assert_called_once_with( Name="deployment_account_id", ) org_client.create_account.assert_called_once_with( Email=account_email, AccountName=account_name, RoleName=cross_account_access_role_name, IamUserAccessToBilling="ALLOW", )
def test_deployment_account_given(logger, concur_mod_fn, wait_on_fn, ssm_client, org_client): account_id = "123456789012" account_name = "test-deployment-account" account_email = "*****@*****.**" cross_account_access_role_name = "some-role" ssm_client.exceptions.ParameterNotFound = ParameterNotFound org_client.exceptions.ConcurrentModificationException = \ ConcurrentModificationException returned_account_id, created = ensure_account( account_id, account_name, account_email, cross_account_access_role_name, ) assert returned_account_id == account_id assert not created logger.info.assert_not_called() concur_mod_fn.assert_not_called() wait_on_fn.assert_not_called() ssm_client.get_parameter.assert_not_called() org_client.create_account.assert_not_called()