File: test_http_destinations.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (83 lines) | stat: -rw-r--r-- 3,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import boto3

from moto import mock_aws
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from moto.moto_api._internal import mock_random

from .test_firehose_destination_types import create_http_delivery_stream

TEST_REGION = "us-west-1"


@mock_aws
def test_create_http_stream():
    """Verify fields of a HTTP delivery stream."""
    client = boto3.client("firehose", region_name=TEST_REGION)

    stream_name = f"stream_{mock_random.get_random_hex(6)}"
    response = create_http_delivery_stream(client, stream_name)
    stream_arn = response["DeliveryStreamARN"]

    response = client.describe_delivery_stream(DeliveryStreamName=stream_name)
    stream_description = response["DeliveryStreamDescription"]

    # Sure and Freezegun don't play nicely together
    stream_description.pop("CreateTimestamp")
    stream_description.pop("LastUpdateTimestamp")

    assert stream_description == {
        "DeliveryStreamName": stream_name,
        "DeliveryStreamARN": stream_arn,
        "DeliveryStreamStatus": "ACTIVE",
        "DeliveryStreamType": "DirectPut",
        "VersionId": "1",
        "Destinations": [
            {
                "DestinationId": "destinationId-000000000001",
                "HttpEndpointDestinationDescription": {
                    "EndpointConfiguration": {"Url": "google.com"},
                    "RetryOptions": {"DurationInSeconds": 100},
                    "BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124},
                    "CloudWatchLoggingOptions": {"Enabled": False},
                    "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",
                    },
                },
            }
        ],
        "HasMoreDestinations": False,
    }


@mock_aws
def test_update_s3_for_http_stream():
    """Verify fields of a HTTP delivery stream."""
    client = boto3.client("firehose", region_name=TEST_REGION)

    stream_name = f"stream_{mock_random.get_random_hex(6)}"
    create_http_delivery_stream(client, stream_name)

    stream = client.describe_delivery_stream(DeliveryStreamName=stream_name)
    version_id = stream["DeliveryStreamDescription"]["VersionId"]

    client.update_destination(
        DeliveryStreamName=stream_name,
        CurrentDeliveryStreamVersionId=version_id,
        DestinationId="destinationId-000000000001",
        HttpEndpointDestinationUpdate={"S3Update": {"ErrorOutputPrefix": "prefix2"}},
    )

    desc = client.describe_delivery_stream(DeliveryStreamName=stream_name)[
        "DeliveryStreamDescription"
    ]
    s3_desc = desc["Destinations"][0]["HttpEndpointDestinationDescription"][
        "S3DestinationDescription"
    ]
    assert s3_desc["ErrorOutputPrefix"] == "prefix2"