Techdebt: Replace sure with regular assertions in RAM (#6681)
This commit is contained in:
parent
a6f140ddab
commit
a36d8fcba4
@ -1,8 +1,8 @@
|
||||
import re
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
import boto3
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
@ -20,16 +20,20 @@ def test_create_resource_share():
|
||||
|
||||
# then
|
||||
resource = response["resourceShare"]
|
||||
resource["allowExternalPrincipals"].should.be.ok
|
||||
resource["creationTime"].should.be.a(datetime)
|
||||
resource["lastUpdatedTime"].should.be.a(datetime)
|
||||
resource["name"].should.equal("test")
|
||||
resource["owningAccountId"].should.equal(ACCOUNT_ID)
|
||||
resource["resourceShareArn"].should.match(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
assert resource["allowExternalPrincipals"] is True
|
||||
assert isinstance(resource["creationTime"], datetime)
|
||||
assert isinstance(resource["lastUpdatedTime"], datetime)
|
||||
assert resource["name"] == "test"
|
||||
assert resource["owningAccountId"] == ACCOUNT_ID
|
||||
assert re.match(
|
||||
(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share"
|
||||
r"/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
),
|
||||
resource["resourceShareArn"],
|
||||
)
|
||||
resource["status"].should.equal("ACTIVE")
|
||||
resource.should_not.have.key("featureSet")
|
||||
assert resource["status"] == "ACTIVE"
|
||||
assert "featureSet" not in resource
|
||||
|
||||
# creating a resource share with the name should result in a second one
|
||||
# not overwrite/update the old one
|
||||
@ -44,18 +48,22 @@ def test_create_resource_share():
|
||||
|
||||
# then
|
||||
resource = response["resourceShare"]
|
||||
resource["allowExternalPrincipals"].should_not.be.ok
|
||||
resource["creationTime"].should.be.a(datetime)
|
||||
resource["lastUpdatedTime"].should.be.a(datetime)
|
||||
resource["name"].should.equal("test")
|
||||
resource["owningAccountId"].should.equal(ACCOUNT_ID)
|
||||
resource["resourceShareArn"].should.match(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
assert resource["allowExternalPrincipals"] is False
|
||||
assert isinstance(resource["creationTime"], datetime)
|
||||
assert isinstance(resource["lastUpdatedTime"], datetime)
|
||||
assert resource["name"] == "test"
|
||||
assert resource["owningAccountId"] == ACCOUNT_ID
|
||||
assert re.match(
|
||||
(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share"
|
||||
r"/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
),
|
||||
resource["resourceShareArn"],
|
||||
)
|
||||
resource["status"].should.equal("ACTIVE")
|
||||
assert resource["status"] == "ACTIVE"
|
||||
|
||||
response = client.get_resource_shares(resourceOwner="SELF")
|
||||
response["resourceShares"].should.have.length_of(2)
|
||||
assert len(response["resourceShares"]) == 2
|
||||
|
||||
|
||||
@mock_ram
|
||||
@ -68,10 +76,10 @@ def test_create_resource_share_errors():
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.create_resource_share(name="test", resourceArns=["inalid-arn"])
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("CreateResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("MalformedArnException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
assert ex.operation_name == "CreateResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "MalformedArnException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
"The specified resource ARN inalid-arn is not valid. "
|
||||
"Verify the ARN and try again."
|
||||
)
|
||||
@ -83,11 +91,12 @@ def test_create_resource_share_errors():
|
||||
name="test", resourceArns=[f"arn:aws:iam::{ACCOUNT_ID}:role/test"]
|
||||
)
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("CreateResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("MalformedArnException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
"You cannot share the selected resource type."
|
||||
assert ex.operation_name == "CreateResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "MalformedArnException" in ex.response["Error"]["Code"]
|
||||
assert (
|
||||
ex.response["Error"]["Message"]
|
||||
== "You cannot share the selected resource type."
|
||||
)
|
||||
|
||||
# invalid principal ID
|
||||
@ -101,10 +110,10 @@ def test_create_resource_share_errors():
|
||||
],
|
||||
)
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("CreateResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("InvalidParameterException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
assert ex.operation_name == "CreateResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "InvalidParameterException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
"Principal ID invalid is malformed. Verify the ID and try again."
|
||||
)
|
||||
|
||||
@ -132,7 +141,7 @@ def test_create_resource_share_with_organization():
|
||||
)
|
||||
|
||||
# then
|
||||
response["resourceShare"]["name"].should.equal("test")
|
||||
assert response["resourceShare"]["name"] == "test"
|
||||
|
||||
# share in an OU
|
||||
# when
|
||||
@ -145,7 +154,7 @@ def test_create_resource_share_with_organization():
|
||||
)
|
||||
|
||||
# then
|
||||
response["resourceShare"]["name"].should.equal("test")
|
||||
assert response["resourceShare"]["name"] == "test"
|
||||
|
||||
|
||||
@mock_ram
|
||||
@ -169,10 +178,10 @@ def test_create_resource_share_with_organization_errors():
|
||||
],
|
||||
)
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("CreateResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("UnknownResourceException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
assert ex.operation_name == "CreateResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "UnknownResourceException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
"Organization o-unknown could not be found."
|
||||
)
|
||||
|
||||
@ -187,10 +196,10 @@ def test_create_resource_share_with_organization_errors():
|
||||
],
|
||||
)
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("CreateResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("UnknownResourceException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
assert ex.operation_name == "CreateResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "UnknownResourceException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
"OrganizationalUnit ou-unknown in unknown organization could not be found."
|
||||
)
|
||||
|
||||
@ -205,18 +214,22 @@ def test_get_resource_shares():
|
||||
response = client.get_resource_shares(resourceOwner="SELF")
|
||||
|
||||
# then
|
||||
response["resourceShares"].should.have.length_of(1)
|
||||
assert len(response["resourceShares"]) == 1
|
||||
resource = response["resourceShares"][0]
|
||||
resource["allowExternalPrincipals"].should.be.ok
|
||||
resource["creationTime"].should.be.a(datetime)
|
||||
resource["featureSet"].should.equal("STANDARD")
|
||||
resource["lastUpdatedTime"].should.be.a(datetime)
|
||||
resource["name"].should.equal("test")
|
||||
resource["owningAccountId"].should.equal(ACCOUNT_ID)
|
||||
resource["resourceShareArn"].should.match(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
assert resource["allowExternalPrincipals"] is True
|
||||
assert isinstance(resource["creationTime"], datetime)
|
||||
assert resource["featureSet"] == "STANDARD"
|
||||
assert isinstance(resource["lastUpdatedTime"], datetime)
|
||||
assert resource["name"] == "test"
|
||||
assert resource["owningAccountId"] == ACCOUNT_ID
|
||||
assert re.match(
|
||||
(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share"
|
||||
r"/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
),
|
||||
resource["resourceShareArn"],
|
||||
)
|
||||
resource["status"].should.equal("ACTIVE")
|
||||
assert resource["status"] == "ACTIVE"
|
||||
|
||||
|
||||
@mock_ram
|
||||
@ -229,10 +242,10 @@ def test_get_resource_shares_errors():
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.get_resource_shares(resourceOwner="invalid")
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("GetResourceShares")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("InvalidParameterException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
assert ex.operation_name == "GetResourceShares"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "InvalidParameterException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
"invalid is not a valid resource owner. "
|
||||
"Specify either SELF or OTHER-ACCOUNTS and try again."
|
||||
)
|
||||
@ -250,19 +263,23 @@ def test_update_resource_share():
|
||||
|
||||
# then
|
||||
resource = response["resourceShare"]
|
||||
resource["allowExternalPrincipals"].should.be.ok
|
||||
resource["name"].should.equal("test-update")
|
||||
resource["owningAccountId"].should.equal(ACCOUNT_ID)
|
||||
resource["resourceShareArn"].should.match(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
assert resource["allowExternalPrincipals"] is True
|
||||
assert resource["name"] == "test-update"
|
||||
assert resource["owningAccountId"] == ACCOUNT_ID
|
||||
assert re.match(
|
||||
(
|
||||
r"arn:aws:ram:us-east-1:\d{12}:resource-share"
|
||||
r"/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
),
|
||||
resource["resourceShareArn"],
|
||||
)
|
||||
resource["status"].should.equal("ACTIVE")
|
||||
resource.should_not.have.key("featureSet")
|
||||
assert resource["status"] == "ACTIVE"
|
||||
assert "featureSet" not in resource
|
||||
creation_time = resource["creationTime"]
|
||||
resource["lastUpdatedTime"].should.be.greater_than(creation_time)
|
||||
assert resource["lastUpdatedTime"] > creation_time
|
||||
|
||||
response = client.get_resource_shares(resourceOwner="SELF")
|
||||
response["resourceShares"].should.have.length_of(1)
|
||||
assert len(response["resourceShares"]) == 1
|
||||
|
||||
|
||||
@mock_ram
|
||||
@ -278,11 +295,12 @@ def test_update_resource_share_errors():
|
||||
name="test-update",
|
||||
)
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("UpdateResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("UnknownResourceException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
f"ResourceShare arn:aws:ram:us-east-1:{ACCOUNT_ID}:resource-share/not-existing could not be found."
|
||||
assert ex.operation_name == "UpdateResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "UnknownResourceException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
f"ResourceShare arn:aws:ram:us-east-1:{ACCOUNT_ID}"
|
||||
":resource-share/not-existing could not be found."
|
||||
)
|
||||
|
||||
|
||||
@ -297,14 +315,14 @@ def test_delete_resource_share():
|
||||
response = client.delete_resource_share(resourceShareArn=arn)
|
||||
|
||||
# then
|
||||
response["returnValue"].should.be.ok
|
||||
assert response["returnValue"] is True
|
||||
|
||||
response = client.get_resource_shares(resourceOwner="SELF")
|
||||
response["resourceShares"].should.have.length_of(1)
|
||||
assert len(response["resourceShares"]) == 1
|
||||
resource = response["resourceShares"][0]
|
||||
resource["status"].should.equal("DELETED")
|
||||
assert resource["status"] == "DELETED"
|
||||
creation_time = resource["creationTime"]
|
||||
resource["lastUpdatedTime"].should.be.greater_than(creation_time)
|
||||
assert resource["lastUpdatedTime"] > creation_time
|
||||
|
||||
|
||||
@mock_ram
|
||||
@ -319,11 +337,12 @@ def test_delete_resource_share_errors():
|
||||
resourceShareArn=f"arn:aws:ram:us-east-1:{ACCOUNT_ID}:resource-share/not-existing"
|
||||
)
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("DeleteResourceShare")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("UnknownResourceException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
f"ResourceShare arn:aws:ram:us-east-1:{ACCOUNT_ID}:resource-share/not-existing could not be found."
|
||||
assert ex.operation_name == "DeleteResourceShare"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "UnknownResourceException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
f"ResourceShare arn:aws:ram:us-east-1:{ACCOUNT_ID}"
|
||||
":resource-share/not-existing could not be found."
|
||||
)
|
||||
|
||||
|
||||
@ -339,7 +358,7 @@ def test_enable_sharing_with_aws_organization():
|
||||
response = client.enable_sharing_with_aws_organization()
|
||||
|
||||
# then
|
||||
response["returnValue"].should.be.ok
|
||||
assert response["returnValue"] is True
|
||||
|
||||
|
||||
@mock_ram
|
||||
@ -353,11 +372,12 @@ def test_enable_sharing_with_aws_organization_errors():
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.enable_sharing_with_aws_organization()
|
||||
ex = e.value
|
||||
ex.operation_name.should.equal("EnableSharingWithAwsOrganization")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("OperationNotPermittedException")
|
||||
ex.response["Error"]["Message"].should.equal(
|
||||
assert ex.operation_name == "EnableSharingWithAwsOrganization"
|
||||
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
assert "OperationNotPermittedException" in ex.response["Error"]["Code"]
|
||||
assert ex.response["Error"]["Message"] == (
|
||||
"Unable to enable sharing with AWS Organizations. "
|
||||
"Received AccessDeniedException from AWSOrganizations with the following error message: "
|
||||
"Received AccessDeniedException from AWSOrganizations with the "
|
||||
"following error message: "
|
||||
"You don't have permissions to access this resource."
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user