Mercurial > public > tweet-analysis
comparison tests/unit/test_handler.py @ 0:cea9500dca25
first commit
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Tue, 14 Sep 2021 17:46:04 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cea9500dca25 |
---|---|
1 import json | |
2 | |
3 import pytest | |
4 | |
5 from hello_world import app | |
6 | |
7 | |
8 @pytest.fixture() | |
9 def apigw_event(): | |
10 """ Generates API GW Event""" | |
11 | |
12 return { | |
13 "body": '{ "test": "body"}', | |
14 "resource": "/{proxy+}", | |
15 "requestContext": { | |
16 "resourceId": "123456", | |
17 "apiId": "1234567890", | |
18 "resourcePath": "/{proxy+}", | |
19 "httpMethod": "POST", | |
20 "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", | |
21 "accountId": "123456789012", | |
22 "identity": { | |
23 "apiKey": "", | |
24 "userArn": "", | |
25 "cognitoAuthenticationType": "", | |
26 "caller": "", | |
27 "userAgent": "Custom User Agent String", | |
28 "user": "", | |
29 "cognitoIdentityPoolId": "", | |
30 "cognitoIdentityId": "", | |
31 "cognitoAuthenticationProvider": "", | |
32 "sourceIp": "127.0.0.1", | |
33 "accountId": "", | |
34 }, | |
35 "stage": "prod", | |
36 }, | |
37 "queryStringParameters": {"foo": "bar"}, | |
38 "headers": { | |
39 "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", | |
40 "Accept-Language": "en-US,en;q=0.8", | |
41 "CloudFront-Is-Desktop-Viewer": "true", | |
42 "CloudFront-Is-SmartTV-Viewer": "false", | |
43 "CloudFront-Is-Mobile-Viewer": "false", | |
44 "X-Forwarded-For": "127.0.0.1, 127.0.0.2", | |
45 "CloudFront-Viewer-Country": "US", | |
46 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | |
47 "Upgrade-Insecure-Requests": "1", | |
48 "X-Forwarded-Port": "443", | |
49 "Host": "1234567890.execute-api.us-east-1.amazonaws.com", | |
50 "X-Forwarded-Proto": "https", | |
51 "X-Amz-Cf-Id": "aaaaaaaaaae3VYQb9jd-nvCd-de396Uhbp027Y2JvkCPNLmGJHqlaA==", | |
52 "CloudFront-Is-Tablet-Viewer": "false", | |
53 "Cache-Control": "max-age=0", | |
54 "User-Agent": "Custom User Agent String", | |
55 "CloudFront-Forwarded-Proto": "https", | |
56 "Accept-Encoding": "gzip, deflate, sdch", | |
57 }, | |
58 "pathParameters": {"proxy": "/examplepath"}, | |
59 "httpMethod": "POST", | |
60 "stageVariables": {"baz": "qux"}, | |
61 "path": "/examplepath", | |
62 } | |
63 | |
64 | |
65 def test_lambda_handler(apigw_event, mocker): | |
66 | |
67 ret = app.lambda_handler(apigw_event, "") | |
68 data = json.loads(ret["body"]) | |
69 | |
70 assert ret["statusCode"] == 200 | |
71 assert "message" in ret["body"] | |
72 assert data["message"] == "hello world" | |
73 # assert "location" in data.dict_keys() |