def test_config_problem(s3_event, mocker):
    client_mock = mocker.MagicMock()
    mocker.patch("lambdas.notification.handler.get_sfn_client", client_mock)

    # simulate config not found
    config_mock = mocker.MagicMock()
    config_mock.from_s3.side_effect = ValueError
    mocker.patch("lambdas.notification.handler.Config", config_mock)

    handler.notification(s3_event, None)

    # ensure it was handled correctly
    args, kwargs = client_mock().start_execution.call_args
    assert (json.loads(
        kwargs.get("input")).get("serviceError").get("Error") == "ValueError")
def test_config_file_problem(s3_event, mocker, caplog):
    config = Config()

    # an invalid configuration - default without any of the required keys
    config.config = {"Default": {}}

    # simulate invalid config
    config_mock = mocker.MagicMock()
    config_mock.from_s3.return_value = config
    mocker.patch("lambdas.notification.handler.Config", config_mock)

    client_mock = mocker.MagicMock()
    mocker.patch("lambdas.notification.handler.get_sfn_client", client_mock)

    handler.notification(s3_event, None)

    args, kwargs = client_mock().start_execution.call_args
    assert (json.loads(
        kwargs.get("input")).get("serviceError").get("Error") == "ConfigError")
def test_notification(mock_config, s3_event, mocker):
    # an invalid configuration - default without any of the required keys
    config = Config()
    config.config = {"my": {"name": "bob"}}

    # simulate invalid config
    config_mock = mocker.MagicMock()
    config_mock.from_s3.return_value = config
    mocker.patch("lambdas.notification.handler.Config", config_mock)

    mock_config = mock_config.return_value
    mock_config.from_s3.return_value = Config()

    client_mock = mocker.MagicMock()
    mocker.patch("lambdas.notification.handler.get_sfn_client", client_mock)

    handler.notification(s3_event, None)

    args, kwargs = client_mock().start_execution.call_args
    assert kwargs.get("stateMachineArn") == os.getenv("STATE_MACHINE_ARN")
    assert "test-key_target_time_series_" in kwargs.get("name")
    assert "input" in kwargs.keys()