示例#1
0
async def test_async_sns_client_publish_dry_run():
    async_sns_client = AsyncSNSClient(dry_run=True)
    async_sns_client.client = asynctest.CoroutineMock()

    result = await async_sns_client.publish("sns_publisher", "test", {"message": True})

    assert result is None
    async_sns_client.client.publish.assert_not_called()
示例#2
0
async def test_async_sns_client_publish_client_error():
    async_sns_client = AsyncSNSClient()
    async_sns_client.aws_account_id = "123"
    async_sns_client.region_name = "us-east-1"
    client_error = ClientError({"Error": {"Code": "Eita Geovana", "Message": "Error"}}, "error")
    async_sns_client.client = mock.Mock(publish=asynctest.CoroutineMock(side_effect=client_error))

    with pytest.raises(SNSClientPublishError):
        await async_sns_client.publish("sns_publisher", "test", {"message": True})
示例#3
0
async def test_async_sns_client_publish():
    async_sns_client = AsyncSNSClient()
    async_sns_client.aws_account_id = "123"
    async_sns_client.client = mock.Mock(publish=asynctest.CoroutineMock())
    async_sns_client.region_name = "us-east-1"
    message = {"msg": True}

    result = await async_sns_client.publish("top", "ico", message, {"at": "tr"})

    assert result is True
    async_sns_client.client.publish.assert_called_once_with(
        TopicArn="arn:aws:sns:us-east-1:123:top__ico",
        MessageStructure="json",
        Message='{"default": "{\\"msg\\": true}"}',
        MessageAttributes={"at": {"DataType": "String", "StringValue": "tr"}},
    )
示例#4
0
async def test_async_sns_client_get_aws_account_id_custom_endpoint(monkeypatch):
    monkeypatch.delenv("AWS_ACCOUNT_ID", raising=False)
    async_sns_client = AsyncSNSClient(endpoint_url="http://hue.com/")

    result = await async_sns_client.get_aws_account_id()

    assert result == "000000000000"
示例#5
0
async def test_async_sns_client_get_aws_account_id_custom_endpoint_custom_account_id(
    async_sns_client, account_id, monkeypatch
):
    monkeypatch.setenv("AWS_ACCOUNT_ID", account_id)
    async_sns_client = AsyncSNSClient(endpoint_url="http://hue.com/")

    result = await async_sns_client.get_aws_account_id()

    assert result == account_id
示例#6
0
async def test_async_sns_client_get_aws_account_id():
    async_sns_client = AsyncSNSClient()
    async_sns_client._session.create_client = mock.Mock()
    mock_get_caller_identity = asynctest.CoroutineMock()
    async_sns_client._session.create_client.return_value.get_caller_identity = mock_get_caller_identity

    assert await async_sns_client.get_aws_account_id()

    async_sns_client._session.create_client.assert_called_once_with(
        "sts", endpoint_url=async_sns_client.endpoint_url, use_ssl=async_sns_client.use_ssl
    )
    mock_get_caller_identity.assert_called_once_with()
示例#7
0
def async_sns_client(request, event_loop):
    return AsyncSNSClient()