-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathconftest.py
251 lines (187 loc) · 5.3 KB
/
conftest.py
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import json
import os
from pytest import fixture
from hypothesis import settings, HealthCheck
from chalice.app import Chalice
# From:
# http://hypothesis.readthedocs.io/en/latest/settings.html#settings-profiles
# On travis we'll have it run through more iterations.
from chalice.deploy import models
settings.register_profile(
'ci', settings(max_examples=2000,
suppress_health_check=[HealthCheck.too_slow]),
)
# When you're developing locally, we'll only run a few examples
# to keep unit tests fast. If you want to run more iterations
# locally just set HYPOTHESIS_PROFILE=ci.
settings.register_profile('dev', settings(max_examples=10))
settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'dev'))
print("HYPOTHESIS PROFILE: %s" % os.environ.get("HYPOTHESIS_PROFILE"))
@fixture(autouse=True)
def ensure_no_local_config(no_local_config):
pass
@fixture
def sample_app():
app = Chalice('sample')
@app.route('/')
def foo():
return {}
return app
@fixture
def sample_app_with_auth():
app = Chalice('sampleauth')
@app.authorizer('myauth')
def myauth(auth_request):
pass
@app.route('/', authorizer=myauth)
def foo():
return {}
return app
@fixture
def sample_app_schedule_only():
app = Chalice('schedule_only')
@app.schedule('rate(5 minutes)')
def cron(event):
pass
return app
@fixture
def sample_sqs_event_app():
app = Chalice('sqs-event')
@app.on_sqs_message(queue='myqueue')
def handler(event):
pass
return app
@fixture
def sample_kinesis_event_app():
app = Chalice('kinesis-event')
@app.on_kinesis_record(stream='mystream')
def handler(event):
pass
return app
@fixture
def sample_ddb_event_app():
app = Chalice('ddb-event')
@app.on_dynamodb_record(stream_arn='arn:aws:...:stream')
def handler(event):
pass
return app
@fixture
def sample_app_lambda_only():
app = Chalice('lambda_only')
@app.lambda_function()
def myfunction(event, context):
pass
return app
@fixture
def sample_websocket_app():
app = Chalice('sample')
@app.on_ws_connect()
def connect():
pass
@app.on_ws_message()
def message():
pass
@app.on_ws_disconnect()
def disconnect():
pass
return app
@fixture
def sample_s3_event_app():
app = Chalice('s3-event')
@app.on_s3_event(bucket='mybucket')
def handler(event):
pass
return app
@fixture
def sample_sns_event_app():
app = Chalice('sns-event')
@app.on_sns_message(topic='mytopic')
def handler(event):
pass
return app
@fixture
def sample_cloudwatch_event_app():
app = Chalice('cloudwatch-event')
@app.on_cw_event({'source': {'source': ['aws.ec2']}})
def foo(event):
return event
return app
@fixture
def create_event():
def create_event_inner(uri, method, path, content_type='application/json'):
return {
'requestContext': {
'httpMethod': method,
'resourcePath': uri,
},
'headers': {
'Content-Type': content_type,
},
'pathParameters': path,
'multiValueQueryStringParameters': None,
'body': "",
'stageVariables': {},
}
return create_event_inner
@fixture
def create_websocket_event():
def create_event_inner(
route_key, body='',
endpoint='abcd1234.execute-api.us-west-2.amazonaws.com'):
return {
'requestContext': {
'routeKey': route_key,
'domainName': endpoint,
'stage': 'api',
'connectionId': 'ABCD1234=',
'apiId': 'abcd1234',
},
'body': body,
}
return create_event_inner
@fixture
def create_empty_header_event():
def create_empty_header_event_inner(uri, method, path,
content_type='application/json'):
return {
'requestContext': {
'httpMethod': method,
'resourcePath': uri,
},
'headers': None,
'pathParameters': path,
'multiValueQueryStringParameters': None,
'body': "",
'stageVariables': {},
}
return create_empty_header_event_inner
@fixture
def create_event_with_body(create_event):
def create_event_with_body_inner(body, uri='/', method='POST',
content_type='application/json'):
event = create_event(uri, method, {}, content_type)
if content_type == 'application/json':
body = json.dumps(body)
event['body'] = body
return event
return create_event_with_body_inner
@fixture
def lambda_function():
return models.LambdaFunction(
resource_name='foo',
function_name='app-stage-foo',
deployment_package=None,
environment_variables={},
runtime='python2.7',
handler='app.app',
tags={},
timeout=None,
memory_size=None,
ephemeral_storage=None,
role=models.PreCreatedIAMRole(role_arn='foobar'),
security_group_ids=[],
subnet_ids=[],
layers=[],
reserved_concurrency=None,
xray=None,
)