-
-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathconftest.py
More file actions
186 lines (174 loc) · 6.62 KB
/
conftest.py
File metadata and controls
186 lines (174 loc) · 6.62 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
from __future__ import annotations
import os
from typing import Any
import pytest
@pytest.fixture
def mock_aws_api_gateway_event(request: pytest.FixtureRequest):
method = request.param[0]
body = request.param[1]
multi_value_query_parameters = request.param[2]
event: dict[str, Any] = {
"path": "/test/hello",
"body": body,
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, lzma, sdch, br",
"Accept-Language": "en-US,en;q=0.8",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Cookie": "cookie1; cookie2",
"Host": "test.execute-api.us-west-2.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"X-Forwarded-For": "192.168.100.1, 192.168.1.1",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https",
},
"pathParameters": {"proxy": "hello"},
"requestContext": {
"accountId": "123456789012",
"resourceId": "us4z18",
"stage": "Prod",
"requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9",
"identity": {
"cognitoIdentityPoolId": "",
"accountId": "",
"cognitoIdentityId": "",
"caller": "",
"apiKey": "",
"sourceIp": "192.168.100.1",
"cognitoAuthenticationType": "",
"cognitoAuthenticationProvider": "",
"userArn": "",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", # noqa: E501
"user": "",
},
"resourcePath": "/{proxy+}",
"httpMethod": method,
"apiId": "123",
},
"resource": "/{proxy+}",
"httpMethod": method,
"queryStringParameters": (
{k: v[0] for k, v in multi_value_query_parameters.items()} if multi_value_query_parameters else None
),
"multiValueQueryStringParameters": multi_value_query_parameters or None,
"stageVariables": {"stageVarName": "stageVarValue"},
}
return event
@pytest.fixture
def mock_http_api_event_v2(request: pytest.FixtureRequest):
method = request.param[0]
body = request.param[1]
multi_value_query_parameters = request.param[2]
query_string = request.param[3]
event = {
"version": "2.0",
"routeKey": "$default",
"rawPath": "/my/path",
"rawQueryString": query_string,
"cookies": ["cookie1", "cookie2"],
"headers": {
"accept-encoding": "gzip,deflate",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"host": "test.execute-api.us-west-2.amazonaws.com",
},
"queryStringParameters": (
{k: v[0] for k, v in multi_value_query_parameters.items()} if multi_value_query_parameters else None
),
"requestContext": {
"accountId": "123456789012",
"apiId": "api-id",
"authorizer": {
"jwt": {
"claims": {"claim1": "value1", "claim2": "value2"},
"scopes": ["scope1", "scope2"],
}
},
"domainName": "id.execute-api.us-east-1.amazonaws.com",
"domainPrefix": "id",
"http": {
"method": method,
"path": "/my/path",
"protocol": "HTTP/1.1",
"sourceIp": "192.168.100.1",
"userAgent": "agent",
},
"requestId": "id",
"routeKey": "$default",
"stage": "$default",
"time": "12/Mar/2020:19:03:58 +0000",
"timeEpoch": 1583348638390,
},
"body": body,
"pathParameters": {"parameter1": "value1"},
"isBase64Encoded": False,
"stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"},
}
return event
@pytest.fixture
def mock_http_api_event_v1(request: pytest.FixtureRequest):
method = request.param[0]
body = request.param[1]
multi_value_query_parameters = request.param[2]
query_string = request.param[3]
event = {
"version": "1.0",
"routeKey": "$default",
"rawPath": "/my/path",
"path": "/my/path",
"httpMethod": method,
"rawQueryString": query_string,
"cookies": ["cookie1", "cookie2"],
"headers": {
"accept-encoding": "gzip,deflate",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"host": "test.execute-api.us-west-2.amazonaws.com",
},
"queryStringParameters": (
{k: v[-1] for k, v in multi_value_query_parameters.items()} if multi_value_query_parameters else None
),
"multiValueQueryStringParameters": (
{k: v for k, v in multi_value_query_parameters.items()} if multi_value_query_parameters else None
),
"requestContext": {
"accountId": "123456789012",
"apiId": "api-id",
"authorizer": {
"jwt": {
"claims": {"claim1": "value1", "claim2": "value2"},
"scopes": ["scope1", "scope2"],
}
},
"domainName": "id.execute-api.us-east-1.amazonaws.com",
"domainPrefix": "id",
"http": {
"protocol": "HTTP/1.1",
"sourceIp": "192.168.100.1",
"userAgent": "agent",
},
"requestId": "id",
"routeKey": "$default",
"stage": "$default",
"time": "12/Mar/2020:19:03:58 +0000",
"timeEpoch": 1583348638390,
},
"body": body,
"pathParameters": {"parameter1": "value1"},
"isBase64Encoded": False,
"stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"},
}
return event
@pytest.fixture(scope="session", autouse=True)
def aws_credentials():
"""Mocked AWS Credentials for moto."""
os.environ["AWS_DEFAULT_REGION"] = "testing"
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SECURITY_TOKEN"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"