Add tests for AWSCloudProvider.create_environment_baseline
This commit is contained in:
parent
7bc5a418c9
commit
8b59546840
@ -48,3 +48,18 @@ def test_create_atat_admin_when_user_already_exists(mock_aws):
|
||||
|
||||
iam_client = mock_aws.boto3.client("iam")
|
||||
iam_client.get_user.assert_any_call(UserName="atat")
|
||||
|
||||
|
||||
def test_create_environment_baseline_succeeds(mock_aws):
|
||||
baseline_info = mock_aws.create_environment_baseline(
|
||||
AUTH_CREDENTIALS, "csp_environment_id"
|
||||
)
|
||||
assert {"policies": [{"BillingReadOnly": "policy-arn"}]} == baseline_info
|
||||
|
||||
|
||||
@pytest.mark.mock_boto3({"iam.create_policy.already_exists": True})
|
||||
def test_create_environment_baseline_when_policy_already_exists(mock_aws):
|
||||
baseline_info = mock_aws.create_environment_baseline(
|
||||
AUTH_CREDENTIALS, "csp_environment_id"
|
||||
)
|
||||
assert "policies" in baseline_info
|
||||
|
@ -54,6 +54,12 @@ def mock_boto_organizations(_config=None, **kwargs):
|
||||
|
||||
def mock_boto_iam(_config=None, **kwargs):
|
||||
user_already_exists = _config.get("iam.create_user.already_exists", False)
|
||||
policy_already_exists = _config.get("iam.create_policy.already_exists", False)
|
||||
|
||||
def _raise_entity_already_exists(**kwargs):
|
||||
raise real_iam_client.exceptions.EntityAlreadyExistsException(
|
||||
{"Error": {}}, "operation-name"
|
||||
)
|
||||
|
||||
import boto3
|
||||
|
||||
@ -66,13 +72,7 @@ def mock_boto_iam(_config=None, **kwargs):
|
||||
mock.put_user_policy = Mock(return_value={"ResponseMetadata": {}})
|
||||
|
||||
if user_already_exists:
|
||||
|
||||
def _raise(**kwargs):
|
||||
raise real_iam_client.exceptions.EntityAlreadyExistsException(
|
||||
{"Error": {}}, "operation-name"
|
||||
)
|
||||
|
||||
mock.create_user = Mock(side_effect=_raise)
|
||||
mock.create_user = Mock(side_effect=_raise_entity_already_exists)
|
||||
else:
|
||||
mock.create_user = Mock(
|
||||
return_value={
|
||||
@ -99,6 +99,11 @@ def mock_boto_iam(_config=None, **kwargs):
|
||||
}
|
||||
)
|
||||
|
||||
if policy_already_exists:
|
||||
mock.create_policy = Mock(side_effect=_raise_entity_already_exists)
|
||||
else:
|
||||
mock.create_policy = Mock(return_value={"Policy": {"Arn": "policy-arn"}})
|
||||
|
||||
return mock
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user