Introduce Pylint to check for duplicate test method names (#3684)

This commit is contained in:
Bert Blommers 2021-08-21 16:33:15 +01:00 committed by GitHub
parent 88c15d3bb8
commit 7acdfe4feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 49 additions and 406 deletions

View File

@ -15,6 +15,7 @@ init:
lint: lint:
flake8 moto flake8 moto
black --check moto/ tests/ black --check moto/ tests/
pylint -j 0 tests
format: format:
black moto/ tests/ black moto/ tests/

View File

@ -2,3 +2,4 @@ pytest
pytest-cov pytest-cov
sure==1.4.11 sure==1.4.11
freezegun freezegun
pylint

View File

@ -7,3 +7,8 @@ markers =
[coverage:run] [coverage:run]
relative_files = True relative_files = True
[pylint.'MESSAGES CONTROL']
disable = W,C,R,E
# Check we have any tests with duplicate names (causing them to be skipped)
enable = function-redefined

View File

@ -5,6 +5,7 @@ import json
import boto import boto
import boto3 import boto3
import boto.dynamodb2
import boto.iam import boto.iam
import boto.s3 import boto.s3
import boto.s3.key import boto.s3.key
@ -20,8 +21,7 @@ from moto import (
mock_s3_deprecated, mock_s3_deprecated,
mock_route53_deprecated, mock_route53_deprecated,
mock_iam_deprecated, mock_iam_deprecated,
mock_dynamodb2, mock_dynamodb2_deprecated,
mock_cloudformation,
) )
from moto.cloudformation import cloudformation_backends from moto.cloudformation import cloudformation_backends
@ -73,6 +73,7 @@ dummy_template4 = {
dummy_template_json = json.dumps(dummy_template) dummy_template_json = json.dumps(dummy_template)
dummy_template_json2 = json.dumps(dummy_template2) dummy_template_json2 = json.dumps(dummy_template2)
dummy_template_json3 = json.dumps(dummy_template3) dummy_template_json3 = json.dumps(dummy_template3)
dummy_template_json4 = json.dumps(dummy_template4)
@mock_cloudformation_deprecated @mock_cloudformation_deprecated
@ -213,32 +214,17 @@ def test_describe_stack_by_stack_id():
stack_by_id.stack_name.should.equal("test_stack") stack_by_id.stack_name.should.equal("test_stack")
@mock_dynamodb2 @mock_dynamodb2_deprecated
@mock_cloudformation_deprecated @mock_cloudformation_deprecated
def test_delete_stack_dynamo_template(): def test_delete_stack_dynamo_template():
conn = boto.connect_cloudformation() conn = boto.connect_cloudformation()
dynamodb_client = boto3.client("dynamodb", region_name="us-east-1") db_conn = boto.dynamodb2.connect_to_region("us-east-1")
conn.create_stack("test_stack", template_body=dummy_template4) #
table_desc = dynamodb_client.list_tables() conn.create_stack("test_stack", template_body=dummy_template_json4)
len(table_desc.get("TableNames")).should.equal(1) db_conn.list_tables()["TableNames"].should.have.length_of(1)
#
conn.delete_stack("test_stack") conn.delete_stack("test_stack")
table_desc = dynamodb_client.list_tables() db_conn.list_tables()["TableNames"].should.have.length_of(0)
len(table_desc.get("TableNames")).should.equal(0)
conn.create_stack("test_stack", template_body=dummy_template4)
@mock_dynamodb2
@mock_cloudformation
def test_delete_stack_dynamo_template():
conn = boto3.client("cloudformation", region_name="us-east-1")
dynamodb_client = boto3.client("dynamodb", region_name="us-east-1")
conn.create_stack(StackName="test_stack", TemplateBody=json.dumps(dummy_template4))
table_desc = dynamodb_client.list_tables()
len(table_desc.get("TableNames")).should.equal(1)
conn.delete_stack(StackName="test_stack")
table_desc = dynamodb_client.list_tables()
len(table_desc.get("TableNames")).should.equal(0)
conn.create_stack(StackName="test_stack", TemplateBody=json.dumps(dummy_template4))
@mock_cloudformation_deprecated @mock_cloudformation_deprecated

View File

@ -11,9 +11,9 @@ import sure # noqa
import pytest import pytest
from moto import mock_cloudformation, mock_s3, mock_sqs, mock_ec2 from moto import mock_cloudformation, mock_dynamodb2, mock_s3, mock_sqs, mock_ec2
from moto.core import ACCOUNT_ID from moto.core import ACCOUNT_ID
from .test_cloudformation_stack_crud import dummy_template_json2 from .test_cloudformation_stack_crud import dummy_template_json2, dummy_template_json4
from tests import EXAMPLE_AMI_ID from tests import EXAMPLE_AMI_ID
dummy_template = { dummy_template = {
@ -1681,3 +1681,17 @@ def test_boto3_create_duplicate_stack():
cf_conn.create_stack( cf_conn.create_stack(
StackName="test_stack", TemplateBody=dummy_template_json, StackName="test_stack", TemplateBody=dummy_template_json,
) )
@mock_dynamodb2
@mock_cloudformation
def test_delete_stack_dynamo_template():
conn = boto3.client("cloudformation", region_name="us-east-1")
dynamodb_client = boto3.client("dynamodb", region_name="us-east-1")
conn.create_stack(StackName="test_stack", TemplateBody=dummy_template_json4)
table_desc = dynamodb_client.list_tables()
len(table_desc.get("TableNames")).should.equal(1)
conn.delete_stack(StackName="test_stack")
table_desc = dynamodb_client.list_tables()
len(table_desc.get("TableNames")).should.equal(0)
conn.create_stack(StackName="test_stack", TemplateBody=dummy_template_json4)

View File

@ -475,58 +475,6 @@ def test_item_add_long_string_range_key_exception():
) )
@mock_dynamodb2
def test_item_add_long_string_range_key_exception():
name = "TestTable"
conn = boto3.client(
"dynamodb",
region_name="us-west-2",
aws_access_key_id="ak",
aws_secret_access_key="sk",
)
conn.create_table(
TableName=name,
KeySchema=[
{"AttributeName": "forum_name", "KeyType": "HASH"},
{"AttributeName": "ReceivedTime", "KeyType": "RANGE"},
],
AttributeDefinitions=[
{"AttributeName": "forum_name", "AttributeType": "S"},
{"AttributeName": "ReceivedTime", "AttributeType": "S"},
],
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
)
conn.put_item(
TableName=name,
Item={
"forum_name": {"S": "LOLCat Forum"},
"subject": {"S": "Check this out!"},
"Body": {"S": "http://url_to_lolcat.gif"},
"SentBy": {"S": "someone@somewhere.edu"},
"ReceivedTime": {"S": "x" * RANGE_KEY_MAX_LENGTH},
},
)
with pytest.raises(ClientError) as ex:
conn.put_item(
TableName=name,
Item={
"forum_name": {"S": "LOLCat Forum"},
"subject": {"S": "Check this out!"},
"Body": {"S": "http://url_to_lolcat.gif"},
"SentBy": {"S": "someone@somewhere.edu"},
"ReceivedTime": {"S": "x" * (RANGE_KEY_MAX_LENGTH + 1)},
},
)
ex.value.response["Error"]["Code"].should.equal("ValidationException")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["Error"]["Message"].should.equal(
"One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes"
)
@mock_dynamodb2 @mock_dynamodb2
def test_update_item_with_long_string_hash_key_exception(): def test_update_item_with_long_string_hash_key_exception():
name = "TestTable" name = "TestTable"
@ -838,79 +786,12 @@ def test_basic_projection_expression_using_get_item():
) )
@mock_dynamodb2
def test_basic_projection_expressions_using_query():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
# Create the DynamoDB table.
table = dynamodb.create_table(
TableName="users",
KeySchema=[
{"AttributeName": "forum_name", "KeyType": "HASH"},
{"AttributeName": "subject", "KeyType": "RANGE"},
],
AttributeDefinitions=[
{"AttributeName": "forum_name", "AttributeType": "S"},
{"AttributeName": "subject", "AttributeType": "S"},
],
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
)
table = dynamodb.Table("users")
table.put_item(
Item={"forum_name": "the-key", "subject": "123", "body": "some test message"}
)
table.put_item(
Item={
"forum_name": "not-the-key",
"subject": "123",
"body": "some other test message",
}
)
# Test a query returning all items
results = table.query(
KeyConditionExpression=Key("forum_name").eq("the-key"),
ProjectionExpression="body, subject",
)
assert "body" in results["Items"][0]
assert results["Items"][0]["body"] == "some test message"
assert "subject" in results["Items"][0]
table.put_item(
Item={
"forum_name": "the-key",
"subject": "1234",
"body": "yet another test message",
}
)
results = table.query(
KeyConditionExpression=Key("forum_name").eq("the-key"),
ProjectionExpression="body",
)
assert "body" in results["Items"][0]
assert "subject" not in results["Items"][0]
assert results["Items"][0]["body"] == "some test message"
assert "body" in results["Items"][1]
assert "subject" not in results["Items"][1]
assert results["Items"][1]["body"] == "yet another test message"
# The projection expression should not remove data from storage
results = table.query(KeyConditionExpression=Key("forum_name").eq("the-key"))
assert "subject" in results["Items"][0]
assert "body" in results["Items"][1]
assert "forum_name" in results["Items"][1]
@mock_dynamodb2 @mock_dynamodb2
def test_basic_projection_expressions_using_scan(): def test_basic_projection_expressions_using_scan():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1") dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
# Create the DynamoDB table. # Create the DynamoDB table.
table = dynamodb.create_table( dynamodb.create_table(
TableName="users", TableName="users",
KeySchema=[ KeySchema=[
{"AttributeName": "forum_name", "KeyType": "HASH"}, {"AttributeName": "forum_name", "KeyType": "HASH"},
@ -957,10 +838,11 @@ def test_basic_projection_expressions_using_scan():
FilterExpression=Key("forum_name").eq("the-key"), ProjectionExpression="body" FilterExpression=Key("forum_name").eq("the-key"), ProjectionExpression="body"
) )
assert "body" in results["Items"][0] bodies = [item["body"] for item in results["Items"]]
bodies.should.contain("some test message")
bodies.should.contain("yet another test message")
assert "subject" not in results["Items"][0] assert "subject" not in results["Items"][0]
assert "forum_name" not in results["Items"][0] assert "forum_name" not in results["Items"][0]
assert "body" in results["Items"][1]
assert "subject" not in results["Items"][1] assert "subject" not in results["Items"][1]
assert "forum_name" not in results["Items"][1] assert "forum_name" not in results["Items"][1]
@ -1151,65 +1033,6 @@ def test_nested_projection_expression_using_query():
) )
@mock_dynamodb2
def test_basic_projection_expressions_using_scan():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
# Create the DynamoDB table.
dynamodb.create_table(
TableName="users",
KeySchema=[
{"AttributeName": "forum_name", "KeyType": "HASH"},
{"AttributeName": "subject", "KeyType": "RANGE"},
],
AttributeDefinitions=[
{"AttributeName": "forum_name", "AttributeType": "S"},
{"AttributeName": "subject", "AttributeType": "S"},
],
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
)
table = dynamodb.Table("users")
table.put_item(
Item={"forum_name": "the-key", "subject": "123", "body": "some test message"}
)
table.put_item(
Item={
"forum_name": "not-the-key",
"subject": "123",
"body": "some other test message",
}
)
# Test a scan returning all items
results = table.scan(
FilterExpression=Key("forum_name").eq("the-key"),
ProjectionExpression="body, subject",
)["Items"]
results.should.equal([{"body": "some test message", "subject": "123"}])
table.put_item(
Item={
"forum_name": "the-key",
"subject": "1234",
"body": "yet another test message",
}
)
results = table.scan(
FilterExpression=Key("forum_name").eq("the-key"), ProjectionExpression="body"
)["Items"]
assert {"body": "some test message"} in results
assert {"body": "yet another test message"} in results
# The projection expression should not remove data from storage
results = table.query(KeyConditionExpression=Key("forum_name").eq("the-key"))
assert "subject" in results["Items"][0]
assert "body" in results["Items"][1]
assert "forum_name" in results["Items"][1]
@mock_dynamodb2 @mock_dynamodb2
def test_nested_projection_expression_using_scan(): def test_nested_projection_expression_using_scan():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1") dynamodb = boto3.resource("dynamodb", region_name="us-east-1")

View File

@ -759,18 +759,6 @@ def test_boto3_update_settype_item_with_conditions():
assert dict(returned_item)["Item"]["foo"].should.equal(set(["baz"])) assert dict(returned_item)["Item"]["foo"].should.equal(set(["baz"]))
@mock_dynamodb2
def test_boto3_put_item_conditions_pass():
table = _create_user_table()
table.put_item(Item={"username": "johndoe", "foo": "bar"})
table.put_item(
Item={"username": "johndoe", "foo": "baz"},
Expected={"foo": {"ComparisonOperator": "EQ", "AttributeValueList": ["bar"]}},
)
returned_item = table.get_item(Key={"username": "johndoe"})
assert dict(returned_item)["Item"]["foo"].should.equal("baz")
@mock_dynamodb2 @mock_dynamodb2
def test_scan_pagination(): def test_scan_pagination():
table = _create_user_table() table = _create_user_table()

View File

@ -783,16 +783,6 @@ def test_ami_registration():
assert images[0]["State"] == "available", "State should be available." assert images[0]["State"] == "available", "State should be available."
@mock_ec2
def test_ami_registration():
ec2 = boto3.client("ec2", region_name="us-east-1")
image_id = ec2.register_image(Name="test-register-image").get("ImageId", "")
images = ec2.describe_images(ImageIds=[image_id]).get("Images", [])
assert images[0]["Name"] == "test-register-image", "No image was registered."
assert images[0]["RootDeviceName"] == "/dev/sda1", "Wrong root device name."
assert images[0]["State"] == "available", "State should be available."
@mock_ec2 @mock_ec2
def test_ami_filter_wildcard(): def test_ami_filter_wildcard():
ec2_resource = boto3.resource("ec2", region_name="us-west-1") ec2_resource = boto3.resource("ec2", region_name="us-west-1")

View File

@ -146,7 +146,7 @@ def test_create_transit_gateway_vpn_attachment():
@mock_ec2 @mock_ec2
def test_create_transit_gateway_vpc_attachment(): def test_create_and_describe_transit_gateway_vpc_attachment():
ec2 = boto3.client("ec2", region_name="us-west-1") ec2 = boto3.client("ec2", region_name="us-west-1")
response = ec2.create_transit_gateway_vpc_attachment( response = ec2.create_transit_gateway_vpc_attachment(
TransitGatewayId="gateway_id", VpcId="some-vpc-id", SubnetIds=["sub1"] TransitGatewayId="gateway_id", VpcId="some-vpc-id", SubnetIds=["sub1"]

View File

@ -77,7 +77,7 @@ def test_create_vpn_connection_with_vpn_gateway():
@mock_ec2 @mock_ec2
def test_describe_vpn_connections(): def test_describe_vpn_connections_boto3():
client = boto3.client("ec2", region_name="us-east-1") client = boto3.client("ec2", region_name="us-east-1")
vpn_gateway = client.create_vpn_gateway(Type="ipsec.1").get("VpnGateway", {}) vpn_gateway = client.create_vpn_gateway(Type="ipsec.1").get("VpnGateway", {})

View File

@ -1565,7 +1565,7 @@ def test_set_security_groups():
@mock_elbv2 @mock_elbv2
@mock_ec2 @mock_ec2
def test_set_subnets(): def test_set_subnets_errors():
client = boto3.client("elbv2", region_name="us-east-1") client = boto3.client("elbv2", region_name="us-east-1")
ec2 = boto3.resource("ec2", region_name="us-east-1") ec2 = boto3.resource("ec2", region_name="us-east-1")

View File

@ -2255,20 +2255,6 @@ def test_update_role_description():
assert response["Role"]["RoleName"] == "my-role" assert response["Role"]["RoleName"] == "my-role"
@mock_iam()
def test_update_role():
conn = boto3.client("iam", region_name="us-east-1")
with pytest.raises(ClientError):
conn.delete_role(RoleName="my-role")
conn.create_role(
RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="/my-path/",
)
response = conn.update_role_description(RoleName="my-role", Description="test")
assert response["Role"]["RoleName"] == "my-role"
@mock_iam() @mock_iam()
def test_update_role(): def test_update_role():
conn = boto3.client("iam", region_name="us-east-1") conn = boto3.client("iam", region_name="us-east-1")
@ -2779,15 +2765,6 @@ def test_delete_account_password_policy():
) )
@mock_iam
def test_delete_account_password_policy_errors():
client = boto3.client("iam", region_name="us-east-1")
client.delete_account_password_policy.when.called_with().should.throw(
ClientError, "The account policy with name PasswordPolicy cannot be found.",
)
@mock_iam @mock_iam
def test_get_account_summary(): def test_get_account_summary():
client = boto3.client("iam", region_name="us-east-1") client = boto3.client("iam", region_name="us-east-1")

View File

@ -1009,6 +1009,7 @@ def test_iam_cloudformation_delete_users_access_key():
user = iam_client.get_user(UserName=user_name)["User"] user = iam_client.get_user(UserName=user_name)["User"]
user["UserName"].should.equal(user_name) user["UserName"].should.equal(user_name)
access_keys = iam_client.list_access_keys(UserName=user_name) access_keys = iam_client.list_access_keys(UserName=user_name)
access_keys["AccessKeyMetadata"][0]["AccessKeyId"].should.equal(access_key_id)
access_keys["AccessKeyMetadata"][0]["UserName"].should.equal(user_name) access_keys["AccessKeyMetadata"][0]["UserName"].should.equal(user_name)
access_key_id.should.equal(access_keys["AccessKeyMetadata"][0]["AccessKeyId"]) access_key_id.should.equal(access_keys["AccessKeyMetadata"][0]["AccessKeyId"])

View File

@ -311,19 +311,6 @@ def test_put_key_policy_via_alias_should_not_update():
policy["Policy"].should.equal("my policy") policy["Policy"].should.equal("my policy")
@mock_kms_deprecated
def test_put_key_policy():
conn = boto.kms.connect_to_region("us-west-2")
key = conn.create_key(
policy="my policy", description="my key1", key_usage="ENCRYPT_DECRYPT"
)
conn.put_key_policy(key["KeyMetadata"]["Arn"], "default", "new policy")
policy = conn.get_key_policy(key["KeyMetadata"]["KeyId"], "default")
policy["Policy"].should.equal("new policy")
@mock_kms_deprecated @mock_kms_deprecated
def test_list_key_policies(): def test_list_key_policies():
conn = boto.kms.connect_to_region("us-west-2") conn = boto.kms.connect_to_region("us-west-2")

View File

@ -1,6 +1,7 @@
import base64 import base64
import boto3 import boto3
import json import json
import sure # noqa
import time import time
import zlib import zlib
@ -178,7 +179,7 @@ def test_put_subscription_filter_with_lambda():
@mock_lambda @mock_lambda
@mock_logs @mock_logs
def test_delete_subscription_filter_errors(): def test_delete_subscription_filter():
# given # given
region_name = "us-east-1" region_name = "us-east-1"
client_lambda = boto3.client("lambda", region_name) client_lambda = boto3.client("lambda", region_name)

View File

@ -177,18 +177,6 @@ def test_describe_origin_endpoint_succeeds():
) )
def test_describe_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region)
channel_id = "unknown-channel"
with pytest.raises(ClientError) as err:
client.describe_origin_endpoint(Id=channel_id)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(
"originEndpoint with id={} not found".format(str(channel_id))
)
@mock_mediapackage @mock_mediapackage
def test_describe_unknown_origin_endpoint_throws_error(): def test_describe_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region) client = boto3.client("mediapackage", region_name=region)
@ -219,18 +207,6 @@ def test_delete_origin_endpoint_succeeds():
) )
def test_delete_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region)
channel_id = "unknown-channel"
with pytest.raises(ClientError) as err:
client.delete_origin_endpoint(Id=channel_id)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(
"originEndpoint with id={} not found".format(str(channel_id))
)
@mock_mediapackage @mock_mediapackage
def test_delete_unknown_origin_endpoint_throws_error(): def test_delete_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region) client = boto3.client("mediapackage", region_name=region)
@ -258,22 +234,6 @@ def test_update_origin_endpoint_succeeds():
update_response["ManifestName"].should.equal("updated-manifest-name") update_response["ManifestName"].should.equal("updated-manifest-name")
def test_update_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region)
channel_id = "unknown-channel"
with pytest.raises(ClientError) as err:
client.update_origin_endpoint(
Id=channel_id,
Description="updated-channel-description",
ManifestName="updated-manifest-name",
)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(
"originEndpoint with id={} not found".format(str(channel_id))
)
@mock_mediapackage @mock_mediapackage
def test_update_unknown_origin_endpoint_throws_error(): def test_update_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region) client = boto3.client("mediapackage", region_name=region)

View File

@ -221,7 +221,7 @@ def test_list_tags_for_resource_return_none_if_no_tags():
@mock_mediastore @mock_mediastore
def test_list_tags_for_resource_return_none_if_no_tags(): def test_list_tags_for_resource_return_error_for_unknown_resource():
client = boto3.client("mediastore", region_name=region) client = boto3.client("mediastore", region_name=region)
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:
client.list_tags_for_resource(Resource="not_existing") client.list_tags_for_resource(Resource="not_existing")

View File

@ -70,16 +70,3 @@ def test_list_items():
len(items).should.equal(1) len(items).should.equal(1)
object_exists = any(d["Name"] == object_path for d in items) object_exists = any(d["Name"] == object_path for d in items)
object_exists.should.equal(True) object_exists.should.equal(True)
@mock_mediastoredata
def test_list_items():
client = boto3.client("mediastore-data", region_name=region)
items = client.list_items()["Items"]
len(items).should.equal(0)
object_path = "foo"
client.put_object(Body="011001", Path=object_path)
items = client.list_items()["Items"]
len(items).should.equal(1)
object_exists = any(d["Name"] == object_path for d in items)
object_exists.should.equal(True)

View File

@ -1163,16 +1163,6 @@ def test__get_resource_for_tagging_non_existing_policy():
ex.message.should.equal("You specified a target that doesn't exist.") ex.message.should.equal("You specified a target that doesn't exist.")
def test__get_resource_for_tagging_non_existing_policy():
org_backend = OrganizationsBackend()
with pytest.raises(TargetNotFoundException) as e:
org_backend._get_resource_for_tagging("p-y1vas4da")
ex = e.value
ex.code.should.equal(400)
ex.description.should.contain("TargetNotFoundException")
ex.message.should.equal("You specified a target that doesn't exist.")
def test__get_resource_to_tag_incorrect_resource(): def test__get_resource_to_tag_incorrect_resource():
org_backend = OrganizationsBackend() org_backend = OrganizationsBackend()
with pytest.raises(InvalidInputException) as e: with pytest.raises(InvalidInputException) as e:
@ -1323,7 +1313,7 @@ def test_enable_aws_service_access():
service = response["EnabledServicePrincipals"][0] service = response["EnabledServicePrincipals"][0]
service["ServicePrincipal"].should.equal("config.amazonaws.com") service["ServicePrincipal"].should.equal("config.amazonaws.com")
date_enabled = service["DateEnabled"] date_enabled = service["DateEnabled"]
date_enabled["DateEnabled"].should.be.a(datetime) date_enabled.should.be.a(datetime)
# enabling the same service again should not result in any error or change # enabling the same service again should not result in any error or change
# when # when
@ -1338,7 +1328,7 @@ def test_enable_aws_service_access():
@mock_organizations @mock_organizations
def test_enable_aws_service_access(): def test_enable_aws_service_access_error():
client = boto3.client("organizations", region_name="us-east-1") client = boto3.client("organizations", region_name="us-east-1")
client.create_organization(FeatureSet="ALL") client.create_organization(FeatureSet="ALL")
@ -1354,7 +1344,7 @@ def test_enable_aws_service_access():
@mock_organizations @mock_organizations
def test_enable_aws_service_access(): def test_enable_multiple_aws_service_access():
# given # given
client = boto3.client("organizations", region_name="us-east-1") client = boto3.client("organizations", region_name="us-east-1")
client.create_organization(FeatureSet="ALL") client.create_organization(FeatureSet="ALL")

View File

@ -1569,17 +1569,7 @@ def test_resize_cluster():
@mock_redshift @mock_redshift
def test_get_cluster_credentials_non_existent_cluster(): def test_get_cluster_credentials_non_existent_cluster_and_user():
client = boto3.client("redshift", region_name="us-east-1")
with pytest.raises(ClientError) as ex:
client.get_cluster_credentials(ClusterIdentifier="non-existent")
ex.value.response["Error"]["Code"].should.equal("ClusterNotFound")
ex.value.response["Error"]["Message"].should.match(r"Cluster .+ not found.")
@mock_redshift
def test_get_cluster_credentials_non_existent_cluster():
client = boto3.client("redshift", region_name="us-east-1") client = boto3.client("redshift", region_name="us-east-1")
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:

View File

@ -2813,7 +2813,7 @@ def test_fifo_send_message_when_same_group_id_is_in_dlq():
@mock_sqs @mock_sqs
def test_message_attributes_in_receive_message(): def test_message_attributes_contains_trace_header():
sqs = boto3.resource("sqs", region_name="us-east-1") sqs = boto3.resource("sqs", region_name="us-east-1")
conn = boto3.client("sqs", region_name="us-east-1") conn = boto3.client("sqs", region_name="us-east-1")
conn.create_queue(QueueName="test-queue") conn.create_queue(QueueName="test-queue")

View File

@ -748,61 +748,3 @@ def test_sts_regions(region):
client = boto3.client("sts", region_name=region) client = boto3.client("sts", region_name=region)
resp = client.get_caller_identity() resp = client.get_caller_identity()
resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
@mock_sts
@mock_iam
def test_get_caller_identity_with_iam_user_credentials():
iam_client = boto3.client("iam", region_name="us-east-1")
iam_user_name = "new-user"
iam_user = iam_client.create_user(UserName=iam_user_name)["User"]
access_key = iam_client.create_access_key(UserName=iam_user_name)["AccessKey"]
identity = boto3.client(
"sts",
region_name="us-east-1",
aws_access_key_id=access_key["AccessKeyId"],
aws_secret_access_key=access_key["SecretAccessKey"],
).get_caller_identity()
identity["Arn"].should.equal(iam_user["Arn"])
identity["UserId"].should.equal(iam_user["UserId"])
identity["Account"].should.equal(str(ACCOUNT_ID))
@mock_sts
@mock_iam
def test_get_caller_identity_with_assumed_role_credentials():
iam_client = boto3.client("iam", region_name="us-east-1")
sts_client = boto3.client("sts", region_name="us-east-1")
iam_role_name = "new-user"
trust_policy_document = {
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::{account_id}:root".format(account_id=ACCOUNT_ID)
},
"Action": "sts:AssumeRole",
},
}
iam_role_arn = iam_client.role_arn = iam_client.create_role(
RoleName=iam_role_name,
AssumeRolePolicyDocument=json.dumps(trust_policy_document),
)["Role"]["Arn"]
session_name = "new-session"
assumed_role = sts_client.assume_role(
RoleArn=iam_role_arn, RoleSessionName=session_name
)
access_key = assumed_role["Credentials"]
identity = boto3.client(
"sts",
region_name="us-east-1",
aws_access_key_id=access_key["AccessKeyId"],
aws_secret_access_key=access_key["SecretAccessKey"],
).get_caller_identity()
identity["Arn"].should.equal(assumed_role["AssumedRoleUser"]["Arn"])
identity["UserId"].should.equal(assumed_role["AssumedRoleUser"]["AssumedRoleId"])
identity["Account"].should.equal(str(ACCOUNT_ID))