예제 #1
0
파일: test_init.py 프로젝트: jcgoette/core
async def test_notify_credential_profile(hass):
    """Test notify service can use profile directly."""
    mock_session = MockAioSession()
    with async_patch("homeassistant.components.aws.AioSession",
                     return_value=mock_session), async_patch(
                         "homeassistant.components.aws.notify.AioSession",
                         return_value=mock_session):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "notify": [{
                        "service": "sqs",
                        "name": "SQS Test",
                        "region_name": "us-east-1",
                        "profile_name": "test",
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    assert hass.services.has_service("notify", "sqs_test") is True
    await hass.services.async_call("notify",
                                   "sqs_test", {
                                       "message": "test",
                                       "target": "ARN"
                                   },
                                   blocking=True)
예제 #2
0
파일: test_init.py 프로젝트: jcgoette/core
async def test_empty_credential(hass):
    """Test a default config will be create for empty credential section."""
    mock_session = MockAioSession()
    with async_patch("homeassistant.components.aws.AioSession",
                     return_value=mock_session):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "notify": [{
                        "service": "lambda",
                        "name": "New Lambda Test",
                        "region_name": "us-east-1",
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    assert hass.services.has_service("notify", "new_lambda_test") is True
    await hass.services.async_call("notify",
                                   "new_lambda_test", {
                                       "message": "test",
                                       "target": "ARN"
                                   },
                                   blocking=True)
    mock_session.invoke.assert_awaited_once()
예제 #3
0
async def test_empty_credential(hass):
    """Test a default config will be create for empty credential section."""
    with async_patch("aiobotocore.AioSession", new=MockAioSession):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "notify": [{
                        "service": "lambda",
                        "name": "New Lambda Test",
                        "region_name": "us-east-1",
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    sessions = hass.data[aws.DATA_SESSIONS]
    assert sessions is not None
    assert len(sessions) == 1
    session = sessions.get("default")
    assert isinstance(session, MockAioSession)

    assert hass.services.has_service("notify", "new_lambda_test") is True
    await hass.services.async_call("notify",
                                   "new_lambda_test", {
                                       "message": "test",
                                       "target": "ARN"
                                   },
                                   blocking=True)
    session.invoke.assert_awaited_once()
예제 #4
0
async def test_credential_skip_validate(hass):
    """Test credential can skip validate."""
    with async_patch("aiobotocore.AioSession", new=MockAioSession):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "credentials": [{
                        "name": "key",
                        "aws_access_key_id": "not-valid",
                        "aws_secret_access_key": "dont-care",
                        "validate": False,
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    sessions = hass.data[aws.DATA_SESSIONS]
    assert sessions is not None
    assert len(sessions) == 1
    session = sessions.get("key")
    assert isinstance(session, MockAioSession)
    session.get_user.assert_not_awaited()
예제 #5
0
async def test_notify_credential_profile(hass):
    """Test notify service can use profile directly."""
    with async_patch("aiobotocore.AioSession", new=MockAioSession):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "notify": [{
                        "service": "sqs",
                        "name": "SQS Test",
                        "region_name": "us-east-1",
                        "profile_name": "test",
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    sessions = hass.data[aws.DATA_SESSIONS]
    assert sessions is not None
    assert len(sessions) == 1
    assert isinstance(sessions.get("default"), MockAioSession)

    assert hass.services.has_service("notify", "sqs_test") is True
    await hass.services.async_call("notify",
                                   "sqs_test", {
                                       "message": "test",
                                       "target": "ARN"
                                   },
                                   blocking=True)
예제 #6
0
파일: test_init.py 프로젝트: jcgoette/core
async def test_empty_config(hass):
    """Test a default config will be create for empty config."""
    mock_session = MockAioSession()
    with async_patch("homeassistant.components.aws.AioSession",
                     return_value=mock_session):
        await async_setup_component(hass, "aws", {"aws": {}})
        await hass.async_block_till_done()

    # we don't validate auto-created default profile
    mock_session.get_user.assert_not_awaited()
예제 #7
0
async def test_empty_config(hass):
    """Test a default config will be create for empty config."""
    with async_patch("aiobotocore.AioSession", new=MockAioSession):
        await async_setup_component(hass, "aws", {"aws": {}})
        await hass.async_block_till_done()

    sessions = hass.data[aws.DATA_SESSIONS]
    assert sessions is not None
    assert len(sessions) == 1
    session = sessions.get("default")
    assert isinstance(session, MockAioSession)
    # we don't validate auto-created default profile
    session.get_user.assert_not_awaited()
예제 #8
0
async def test_access_key_credential(hass):
    """Test credentials with access key."""
    with async_patch("aiobotocore.AioSession", new=MockAioSession):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "credentials": [
                        {
                            "name": "test",
                            "profile_name": "test-profile"
                        },
                        {
                            "name": "key",
                            "aws_access_key_id": "test-key",
                            "aws_secret_access_key": "test-secret",
                        },
                    ],
                    "notify": [{
                        "service": "sns",
                        "credential_name": "key",
                        "name": "SNS Test",
                        "region_name": "us-east-1",
                    }],
                }
            },
        )
        await hass.async_block_till_done()

    sessions = hass.data[aws.DATA_SESSIONS]
    assert sessions is not None
    assert len(sessions) == 2
    session = sessions.get("key")
    assert isinstance(session, MockAioSession)

    assert hass.services.has_service("notify", "sns_test") is True
    await hass.services.async_call(
        "notify",
        "sns_test",
        {
            "title": "test",
            "message": "test",
            "target": "ARN"
        },
        blocking=True,
    )
    session.publish.assert_awaited_once()
예제 #9
0
파일: test_init.py 프로젝트: jcgoette/core
async def test_service_call_extra_data(hass):
    """Test service call extra data are parsed properly."""
    mock_session = MockAioSession()
    with async_patch("homeassistant.components.aws.AioSession",
                     return_value=mock_session):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "notify": [{
                        "service": "sns",
                        "name": "SNS Test",
                        "region_name": "us-east-1",
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    assert hass.services.has_service("notify", "sns_test") is True
    await hass.services.async_call(
        "notify",
        "sns_test",
        {
            "message": "test",
            "target": "ARN",
            "data": {
                "AWS.SNS.SMS.SenderID": "HA-notify"
            },
        },
        blocking=True,
    )
    mock_session.publish.assert_called_once_with(
        TargetArn="ARN",
        Message="test",
        Subject="Home Assistant",
        MessageAttributes={
            "AWS.SNS.SMS.SenderID": {
                "StringValue": "HA-notify",
                "DataType": "String"
            }
        },
    )
예제 #10
0
파일: test_init.py 프로젝트: jcgoette/core
async def test_access_key_credential(hass):
    """Test credentials with access key."""
    mock_session = MockAioSession()
    with async_patch("homeassistant.components.aws.AioSession",
                     return_value=mock_session):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "credentials": [
                        {
                            "name": "test",
                            "profile_name": "test-profile"
                        },
                        {
                            "name": "key",
                            "aws_access_key_id": "test-key",
                            "aws_secret_access_key": "test-secret",
                        },
                    ],
                    "notify": [{
                        "service": "sns",
                        "credential_name": "key",
                        "name": "SNS Test",
                        "region_name": "us-east-1",
                    }],
                }
            },
        )
        await hass.async_block_till_done()

    assert hass.services.has_service("notify", "sns_test") is True
    await hass.services.async_call(
        "notify",
        "sns_test",
        {
            "title": "test",
            "message": "test",
            "target": "ARN"
        },
        blocking=True,
    )
    mock_session.publish.assert_awaited_once()
예제 #11
0
파일: test_init.py 프로젝트: jcgoette/core
async def test_credential_skip_validate(hass):
    """Test credential can skip validate."""
    mock_session = MockAioSession()
    with async_patch("homeassistant.components.aws.AioSession",
                     return_value=mock_session):
        await async_setup_component(
            hass,
            "aws",
            {
                "aws": {
                    "credentials": [{
                        "name": "key",
                        "aws_access_key_id": "not-valid",
                        "aws_secret_access_key": "dont-care",
                        "validate": False,
                    }]
                }
            },
        )
        await hass.async_block_till_done()

    mock_session.get_user.assert_not_awaited()