File: test_stepfunctions_sns_integration.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 (38 lines) | stat: -rw-r--r-- 1,251 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
import json
from unittest import SkipTest

import boto3

from moto import mock_aws, settings
from moto.sns.models import sns_backends
from tests import DEFAULT_ACCOUNT_ID

from . import verify_execution_result


@mock_aws(config={"stepfunctions": {"execute_state_machine": True}})
def test_state_machine_calling_sns_publish():
    if not settings.TEST_DECORATOR_MODE:
        raise SkipTest("No point in testing this in ServerMode")
    sns = boto3.client("sns", "us-east-1")
    topic_arn = sns.create_topic(Name="mytopic")["TopicArn"]

    exec_input = {"TopicArn": topic_arn, "Message": "my msg"}

    expected_status = "SUCCEEDED"
    tmpl_name = "services/sns_publish"

    def _verify_result(client, execution, execution_arn):
        assert "stopDate" in execution
        assert json.loads(execution["input"]) == exec_input
        assert "MessageId" in json.loads(execution["output"])

        backend = sns_backends[DEFAULT_ACCOUNT_ID]["us-east-1"]
        topic = list(backend.topics.values())[0]
        notification = topic.sent_notifications[0]
        _, msg, _, _, _ = notification
        assert msg == "my msg"

    verify_execution_result(
        _verify_result, expected_status, tmpl_name, exec_input=json.dumps(exec_input)
    )