Techdebt: Replace sure with regular assertions in Firehose (#6565)

This commit is contained in:
Bert Blommers 2023-07-27 22:25:43 +00:00 committed by GitHub
parent 689c93376a
commit a68a035038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 166 additions and 185 deletions

View File

@ -1,6 +1,5 @@
"""Unit tests verifying various delivery stream destination content.""" """Unit tests verifying various delivery stream destination content."""
import boto3 import boto3
import sure # noqa # pylint: disable=unused-import
from moto import mock_firehose from moto import mock_firehose
from moto import settings from moto import settings
@ -118,43 +117,41 @@ def test_create_redshift_delivery_stream():
stream_description = response["DeliveryStreamDescription"] stream_description = response["DeliveryStreamDescription"]
# Sure and Freezegun don't play nicely together # Sure and Freezegun don't play nicely together
_ = stream_description.pop("CreateTimestamp") stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp") stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal( assert stream_description == {
{ "DeliveryStreamName": stream_name,
"DeliveryStreamName": stream_name, "DeliveryStreamARN": stream_arn,
"DeliveryStreamARN": stream_arn, "DeliveryStreamStatus": "ACTIVE",
"DeliveryStreamStatus": "ACTIVE", "DeliveryStreamType": "DirectPut",
"DeliveryStreamType": "DirectPut", "VersionId": "1",
"VersionId": "1", "Destinations": [
"Destinations": [ {
{ "DestinationId": "destinationId-000000000001",
"DestinationId": "destinationId-000000000001", "RedshiftDestinationDescription": {
"RedshiftDestinationDescription": { "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role", "ClusterJDBCURL": "jdbc:redshift://host.amazonaws.com:5439/database",
"ClusterJDBCURL": "jdbc:redshift://host.amazonaws.com:5439/database", "CopyCommand": {
"CopyCommand": { "DataTableName": "outputTable",
"DataTableName": "outputTable", "CopyOptions": "CSV DELIMITER ',' NULL '\\0'",
"CopyOptions": "CSV DELIMITER ',' NULL '\\0'",
},
"Username": "username",
"S3DestinationDescription": {
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"BucketARN": "arn:aws:s3:::firehose-test",
"Prefix": "myFolder/",
"BufferingHints": {
"SizeInMBs": 123,
"IntervalInSeconds": 124,
},
"CompressionFormat": "UNCOMPRESSED",
},
}, },
} "Username": "username",
], "S3DestinationDescription": {
"HasMoreDestinations": False, "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
} "BucketARN": "arn:aws:s3:::firehose-test",
) "Prefix": "myFolder/",
"BufferingHints": {
"SizeInMBs": 123,
"IntervalInSeconds": 124,
},
"CompressionFormat": "UNCOMPRESSED",
},
},
}
],
"HasMoreDestinations": False,
}
@mock_firehose @mock_firehose
@ -170,52 +167,48 @@ def test_create_extended_s3_delivery_stream():
stream_description = response["DeliveryStreamDescription"] stream_description = response["DeliveryStreamDescription"]
# Sure and Freezegun don't play nicely together # Sure and Freezegun don't play nicely together
_ = stream_description.pop("CreateTimestamp") stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp") stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal( assert stream_description == {
{ "DeliveryStreamName": stream_name,
"DeliveryStreamName": stream_name, "DeliveryStreamARN": stream_arn,
"DeliveryStreamARN": stream_arn, "DeliveryStreamStatus": "ACTIVE",
"DeliveryStreamStatus": "ACTIVE", "DeliveryStreamType": "DirectPut",
"DeliveryStreamType": "DirectPut", "VersionId": "1",
"VersionId": "1", "Destinations": [
"Destinations": [ {
{ "DestinationId": "destinationId-000000000001",
"DestinationId": "destinationId-000000000001", "ExtendedS3DestinationDescription": {
"ExtendedS3DestinationDescription": { "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role", "BucketARN": "arn:aws:s3:::firehose-test",
"BucketARN": "arn:aws:s3:::firehose-test", "Prefix": "myFolder/",
"Prefix": "myFolder/", "CompressionFormat": "UNCOMPRESSED",
"CompressionFormat": "UNCOMPRESSED", "DataFormatConversionConfiguration": {
"DataFormatConversionConfiguration": { "Enabled": True,
"Enabled": True, "InputFormatConfiguration": {
"InputFormatConfiguration": { "Deserializer": {"HiveJsonSerDe": {}}
"Deserializer": {"HiveJsonSerDe": {}} },
}, "OutputFormatConfiguration": {
"OutputFormatConfiguration": { "Serializer": {"ParquetSerDe": {"Compression": "SNAPPY"}}
"Serializer": { },
"ParquetSerDe": {"Compression": "SNAPPY"} "SchemaConfiguration": {
} "DatabaseName": stream_name,
}, "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"SchemaConfiguration": { "TableName": "outputTable",
"DatabaseName": stream_name,
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"TableName": "outputTable",
},
}, },
}, },
"S3DestinationDescription": { },
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role", "S3DestinationDescription": {
"BucketARN": "arn:aws:s3:::firehose-test", "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"Prefix": "myFolder/", "BucketARN": "arn:aws:s3:::firehose-test",
"CompressionFormat": "UNCOMPRESSED", "Prefix": "myFolder/",
}, "CompressionFormat": "UNCOMPRESSED",
} },
], }
"HasMoreDestinations": False, ],
} "HasMoreDestinations": False,
) }
@mock_firehose @mock_firehose
@ -234,40 +227,38 @@ def test_create_elasticsearch_delivery_stream():
_ = stream_description.pop("CreateTimestamp") _ = stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp") _ = stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal( assert stream_description == {
{ "DeliveryStreamName": stream_name,
"DeliveryStreamName": stream_name, "DeliveryStreamARN": stream_arn,
"DeliveryStreamARN": stream_arn, "DeliveryStreamStatus": "ACTIVE",
"DeliveryStreamStatus": "ACTIVE", "DeliveryStreamType": "DirectPut",
"DeliveryStreamType": "DirectPut", "VersionId": "1",
"VersionId": "1", "Destinations": [
"Destinations": [ {
{ "DestinationId": "destinationId-000000000001",
"DestinationId": "destinationId-000000000001", "ElasticsearchDestinationDescription": {
"ElasticsearchDestinationDescription": { "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"DomainARN": "arn:aws:es:::domain/firehose-test",
"IndexName": "myIndex",
"TypeName": "UNCOMPRESSED",
"IndexRotationPeriod": "NoRotation",
"BufferingHints": {"IntervalInSeconds": 123, "SizeInMBs": 123},
"RetryOptions": {"DurationInSeconds": 123},
"S3DestinationDescription": {
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role", "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"DomainARN": "arn:aws:es:::domain/firehose-test", "BucketARN": "arn:aws:s3:::firehose-test",
"IndexName": "myIndex", "Prefix": "myFolder/",
"TypeName": "UNCOMPRESSED", "BufferingHints": {
"IndexRotationPeriod": "NoRotation", "SizeInMBs": 123,
"BufferingHints": {"IntervalInSeconds": 123, "SizeInMBs": 123}, "IntervalInSeconds": 124,
"RetryOptions": {"DurationInSeconds": 123},
"S3DestinationDescription": {
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"BucketARN": "arn:aws:s3:::firehose-test",
"Prefix": "myFolder/",
"BufferingHints": {
"SizeInMBs": 123,
"IntervalInSeconds": 124,
},
"CompressionFormat": "UNCOMPRESSED",
}, },
"CompressionFormat": "UNCOMPRESSED",
}, },
} },
], }
"HasMoreDestinations": False, ],
} "HasMoreDestinations": False,
) }
@mock_firehose @mock_firehose
@ -292,28 +283,26 @@ def test_create_s3_delivery_stream():
stream_description = response["DeliveryStreamDescription"] stream_description = response["DeliveryStreamDescription"]
# Sure and Freezegun don't play nicely together # Sure and Freezegun don't play nicely together
_ = stream_description.pop("CreateTimestamp") stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp") stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal( assert stream_description == {
{ "DeliveryStreamName": stream_name,
"DeliveryStreamName": stream_name, "DeliveryStreamARN": stream_arn,
"DeliveryStreamARN": stream_arn, "DeliveryStreamStatus": "ACTIVE",
"DeliveryStreamStatus": "ACTIVE", "DeliveryStreamType": "DirectPut",
"DeliveryStreamType": "DirectPut", "VersionId": "1",
"VersionId": "1", "Destinations": [
"Destinations": [ {
{ "DestinationId": "destinationId-000000000001",
"DestinationId": "destinationId-000000000001", "S3DestinationDescription": {
"S3DestinationDescription": { "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role", "BucketARN": "arn:aws:s3:::firehose-test",
"BucketARN": "arn:aws:s3:::firehose-test", "Prefix": "myFolder/",
"Prefix": "myFolder/", "BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124},
"BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124}, "CompressionFormat": "UNCOMPRESSED",
"CompressionFormat": "UNCOMPRESSED", },
}, }
} ],
], "HasMoreDestinations": False,
"HasMoreDestinations": False, }
}
)

View File

@ -19,7 +19,7 @@ def test_firehose_without_encryption():
resp = client.describe_delivery_stream(DeliveryStreamName=name)[ resp = client.describe_delivery_stream(DeliveryStreamName=name)[
"DeliveryStreamDescription" "DeliveryStreamDescription"
] ]
resp.shouldnt.have.key("DeliveryStreamEncryptionConfiguration") assert "DeliveryStreamEncryptionConfiguration" not in resp
client.start_delivery_stream_encryption( client.start_delivery_stream_encryption(
DeliveryStreamName=name, DeliveryStreamName=name,
@ -29,12 +29,10 @@ def test_firehose_without_encryption():
stream = client.describe_delivery_stream(DeliveryStreamName=name)[ stream = client.describe_delivery_stream(DeliveryStreamName=name)[
"DeliveryStreamDescription" "DeliveryStreamDescription"
] ]
stream.should.have.key("DeliveryStreamEncryptionConfiguration").equals( assert stream["DeliveryStreamEncryptionConfiguration"] == {
{ "KeyType": "AWS_OWNED_CMK",
"KeyType": "AWS_OWNED_CMK", "Status": "ENABLED",
"Status": "ENABLED", }
}
)
@mock_firehose @mock_firehose
@ -50,18 +48,16 @@ def test_firehose_with_encryption():
stream = client.describe_delivery_stream(DeliveryStreamName=name)[ stream = client.describe_delivery_stream(DeliveryStreamName=name)[
"DeliveryStreamDescription" "DeliveryStreamDescription"
] ]
stream.should.have.key("DeliveryStreamEncryptionConfiguration").equals( assert stream["DeliveryStreamEncryptionConfiguration"] == {
{"KeyType": "AWS_OWNED_CMK"} "KeyType": "AWS_OWNED_CMK"
) }
client.stop_delivery_stream_encryption(DeliveryStreamName=name) client.stop_delivery_stream_encryption(DeliveryStreamName=name)
stream = client.describe_delivery_stream(DeliveryStreamName=name)[ stream = client.describe_delivery_stream(DeliveryStreamName=name)[
"DeliveryStreamDescription" "DeliveryStreamDescription"
] ]
stream.should.have.key("DeliveryStreamEncryptionConfiguration").should.have.key( assert stream["DeliveryStreamEncryptionConfiguration"]["Status"] == "DISABLED"
"Status"
).equals("DISABLED")
@mock_firehose @mock_firehose
@ -74,8 +70,8 @@ def test_start_encryption_on_unknown_stream():
DeliveryStreamEncryptionConfigurationInput={"KeyType": "AWS_OWNED_CMK"}, DeliveryStreamEncryptionConfigurationInput={"KeyType": "AWS_OWNED_CMK"},
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException") assert err["Code"] == "ResourceNotFoundException"
err["Message"].should.equal("Firehose ? under account 123456789012 not found.") assert err["Message"] == "Firehose ? under account 123456789012 not found."
@mock_firehose @mock_firehose
@ -85,5 +81,5 @@ def test_stop_encryption_on_unknown_stream():
with pytest.raises(ClientError) as exc: with pytest.raises(ClientError) as exc:
client.stop_delivery_stream_encryption(DeliveryStreamName="?") client.stop_delivery_stream_encryption(DeliveryStreamName="?")
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException") assert err["Code"] == "ResourceNotFoundException"
err["Message"].should.equal("Firehose ? under account 123456789012 not found.") assert err["Message"] == "Firehose ? under account 123456789012 not found."

View File

@ -1,6 +1,5 @@
"""Unit tests verifying put-related delivery stream APIs.""" """Unit tests verifying put-related delivery stream APIs."""
import boto3 import boto3
import sure # noqa pylint: disable=unused-import
from moto import mock_firehose from moto import mock_firehose
from moto import mock_s3 from moto import mock_s3

View File

@ -1,5 +1,4 @@
import boto3 import boto3
import sure # noqa # pylint: disable=unused-import
from moto import mock_firehose from moto import mock_firehose
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
@ -22,40 +21,38 @@ def test_create_http_stream():
stream_description = response["DeliveryStreamDescription"] stream_description = response["DeliveryStreamDescription"]
# Sure and Freezegun don't play nicely together # Sure and Freezegun don't play nicely together
_ = stream_description.pop("CreateTimestamp") stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp") stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal( assert stream_description == {
{ "DeliveryStreamName": stream_name,
"DeliveryStreamName": stream_name, "DeliveryStreamARN": stream_arn,
"DeliveryStreamARN": stream_arn, "DeliveryStreamStatus": "ACTIVE",
"DeliveryStreamStatus": "ACTIVE", "DeliveryStreamType": "DirectPut",
"DeliveryStreamType": "DirectPut", "VersionId": "1",
"VersionId": "1", "Destinations": [
"Destinations": [ {
{ "DestinationId": "destinationId-000000000001",
"DestinationId": "destinationId-000000000001", "HttpEndpointDestinationDescription": {
"HttpEndpointDestinationDescription": { "EndpointConfiguration": {"Url": "google.com"},
"EndpointConfiguration": {"Url": "google.com"}, "RetryOptions": {"DurationInSeconds": 100},
"RetryOptions": {"DurationInSeconds": 100}, "BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124},
"BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124}, "CloudWatchLoggingOptions": {"Enabled": False},
"CloudWatchLoggingOptions": {"Enabled": False}, "S3DestinationDescription": {
"S3DestinationDescription": { "RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role",
"RoleARN": f"arn:aws:iam::{ACCOUNT_ID}:role/firehose_delivery_role", "BucketARN": "arn:aws:s3:::firehose-test",
"BucketARN": "arn:aws:s3:::firehose-test", "Prefix": "myFolder/",
"Prefix": "myFolder/", "BufferingHints": {
"BufferingHints": { "SizeInMBs": 123,
"SizeInMBs": 123, "IntervalInSeconds": 124,
"IntervalInSeconds": 124,
},
"CompressionFormat": "UNCOMPRESSED",
}, },
"CompressionFormat": "UNCOMPRESSED",
}, },
} },
], }
"HasMoreDestinations": False, ],
} "HasMoreDestinations": False,
) }
@mock_firehose @mock_firehose
@ -82,4 +79,4 @@ def test_update_s3_for_http_stream():
s3_desc = desc["Destinations"][0]["HttpEndpointDestinationDescription"][ s3_desc = desc["Destinations"][0]["HttpEndpointDestinationDescription"][
"S3DestinationDescription" "S3DestinationDescription"
] ]
s3_desc.should.have.key("ErrorOutputPrefix").equals("prefix2") assert s3_desc["ErrorOutputPrefix"] == "prefix2"