-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathmock_test_samplelambda.py
More file actions
32 lines (22 loc) · 999 Bytes
/
mock_test_samplelambda.py
File metadata and controls
32 lines (22 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
import json
from sys import path
import pytest
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
path.append("src/sampleCodeLayer/python")
path.append("src/sampleSchemaLayer/python")
from src.sampleLambda import app
@pytest.fixture()
def apigw_event() -> APIGatewayProxyEvent:
with open(f"events/unit-test-event.json") as f:
return APIGatewayProxyEvent(json.load(f))
def test_lambda_handler(apigw_event: dict, mocker) -> None:
mocker.patch("src.sampleLambda.app.get_s3_bucket_list_as_string",
return_value="bucket1|bucket2")
# call lambda function handler with synthetic event
test_response = app.lambda_handler(apigw_event, "")
test_response_data = test_response["body"].split("|")
assert test_response["statusCode"] == 200
assert "bucket1" in test_response_data
assert "bucket2" in test_response_data