示例#1
0
def test_invalid_queue(set_environment):
    with pytest.raises(exceptions.InvalidConfigurationError):
        process_event(
            event=None,
            context=MockContext(function_name=config("FUNCTION_NAME")),
            paths=None,
            queue_type="badqueue",
        )
示例#2
0
    def test_process_event_sqs(self, set_environment, fixture_name, fixture):
        from dummy_lambda.func.main import Path, PATHS

        response = process_event(
            event=sqs_payload(fixture["payload"]),
            context=MockContext(function_name=config("FUNCTION_NAME")),
            path_enum=Path,
            paths=PATHS,
            queue_type=QueueType.SQS,
            debug=True,
        )
        emit_logs(response)
        for k, v in fixture["response"].items():
            assert response[k] == v
示例#3
0
def test_fail_catastrophically(set_environment):
    def _fail(**kwargs):
        raise exceptions.FailCatastrophically()

    with pytest.raises(exceptions.FailCatastrophically):
        process_event(
            event=[{
                "foo": "bar"
            }],
            context=MockContext(function_name=config("FUNCTION_NAME")),
            paths={"FAIL": [Action(functions=[_fail])]},
            queue_type=QueueType.RAW,
            default_path="FAIL",
        )
示例#4
0
    def test_process_event_autogenerate_path(self, set_environment,
                                             fixture_name, fixture):
        from dummy_lambda.func.main import PATHS

        # Simulate a PATHS dictionary where the user didn't define and use an enumeration.
        _PATHS = {
            str(path).split(".")[-1]:
            [a.copy() if isinstance(a, Action) else a for a in actions]
            for path, actions in deepcopy(PATHS).items()
        }

        response = process_event(
            event=raw_payload(fixture["payload"]),
            context=MockContext(function_name=config("FUNCTION_NAME")),
            paths=_PATHS,
            queue_type=QueueType.RAW,
            debug=True,
        )
        emit_logs(response)
        for k, v in fixture["response"].items():
            assert response[k] == v