@@ -28,44 +28,218 @@ def test_get_handler_error(self, handler):
28
28
with pytest .raises (ValueError ):
29
29
self .subject .get_handler ()
30
30
31
- @pytest .mark .parametrize (('verb' , 'path' , 'status' , 'message' ), [
32
- ('GET' , '/simple/' , 200 , 'OK' ),
33
- ('HEAD' , '/simple/' , 200 , 'OK' ),
34
- ('POST' , '/simple/' , 200 , 'OK' ),
31
+ @pytest .mark .parametrize (('event' , 'exp' ), [
32
+ (
33
+ {
34
+ 'version' : '1.0' ,
35
+ 'httpMethod' : 'GET' ,
36
+ 'path' : '/simple/' ,
37
+ },
38
+ EventProxy .jsonify ('GET' , 200 , message = 'OK' ),
39
+ ),
40
+ (
41
+ {
42
+ 'version' : '1.0' ,
43
+ 'httpMethod' : 'HEAD' ,
44
+ 'path' : '/simple/' ,
45
+ },
46
+ EventProxy .jsonify ('HEAD' , 200 , message = 'OK' ),
47
+ ),
48
+ (
49
+ {
50
+ 'version' : '1.0' ,
51
+ 'httpMethod' : 'POST' ,
52
+ 'path' : '/simple/' ,
53
+ 'body' : '{"fizz": "buzz"}' ,
54
+ },
55
+ EventProxy .jsonify ('POST' , 200 , message = 'OK' ),
56
+ ),
57
+ (
58
+ {
59
+ 'version' : '2.0' ,
60
+ 'rawPath' : '/simple/' ,
61
+ 'requestContext' : {
62
+ 'http' : {
63
+ 'method' : 'GET' ,
64
+ 'path' : '/simple/' ,
65
+ },
66
+ },
67
+ },
68
+ EventProxy .jsonify ('GET' , 200 , message = 'OK' ),
69
+ ),
70
+ (
71
+ {
72
+ 'version' : '2.0' ,
73
+ 'rawPath' : '/simple/' ,
74
+ 'requestContext' : {
75
+ 'http' : {
76
+ 'method' : 'HEAD' ,
77
+ 'path' : '/simple/' ,
78
+ },
79
+ },
80
+ },
81
+ EventProxy .jsonify ('HEAD' , 200 , message = 'OK' ),
82
+ ),
83
+ (
84
+ {
85
+ 'version' : '2.0' ,
86
+ 'rawPath' : '/simple/' ,
87
+ 'body' : '{"fizz": "buzz"}' ,
88
+ 'requestContext' : {
89
+ 'http' : {
90
+ 'method' : 'POST' ,
91
+ 'path' : '/simple/' ,
92
+ },
93
+ },
94
+ },
95
+ EventProxy .jsonify ('POST' , 200 , message = 'OK' ),
96
+ ),
35
97
])
36
- def test_invoke_success (self , verb , path , status , message ):
98
+ def test_invoke_success (self , event , exp ):
37
99
self .subject .get_handler = lambda : lambda event , context : exp
38
- exp = EventProxy .jsonify (verb , status , message = message )
39
- ret = self .subject .invoke ({'httpMethod' : verb , 'path' : path })
100
+ ret = self .subject .invoke (event )
40
101
assert ret == exp
41
102
42
- @pytest .mark .parametrize (('verb' , 'path' , 'status' , 'message' ), [
43
- ('GET' , '/simple/' , 502 , 'Internal server error' ),
44
- ('HEAD' , '/simple/' , 502 , 'Internal server error' ),
45
- ('POST' , '/simple/' , 502 , 'Internal server error' ),
46
- ('GET' , '/' , 403 , 'Forbidden' ),
47
- ('HEAD' , '/' , 403 , 'Forbidden' ),
48
- ('POST' , '/' , 403 , 'Forbidden' ),
103
+ @pytest .mark .parametrize (('event' , 'exp' ), [
104
+ (
105
+ {
106
+ 'version' : '2.0' ,
107
+ 'rawPath' : '/simple/' ,
108
+ 'requestContext' : {
109
+ 'http' : {
110
+ 'method' : 'GET' ,
111
+ 'path' : '/simple/' ,
112
+ },
113
+ },
114
+ },
115
+ EventProxy .jsonify ('GET' , 502 , message = 'Internal server error' ),
116
+ ),
117
+ (
118
+ {
119
+ 'version' : '2.0' ,
120
+ 'rawPath' : '/simple/' ,
121
+ 'requestContext' : {
122
+ 'http' : {
123
+ 'method' : 'HEAD' ,
124
+ 'path' : '/simple/' ,
125
+ },
126
+ },
127
+ },
128
+ EventProxy .jsonify ('HEAD' , 502 , message = 'Internal server error' ),
129
+ ),
130
+ (
131
+ {
132
+ 'version' : '2.0' ,
133
+ 'rawPath' : '/simple/' ,
134
+ 'requestContext' : {
135
+ 'http' : {
136
+ 'method' : 'POST' ,
137
+ 'path' : '/simple/' ,
138
+ },
139
+ },
140
+ },
141
+ EventProxy .jsonify ('POST' , 502 , message = 'Internal server error' ),
142
+ ),
143
+ (
144
+ {
145
+ 'version' : '2.0' ,
146
+ 'rawPath' : '/' ,
147
+ 'requestContext' : {
148
+ 'http' : {
149
+ 'method' : 'GET' ,
150
+ 'path' : '/' ,
151
+ },
152
+ },
153
+ },
154
+ EventProxy .jsonify ('GET' , 403 , message = 'Forbidden' ),
155
+ ),
156
+ (
157
+ {
158
+ 'version' : '2.0' ,
159
+ 'rawPath' : '/' ,
160
+ 'requestContext' : {
161
+ 'http' : {
162
+ 'method' : 'HEAD' ,
163
+ 'path' : '/' ,
164
+ },
165
+ },
166
+ },
167
+ EventProxy .jsonify ('HEAD' , 403 , message = 'Forbidden' ),
168
+ ),
169
+ (
170
+ {
171
+ 'version' : '2.0' ,
172
+ 'rawPath' : '/' ,
173
+ 'requestContext' : {
174
+ 'http' : {
175
+ 'method' : 'POST' ,
176
+ 'path' : '/' ,
177
+ },
178
+ },
179
+ },
180
+ EventProxy .jsonify ('POST' , 403 , message = 'Forbidden' ),
181
+ ),
49
182
])
50
- def test_invoke_error (self , verb , path , status , message ):
183
+ def test_invoke_error (self , event , exp ):
51
184
def handler (event , context ):
52
185
raise Exception ()
53
186
self .subject .get_handler = lambda : handler
54
- exp = EventProxy .jsonify (verb , status , message = message )
55
- ret = self .subject .invoke ({'httpMethod' : verb , 'path' : path })
187
+ ret = self .subject .invoke (event )
56
188
assert ret == exp
57
189
58
- @pytest .mark .parametrize (('verb' , 'path' , 'status' , 'message' ), [
59
- ('GET' , '/simple/' , 504 , 'Endpoint request timed out' ),
60
- ('HEAD' , '/simple/' , 504 , 'Endpoint request timed out' ),
61
- ('POST' , '/simple/' , 504 , 'Endpoint request timed out' ),
190
+ @pytest .mark .parametrize (('event' , 'exp' ), [
191
+ (
192
+ {
193
+ 'version' : '2.0' ,
194
+ 'rawPath' : '/simple/' ,
195
+ 'requestContext' : {
196
+ 'http' : {
197
+ 'method' : 'GET' ,
198
+ 'path' : '/simple/' ,
199
+ },
200
+ },
201
+ },
202
+ EventProxy .jsonify (
203
+ 'GET' , 504 ,
204
+ message = 'Endpoint request timed out' ,
205
+ ),
206
+ ),
207
+ (
208
+ {
209
+ 'version' : '2.0' ,
210
+ 'rawPath' : '/simple/' ,
211
+ 'requestContext' : {
212
+ 'http' : {
213
+ 'method' : 'HEAD' ,
214
+ 'path' : '/simple/' ,
215
+ },
216
+ },
217
+ },
218
+ EventProxy .jsonify ('HEAD' , 504 ),
219
+ ),
220
+ (
221
+ {
222
+ 'version' : '2.0' ,
223
+ 'rawPath' : '/simple/' ,
224
+ 'body' : '{"fizz": "buzz"}' ,
225
+ 'requestContext' : {
226
+ 'http' : {
227
+ 'method' : 'POST' ,
228
+ 'path' : '/simple/' ,
229
+ },
230
+ },
231
+ },
232
+ EventProxy .jsonify (
233
+ 'POST' , 504 ,
234
+ message = 'Endpoint request timed out' ,
235
+ ),
236
+ ),
62
237
])
63
- def test_invoke_timeout (self , verb , path , status , message ):
238
+ def test_invoke_timeout (self , event , exp ):
64
239
patch = 'lambda_gateway.event_proxy.EventProxy.invoke_async'
65
240
with mock .patch (patch ) as mock_invoke :
66
241
mock_invoke .side_effect = asyncio .TimeoutError
67
- exp = EventProxy .jsonify (verb , status , message = message )
68
- ret = self .subject .invoke ({'httpMethod' : verb , 'path' : path })
242
+ ret = self .subject .invoke (event )
69
243
assert ret == exp
70
244
71
245
@pytest .mark .parametrize (('verb' , 'statusCode' , 'body' , 'exp' ), [
0 commit comments