1515#
1616
1717import json
18- import pytest
19-
18+ import asyncio
2019from fdk import constants
2120from fdk import event_handler
2221from fdk import fixtures
2322
2423from fdk .tests import funcs
2524
2625
27- @ pytest . mark . asyncio
28- async def test_override_content_type ():
29- call = await fixtures . setup_fn_call (
30- funcs . content_type )
31- content , status , headers = await call
26+ def test_override_content_type ():
27+ call = asyncio . run ( fixtures . setup_fn_call (
28+ funcs . content_type ))
29+
30+ content , status , headers = asyncio . run ( call )
3231
3332 assert 200 == status
3433 assert "OK" == content
@@ -39,49 +38,45 @@ async def test_override_content_type():
3938 constants .FN_FDK_VERSION ) == constants .VERSION_HEADER_VALUE
4039
4140
42- @pytest .mark .asyncio
43- async def test_parse_request_without_data ():
44- call = await fixtures .setup_fn_call (funcs .dummy_func )
41+ def test_parse_request_without_data ():
42+ call = asyncio .run (fixtures .setup_fn_call (funcs .dummy_func ))
4543
46- content , status , headers = await call
44+ content , status , headers = asyncio . run ( call )
4745 assert 200 == status
4846 assert "Hello World" == content
4947
5048
51- @pytest .mark .asyncio
52- async def test_parse_request_with_data ():
49+ def test_parse_request_with_data ():
5350 input_content = json .dumps (
5451 {"name" : "John" }).encode ("utf-8" )
55- call = await fixtures .setup_fn_call (
56- funcs .dummy_func , content = input_content )
57- content , status , headers = await call
52+ call = asyncio . run ( fixtures .setup_fn_call (
53+ funcs .dummy_func , content = input_content ))
54+ content , status , headers = asyncio . run ( call )
5855
5956 assert 200 == status
6057 assert "Hello John" == content
6158
6259
63- @pytest .mark .asyncio
64- async def test_custom_response_object ():
60+ def test_custom_response_object ():
6561 input_content = json .dumps (
6662 {"name" : "John" }).encode ("utf-8" )
67- call = await fixtures .setup_fn_call (
68- funcs .custom_response , input_content )
69- content , status , headers = await call
63+ call = asyncio . run ( fixtures .setup_fn_call (
64+ funcs .custom_response , input_content ))
65+ content , status , headers = asyncio . run ( call )
7066
7167 assert 201 == status
7268
7369
74- @pytest .mark .asyncio
75- async def test_encap_headers_gw ():
76- call = await fixtures .setup_fn_call (
70+ def test_encap_headers_gw ():
71+ call = asyncio .run (fixtures .setup_fn_call (
7772 funcs .encaped_header ,
7873 headers = {
7974 "custom-header-maybe" : "yo" ,
8075 "content-type" : "application/yo"
8176 },
8277 gateway = True ,
83- )
84- content , status , headers = await call
78+ ))
79+ content , status , headers = asyncio . run ( call )
8580
8681 # make sure that content type is not encaped, and custom header is
8782 # when coming out of the fdk
@@ -90,77 +85,70 @@ async def test_encap_headers_gw():
9085 assert "yo" in headers .get ("fn-http-h-custom-header-maybe" )
9186
9287
93- @pytest .mark .asyncio
94- async def test_encap_headers ():
95- call = await fixtures .setup_fn_call (
88+ def test_encap_headers ():
89+ call = asyncio .run (fixtures .setup_fn_call (
9690 funcs .encaped_header ,
9791 headers = {
9892 "custom-header-maybe" : "yo" ,
9993 "content-type" : "application/yo"
10094 }
101- )
102- content , status , headers = await call
95+ ))
96+ content , status , headers = asyncio . run ( call )
10397
10498 # make sure that custom header is not encaped out of fdk
10599 assert 200 == status
106100 assert "application/yo" in headers .get ("content-type" )
107101 assert "yo" in headers .get ("custom-header-maybe" )
108102
109103
110- @pytest .mark .asyncio
111- async def test_errored_func ():
112- call = await fixtures .setup_fn_call (funcs .expectioner )
113- content , status , headers = await call
104+ def test_errored_func ():
105+ call = asyncio .run (fixtures .setup_fn_call (funcs .expectioner ))
106+ content , status , headers = asyncio .run (call )
114107
115108 assert 502 == status
116109
117110
118- @pytest .mark .asyncio
119- async def test_none_func ():
120- call = await fixtures .setup_fn_call (funcs .none_func )
121- content , status , headers = await call
111+ def test_none_func ():
112+ call = asyncio .run (fixtures .setup_fn_call (funcs .none_func ))
113+ content , status , headers = asyncio .run (call )
122114
123115 assert 0 == len (content )
124116 assert 200 == status
125117
126118
127- @pytest .mark .asyncio
128- async def test_coro_func ():
129- call = await fixtures .setup_fn_call (funcs .coro )
130- content , status , headers = await call
119+ def test_coro_func ():
120+ call = asyncio .run (fixtures .setup_fn_call (funcs .coro ))
121+ content , status , headers = asyncio .run (call )
131122
132123 assert 200 == status
133124 assert 'hello from coro' == content
134125
135126
136- @pytest .mark .asyncio
137- async def test_default_enforced_response_code ():
127+ def test_default_enforced_response_code ():
138128 event_coro = event_handler .event_handle (
139129 fixtures .code (funcs .code404 ))
140130
141- http_resp = await event_coro (fixtures .fake_request (gateway = True ))
131+ http_resp = asyncio . run ( event_coro (fixtures .fake_request (gateway = True ) ))
142132
143133 assert http_resp .status == 200
144134 assert http_resp .headers .get (constants .FN_HTTP_STATUS ) == "404"
145135
146136
147- @pytest .mark .asyncio
148- async def test_enforced_response_codes_502 ():
137+ def test_enforced_response_codes_502 ():
149138 event_coro = event_handler .event_handle (
150139 fixtures .code (funcs .code502 ))
151140
152- http_resp = await event_coro (fixtures .fake_request (gateway = True ))
141+ http_resp = asyncio . run ( event_coro (fixtures .fake_request (gateway = True ) ))
153142
154143 assert http_resp .status == 502
155144 assert http_resp .headers .get (constants .FN_HTTP_STATUS ) == "502"
156145
157146
158- @pytest .mark .asyncio
159- async def test_enforced_response_codes_504 ():
147+ def test_enforced_response_codes_504 ():
160148 event_coro = event_handler .event_handle (
161149 fixtures .code (funcs .code504 ))
162150
163- http_resp = await event_coro (fixtures .fake_request (gateway = True ))
151+ http_resp = asyncio . run ( event_coro (fixtures .fake_request (gateway = True ) ))
164152
165153 assert http_resp .status == 504
166154 assert http_resp .headers .get (constants .FN_HTTP_STATUS ) == "504"
@@ -178,8 +166,7 @@ def test_log_frame_header(monkeypatch, capsys):
178166 assert "\n foo=12345\n " in captured .err
179167
180168
181- @pytest .mark .asyncio
182- async def test_request_url_and_method_set_with_gateway ():
169+ def test_request_url_and_method_set_with_gateway ():
183170 headers = {
184171 "fn-http-method" : "PUT" ,
185172 "fn-http-request-url" : "/foo-bar?baz" ,
@@ -188,11 +175,11 @@ async def test_request_url_and_method_set_with_gateway():
188175
189176 funcs .setup_context_capture ()
190177
191- call = await fixtures .setup_fn_call_raw (
178+ call = asyncio . run ( fixtures .setup_fn_call_raw (
192179 funcs .capture_request_ctx ,
193180 headers = headers
194- )
195- content , status , headers = await call
181+ ))
182+ content , status , headers = asyncio . run ( call )
196183 assert content == "OK"
197184
198185 ctx = funcs .get_captured_context ()
@@ -204,8 +191,7 @@ async def test_request_url_and_method_set_with_gateway():
204191 assert ctx .Headers ()["fn-http-h-not-aheader" ] == "nothttp"
205192
206193
207- @pytest .mark .asyncio
208- async def test_encap_request_headers_gateway ():
194+ def test_encap_request_headers_gateway ():
209195 headers = {
210196 "fn-intent" : "httprequest" ,
211197 "fn-http-h-my-header" : "foo" ,
@@ -214,13 +200,13 @@ async def test_encap_request_headers_gateway():
214200 }
215201
216202 funcs .setup_context_capture ()
217- call = await fixtures .setup_fn_call_raw (
203+ call = asyncio . run ( fixtures .setup_fn_call_raw (
218204 funcs .capture_request_ctx ,
219205 content = None ,
220206 headers = headers
221- )
207+ ))
222208
223- content , status , headers = await call
209+ content , status , headers = asyncio . run ( call )
224210
225211 assert content == 'OK'
226212
@@ -238,8 +224,7 @@ async def test_encap_request_headers_gateway():
238224 "funny-header" : ["baz" , "bob" ]}
239225
240226
241- @pytest .mark .asyncio
242- async def test_bytes_response ():
243- call = await fixtures .setup_fn_call (funcs .binary_result )
244- content , status , headers = await call
227+ def test_bytes_response ():
228+ call = asyncio .run (fixtures .setup_fn_call (funcs .binary_result ))
229+ content , status , headers = asyncio .run (call )
245230 assert content == bytes ([1 , 2 , 3 , 4 , 5 ])
0 commit comments