moto/tests/test_kinesis/test_firehose.py

269 lines
9.7 KiB
Python
Raw Normal View History

2015-10-30 13:59:57 +00:00
from __future__ import unicode_literals
import datetime
from botocore.exceptions import ClientError
2015-10-30 13:59:57 +00:00
import boto3
import sure # noqa
from moto import mock_kinesis
from moto.core import ACCOUNT_ID
2015-10-30 13:59:57 +00:00
def create_s3_delivery_stream(client, stream_name):
return client.create_delivery_stream(
DeliveryStreamName=stream_name,
DeliveryStreamType="DirectPut",
ExtendedS3DestinationConfiguration={
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(ACCOUNT_ID),
2019-10-31 15:44:26 +00:00
"BucketARN": "arn:aws:s3:::kinesis-test",
"Prefix": "myFolder/",
"CompressionFormat": "UNCOMPRESSED",
"DataFormatConversionConfiguration": {
"Enabled": True,
"InputFormatConfiguration": {"Deserializer": {"HiveJsonSerDe": {}}},
"OutputFormatConfiguration": {
"Serializer": {"ParquetSerDe": {"Compression": "SNAPPY"}}
},
2019-10-31 15:44:26 +00:00
"SchemaConfiguration": {
"DatabaseName": stream_name,
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"TableName": "outputTable",
},
},
2019-10-31 15:44:26 +00:00
},
)
def create_redshift_delivery_stream(client, stream_name):
2015-10-30 13:59:57 +00:00
return client.create_delivery_stream(
DeliveryStreamName=stream_name,
RedshiftDestinationConfiguration={
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(ACCOUNT_ID),
2019-10-31 15:44:26 +00:00
"ClusterJDBCURL": "jdbc:redshift://host.amazonaws.com:5439/database",
"CopyCommand": {
"DataTableName": "outputTable",
"CopyOptions": "CSV DELIMITER ',' NULL '\\0'",
2015-10-30 13:59:57 +00:00
},
2019-10-31 15:44:26 +00:00
"Username": "username",
"Password": "password",
"S3Configuration": {
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"BucketARN": "arn:aws:s3:::kinesis-test",
"Prefix": "myFolder/",
"BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124},
"CompressionFormat": "UNCOMPRESSED",
},
},
2015-10-30 13:59:57 +00:00
)
@mock_kinesis
def test_create_redshift_delivery_stream():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
response = create_redshift_delivery_stream(client, "stream1")
stream_arn = response["DeliveryStreamARN"]
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
response = client.describe_delivery_stream(DeliveryStreamName="stream1")
stream_description = response["DeliveryStreamDescription"]
2015-10-30 13:59:57 +00:00
# Sure and Freezegun don't play nicely together
2019-10-31 15:44:26 +00:00
_ = stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal(
{
"DeliveryStreamName": "stream1",
"DeliveryStreamARN": stream_arn,
"DeliveryStreamStatus": "ACTIVE",
"VersionId": "string",
"Destinations": [
{
"DestinationId": "string",
"RedshiftDestinationDescription": {
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"ClusterJDBCURL": "jdbc:redshift://host.amazonaws.com:5439/database",
"CopyCommand": {
"DataTableName": "outputTable",
"CopyOptions": "CSV DELIMITER ',' NULL '\\0'",
},
"Username": "username",
"S3DestinationDescription": {
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"BucketARN": "arn:aws:s3:::kinesis-test",
"Prefix": "myFolder/",
"BufferingHints": {
"SizeInMBs": 123,
"IntervalInSeconds": 124,
},
"CompressionFormat": "UNCOMPRESSED",
2015-10-30 13:59:57 +00:00
},
2019-10-31 15:44:26 +00:00
},
2015-10-30 13:59:57 +00:00
}
2019-10-31 15:44:26 +00:00
],
"HasMoreDestinations": False,
}
)
2015-10-30 13:59:57 +00:00
@mock_kinesis
def test_create_s3_delivery_stream():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
2019-10-31 15:44:26 +00:00
response = create_s3_delivery_stream(client, "stream1")
stream_arn = response["DeliveryStreamARN"]
2019-10-31 15:44:26 +00:00
response = client.describe_delivery_stream(DeliveryStreamName="stream1")
stream_description = response["DeliveryStreamDescription"]
# Sure and Freezegun don't play nicely together
2019-10-31 15:44:26 +00:00
_ = stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal(
{
"DeliveryStreamName": "stream1",
"DeliveryStreamARN": stream_arn,
"DeliveryStreamStatus": "ACTIVE",
"VersionId": "string",
"Destinations": [
{
"DestinationId": "string",
"ExtendedS3DestinationDescription": {
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"BucketARN": "arn:aws:s3:::kinesis-test",
"Prefix": "myFolder/",
"CompressionFormat": "UNCOMPRESSED",
"DataFormatConversionConfiguration": {
"Enabled": True,
"InputFormatConfiguration": {
"Deserializer": {"HiveJsonSerDe": {}}
},
2019-10-31 15:44:26 +00:00
"OutputFormatConfiguration": {
"Serializer": {
"ParquetSerDe": {"Compression": "SNAPPY"}
}
},
"SchemaConfiguration": {
"DatabaseName": "stream1",
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"TableName": "outputTable",
},
},
},
2019-10-31 15:44:26 +00:00
}
],
"HasMoreDestinations": False,
}
)
@mock_kinesis
def test_create_stream_without_redshift():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
response = client.create_delivery_stream(
DeliveryStreamName="stream1",
S3DestinationConfiguration={
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(ACCOUNT_ID),
2019-10-31 15:44:26 +00:00
"BucketARN": "arn:aws:s3:::kinesis-test",
"Prefix": "myFolder/",
"BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124},
"CompressionFormat": "UNCOMPRESSED",
},
)
2019-10-31 15:44:26 +00:00
stream_arn = response["DeliveryStreamARN"]
2019-10-31 15:44:26 +00:00
response = client.describe_delivery_stream(DeliveryStreamName="stream1")
stream_description = response["DeliveryStreamDescription"]
# Sure and Freezegun don't play nicely together
2019-10-31 15:44:26 +00:00
_ = stream_description.pop("CreateTimestamp")
_ = stream_description.pop("LastUpdateTimestamp")
stream_description.should.equal(
{
"DeliveryStreamName": "stream1",
"DeliveryStreamARN": stream_arn,
"DeliveryStreamStatus": "ACTIVE",
"VersionId": "string",
"Destinations": [
{
"DestinationId": "string",
"S3DestinationDescription": {
2019-12-17 02:25:20 +00:00
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
"RoleARN": "arn:aws:iam::{}:role/firehose_delivery_role".format(
ACCOUNT_ID
),
2019-10-31 15:44:26 +00:00
"BucketARN": "arn:aws:s3:::kinesis-test",
"Prefix": "myFolder/",
"BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124},
"CompressionFormat": "UNCOMPRESSED",
},
}
2019-10-31 15:44:26 +00:00
],
"HasMoreDestinations": False,
}
)
2017-02-24 02:37:43 +00:00
@mock_kinesis
2020-01-20 23:21:11 +00:00
def test_deescribe_non_existent_stream():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
2017-02-24 02:37:43 +00:00
client.describe_delivery_stream.when.called_with(
2019-10-31 15:44:26 +00:00
DeliveryStreamName="not-a-stream"
).should.throw(ClientError)
2015-10-30 13:59:57 +00:00
@mock_kinesis
def test_list_and_delete_stream():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
create_redshift_delivery_stream(client, "stream1")
create_redshift_delivery_stream(client, "stream2")
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
set(client.list_delivery_streams()["DeliveryStreamNames"]).should.equal(
set(["stream1", "stream2"])
)
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
client.delete_delivery_stream(DeliveryStreamName="stream1")
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
set(client.list_delivery_streams()["DeliveryStreamNames"]).should.equal(
set(["stream2"])
)
2015-10-30 13:59:57 +00:00
@mock_kinesis
def test_put_record():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
create_redshift_delivery_stream(client, "stream1")
client.put_record(DeliveryStreamName="stream1", Record={"Data": "some data"})
2015-10-30 13:59:57 +00:00
@mock_kinesis
def test_put_record_batch():
2019-10-31 15:44:26 +00:00
client = boto3.client("firehose", region_name="us-east-1")
2015-10-30 13:59:57 +00:00
2019-10-31 15:44:26 +00:00
create_redshift_delivery_stream(client, "stream1")
2015-10-30 13:59:57 +00:00
client.put_record_batch(
2019-10-31 15:44:26 +00:00
DeliveryStreamName="stream1",
Records=[{"Data": "some data1"}, {"Data": "some data2"}],
2015-10-30 13:59:57 +00:00
)