diff --git a/Makefile b/Makefile index ad03a3964..e0fd4e6c0 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ init: lint: flake8 moto black --check moto/ tests/ + pylint -j 0 tests format: black moto/ tests/ diff --git a/requirements-tests.txt b/requirements-tests.txt index 847ce539e..350da8111 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -2,3 +2,4 @@ pytest pytest-cov sure==1.4.11 freezegun +pylint diff --git a/setup.cfg b/setup.cfg index b7aa23edf..f907977e3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,3 +7,8 @@ markers = [coverage:run] 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 diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud.py b/tests/test_cloudformation/test_cloudformation_stack_crud.py index 1725be0f6..9c1a723a0 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud.py @@ -5,6 +5,7 @@ import json import boto import boto3 +import boto.dynamodb2 import boto.iam import boto.s3 import boto.s3.key @@ -20,8 +21,7 @@ from moto import ( mock_s3_deprecated, mock_route53_deprecated, mock_iam_deprecated, - mock_dynamodb2, - mock_cloudformation, + mock_dynamodb2_deprecated, ) from moto.cloudformation import cloudformation_backends @@ -73,6 +73,7 @@ dummy_template4 = { dummy_template_json = json.dumps(dummy_template) dummy_template_json2 = json.dumps(dummy_template2) dummy_template_json3 = json.dumps(dummy_template3) +dummy_template_json4 = json.dumps(dummy_template4) @mock_cloudformation_deprecated @@ -213,32 +214,17 @@ def test_describe_stack_by_stack_id(): stack_by_id.stack_name.should.equal("test_stack") -@mock_dynamodb2 +@mock_dynamodb2_deprecated @mock_cloudformation_deprecated def test_delete_stack_dynamo_template(): conn = boto.connect_cloudformation() - dynamodb_client = boto3.client("dynamodb", region_name="us-east-1") - conn.create_stack("test_stack", template_body=dummy_template4) - table_desc = dynamodb_client.list_tables() - len(table_desc.get("TableNames")).should.equal(1) + db_conn = boto.dynamodb2.connect_to_region("us-east-1") + # + conn.create_stack("test_stack", template_body=dummy_template_json4) + db_conn.list_tables()["TableNames"].should.have.length_of(1) + # conn.delete_stack("test_stack") - table_desc = dynamodb_client.list_tables() - 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)) + db_conn.list_tables()["TableNames"].should.have.length_of(0) @mock_cloudformation_deprecated diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 0ffb71fdc..1c2c546cd 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -11,9 +11,9 @@ import sure # noqa 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 .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 dummy_template = { @@ -1681,3 +1681,17 @@ def test_boto3_create_duplicate_stack(): cf_conn.create_stack( 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) diff --git a/tests/test_dynamodb2/test_dynamodb.py b/tests/test_dynamodb2/test_dynamodb.py index 7085c0d67..2efcf6e26 100644 --- a/tests/test_dynamodb2/test_dynamodb.py +++ b/tests/test_dynamodb2/test_dynamodb.py @@ -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 def test_update_item_with_long_string_hash_key_exception(): 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 def test_basic_projection_expressions_using_scan(): dynamodb = boto3.resource("dynamodb", region_name="us-east-1") # Create the DynamoDB table. - table = dynamodb.create_table( + dynamodb.create_table( TableName="users", KeySchema=[ {"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" ) - 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 "forum_name" not in results["Items"][0] - assert "body" in results["Items"][1] assert "subject" 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 def test_nested_projection_expression_using_scan(): dynamodb = boto3.resource("dynamodb", region_name="us-east-1") diff --git a/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py index b5cc01c84..eaa392df3 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py @@ -759,18 +759,6 @@ def test_boto3_update_settype_item_with_conditions(): 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 def test_scan_pagination(): table = _create_user_table() diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index b2bf4b7f4..a73f7a8ad 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -783,16 +783,6 @@ def test_ami_registration(): 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 def test_ami_filter_wildcard(): ec2_resource = boto3.resource("ec2", region_name="us-west-1") diff --git a/tests/test_ec2/test_transit_gateway.py b/tests/test_ec2/test_transit_gateway.py index 7c2141553..cbda02e3d 100644 --- a/tests/test_ec2/test_transit_gateway.py +++ b/tests/test_ec2/test_transit_gateway.py @@ -146,7 +146,7 @@ def test_create_transit_gateway_vpn_attachment(): @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") response = ec2.create_transit_gateway_vpc_attachment( TransitGatewayId="gateway_id", VpcId="some-vpc-id", SubnetIds=["sub1"] diff --git a/tests/test_ec2/test_vpn_connections.py b/tests/test_ec2/test_vpn_connections.py index acb322f8a..985e8fd89 100644 --- a/tests/test_ec2/test_vpn_connections.py +++ b/tests/test_ec2/test_vpn_connections.py @@ -77,7 +77,7 @@ def test_create_vpn_connection_with_vpn_gateway(): @mock_ec2 -def test_describe_vpn_connections(): +def test_describe_vpn_connections_boto3(): client = boto3.client("ec2", region_name="us-east-1") vpn_gateway = client.create_vpn_gateway(Type="ipsec.1").get("VpnGateway", {}) diff --git a/tests/test_elbv2/test_elbv2.py b/tests/test_elbv2/test_elbv2.py index aec1c090c..7b738dca2 100644 --- a/tests/test_elbv2/test_elbv2.py +++ b/tests/test_elbv2/test_elbv2.py @@ -1565,7 +1565,7 @@ def test_set_security_groups(): @mock_elbv2 @mock_ec2 -def test_set_subnets(): +def test_set_subnets_errors(): client = boto3.client("elbv2", region_name="us-east-1") ec2 = boto3.resource("ec2", region_name="us-east-1") diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 8bb6ef9d8..558472295 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -2255,20 +2255,6 @@ def test_update_role_description(): 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() def test_update_role(): 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 def test_get_account_summary(): client = boto3.client("iam", region_name="us-east-1") diff --git a/tests/test_iam/test_iam_cloudformation.py b/tests/test_iam/test_iam_cloudformation.py index f4b2e51ba..6e777dd57 100644 --- a/tests/test_iam/test_iam_cloudformation.py +++ b/tests/test_iam/test_iam_cloudformation.py @@ -1009,6 +1009,7 @@ def test_iam_cloudformation_delete_users_access_key(): user = iam_client.get_user(UserName=user_name)["User"] user["UserName"].should.equal(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_key_id.should.equal(access_keys["AccessKeyMetadata"][0]["AccessKeyId"]) diff --git a/tests/test_kms/test_kms.py b/tests/test_kms/test_kms.py index de7a93fce..ba4ef1707 100644 --- a/tests/test_kms/test_kms.py +++ b/tests/test_kms/test_kms.py @@ -311,19 +311,6 @@ def test_put_key_policy_via_alias_should_not_update(): 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 def test_list_key_policies(): conn = boto.kms.connect_to_region("us-west-2") diff --git a/tests/test_logs/test_integration.py b/tests/test_logs/test_integration.py index eab839970..590ff29a9 100644 --- a/tests/test_logs/test_integration.py +++ b/tests/test_logs/test_integration.py @@ -1,6 +1,7 @@ import base64 import boto3 import json +import sure # noqa import time import zlib @@ -178,7 +179,7 @@ def test_put_subscription_filter_with_lambda(): @mock_lambda @mock_logs -def test_delete_subscription_filter_errors(): +def test_delete_subscription_filter(): # given region_name = "us-east-1" client_lambda = boto3.client("lambda", region_name) diff --git a/tests/test_mediapackage/test_mediapackage.py b/tests/test_mediapackage/test_mediapackage.py index 579688ced..0c776a9cc 100644 --- a/tests/test_mediapackage/test_mediapackage.py +++ b/tests/test_mediapackage/test_mediapackage.py @@ -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 def test_describe_unknown_origin_endpoint_throws_error(): 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 def test_delete_unknown_origin_endpoint_throws_error(): 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") -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 def test_update_unknown_origin_endpoint_throws_error(): client = boto3.client("mediapackage", region_name=region) diff --git a/tests/test_mediastore/test_mediastore.py b/tests/test_mediastore/test_mediastore.py index 924406c47..b0dd1851f 100644 --- a/tests/test_mediastore/test_mediastore.py +++ b/tests/test_mediastore/test_mediastore.py @@ -221,7 +221,7 @@ def test_list_tags_for_resource_return_none_if_no_tags(): @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) with pytest.raises(ClientError) as ex: client.list_tags_for_resource(Resource="not_existing") diff --git a/tests/test_mediastoredata/test_mediastoredata.py b/tests/test_mediastoredata/test_mediastoredata.py index 43d3ab3ff..3f1d6d95a 100644 --- a/tests/test_mediastoredata/test_mediastoredata.py +++ b/tests/test_mediastoredata/test_mediastoredata.py @@ -70,16 +70,3 @@ def test_list_items(): len(items).should.equal(1) object_exists = any(d["Name"] == object_path for d in items) 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) diff --git a/tests/test_organizations/test_organizations_boto3.py b/tests/test_organizations/test_organizations_boto3.py index 384a86998..ee3a92d0c 100644 --- a/tests/test_organizations/test_organizations_boto3.py +++ b/tests/test_organizations/test_organizations_boto3.py @@ -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.") -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(): org_backend = OrganizationsBackend() with pytest.raises(InvalidInputException) as e: @@ -1323,7 +1313,7 @@ def test_enable_aws_service_access(): service = response["EnabledServicePrincipals"][0] service["ServicePrincipal"].should.equal("config.amazonaws.com") 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 # when @@ -1338,7 +1328,7 @@ def test_enable_aws_service_access(): @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.create_organization(FeatureSet="ALL") @@ -1354,7 +1344,7 @@ def test_enable_aws_service_access(): @mock_organizations -def test_enable_aws_service_access(): +def test_enable_multiple_aws_service_access(): # given client = boto3.client("organizations", region_name="us-east-1") client.create_organization(FeatureSet="ALL") diff --git a/tests/test_redshift/test_redshift.py b/tests/test_redshift/test_redshift.py index dfb3186aa..472f3c5ec 100644 --- a/tests/test_redshift/test_redshift.py +++ b/tests/test_redshift/test_redshift.py @@ -1569,17 +1569,7 @@ def test_resize_cluster(): @mock_redshift -def test_get_cluster_credentials_non_existent_cluster(): - 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(): +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: diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 2efc0ae7c..261078c60 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -2813,7 +2813,7 @@ def test_fifo_send_message_when_same_group_id_is_in_dlq(): @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") conn = boto3.client("sqs", region_name="us-east-1") conn.create_queue(QueueName="test-queue") diff --git a/tests/test_sts/test_sts.py b/tests/test_sts/test_sts.py index 6505ab206..3fa656a01 100644 --- a/tests/test_sts/test_sts.py +++ b/tests/test_sts/test_sts.py @@ -748,61 +748,3 @@ def test_sts_regions(region): client = boto3.client("sts", region_name=region) resp = client.get_caller_identity() 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))