|
5 | 5 |
|
6 | 6 | from hello_world import app
|
7 | 7 |
|
8 |
| - |
9 | 8 | @pytest.fixture()
|
10 | 9 | def apigw_event():
|
11 | 10 | """ Generates API GW Event"""
|
@@ -69,13 +68,24 @@ class Context:
|
69 | 68 | invoked_function_arn: str = "arn:aws:lambda:eu-west-1:298026489:function:test"
|
70 | 69 | aws_request_id: str = "5b441b59-a550-11c8-6564-f1c833cf438c"
|
71 | 70 |
|
72 |
| -def test_lambda_handler(apigw_event, mocker): |
73 |
| - |
74 |
| - |
| 71 | +def test_lambda_handler(apigw_event, mocker, capsys): |
75 | 72 | ret = app.lambda_handler(apigw_event, Context())
|
76 | 73 | data = json.loads(ret["body"])
|
77 | 74 |
|
| 75 | + output = capsys.readouterr() |
| 76 | + output = output.out.split('\n') |
| 77 | + stdout_one_string = '\t'.join(output) |
| 78 | + |
78 | 79 | assert ret["statusCode"] == 200
|
79 |
| - assert "message" in ret["body"] |
80 | 80 | assert data["message"] == "hello world"
|
81 |
| - # assert "location" in data.dict_keys() |
| 81 | + assert "location" in data |
| 82 | + assert "message" in ret["body"] |
| 83 | + |
| 84 | + # assess custom metric was flushed in stdout/logs |
| 85 | + assert "SuccessfulLocations" in stdout_one_string |
| 86 | + assert "ColdStart" in stdout_one_string |
| 87 | + assert "UniqueMetricDimension" in stdout_one_string |
| 88 | + |
| 89 | + # assess our custom middleware ran |
| 90 | + assert "Logging response after Handler is called" in stdout_one_string |
| 91 | + assert "Logging event before Handler is called" in stdout_one_string |
0 commit comments