Skip to content

A pytest plugin for testing AWS Lambda integrations with Amazon APIGateway

License

Notifications You must be signed in to change notification settings

felixscherz/pytest-aws-apigateway

Repository files navigation

pytest-aws-apigateway

PyPI - Version PyPI - Python Version


Rationale

pytest_aws_apigateway is a pytest plugin to make testing AWS Lambda integrations with AWS ApiGateway easier. It registers AWS Lambda function handlers as callbacks to requests made using httpx so you can test your REST API using HTTP requests.

Usage

Add integrations

pytest-aws-apigateway lets you register AWS Lambda function handlers to act just like AWS ApiGateway proxy integrations.

import httpx
from pytest_aws_apigateway import ApiGatewayMock


def handler(event, context):
    return {"statusCode": 200, "body": json.dumps({"message": "Hello World!"})}

def test_hello_world(apigateway_mock: ApiGatewayMock):
    apigateway_mock.add_integration(
        "/", handler=handler, method="GET", endpoint="https://greetings/"
    )

    with httpx.Client() as client:
        resp = client.get("https://greetings/")
        assert resp.json() == {"message": "Hello World!"}

License

pytest-aws-apigateway is distributed under the terms of the MIT license.

About

A pytest plugin for testing AWS Lambda integrations with Amazon APIGateway

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages