88from aiohttp_swagger import *
99
1010
11- @asyncio .coroutine
12- def ping (request ):
11+ async def ping (request ):
1312 """
1413 ---
1514 description: This end-point allow to test that service is up.
@@ -26,13 +25,11 @@ def ping(request):
2625 return web .Response (text = "pong" )
2726
2827
29- @asyncio .coroutine
30- def undoc_ping (request ):
28+ async def undoc_ping (request ):
3129 return web .Response (text = "pong" )
3230
3331
34- @asyncio .coroutine
35- def users_with_data_def (request ):
32+ async def users_with_data_def (request ):
3633 """
3734 ---
3835 description: This endpoint returns user which is defined though data definition during initialization.
@@ -53,8 +50,7 @@ class ClassView(web.View):
5350 def _irrelevant_method (self ):
5451 pass
5552
56- @asyncio .coroutine
57- def get (self ):
53+ async def get (self ):
5854 """
5955 ---
6056 description: Get resources
@@ -70,8 +66,7 @@ def get(self):
7066 """
7167 return web .Response (text = "OK" )
7268
73- @asyncio .coroutine
74- def post (self ):
69+ async def post (self ):
7570 """
7671 ---
7772 description: Post resources
@@ -87,64 +82,57 @@ def post(self):
8782 """
8883 return web .Response (text = "OK" )
8984
90- @asyncio .coroutine
91- def patch (self ):
85+ async def patch (self ):
9286 """
9387 This method is undocumented in the swagger sense.
9488 """
9589 return web .Response (text = "OK" )
9690
9791
9892@swagger_path (abspath (join (dirname (__file__ ))) + '/data/partial_swagger.yaml' )
99- @asyncio .coroutine
100- def ping_partial (request ):
93+ async def ping_partial (request ):
10194 return web .Response (text = "pong" )
10295
10396
104- @asyncio .coroutine
105- def test_ping (test_client , loop ):
97+ async def test_ping (test_client , loop ):
10698 app = web .Application (loop = loop )
10799 app .router .add_route ('GET' , "/ping" , ping )
108-
109- client = yield from test_client (app )
110- resp = yield from client .get ('/ping' )
100+ client = await test_client (app )
101+ resp = await client .get ('/ping' )
111102 assert resp .status == 200
112- text = yield from resp .text ()
103+ text = await resp .text ()
113104 assert 'pong' in text
114105
115106
116- @asyncio .coroutine
117- def test_swagger_file_url (test_client , loop ):
107+ async def test_swagger_file_url (test_client , loop ):
118108 TESTS_PATH = abspath (join (dirname (__file__ )))
119109
120110 app = web .Application (loop = loop )
121111 setup_swagger (app ,
122112 swagger_from_file = TESTS_PATH + "/data/example_swagger.yaml" )
123113
124- client = yield from test_client (app )
125- resp1 = yield from client .get ('/api/doc/swagger.json' )
114+ client = await test_client (app )
115+ resp1 = await client .get ('/api/doc/swagger.json' )
126116 assert resp1 .status == 200
127- result = yield from resp1 .json ()
117+ result = await resp1 .json ()
128118 assert '/example1' in result ['paths' ]
129119 assert '/example2' in result ['paths' ]
130120 assert 'API Title' in result ['info' ]['title' ]
131121
132122
133- @asyncio .coroutine
134- def test_partial_swagger_file (test_client , loop ):
123+ async def test_partial_swagger_file (test_client , loop ):
135124 app = web .Application (loop = loop )
136125 app .router .add_route ('GET' , "/ping-partial" , ping_partial )
137126 setup_swagger (app )
138127
139- client = yield from test_client (app )
140- resp1 = yield from client .get ('/api/doc/swagger.json' )
128+ client = await test_client (app )
129+ resp1 = await client .get ('/api/doc/swagger.json' )
141130 assert resp1 .status == 200
142- result = yield from resp1 .json ()
131+ result = await resp1 .json ()
143132 assert '/ping-partial' in result ['paths' ]
144133
145134
146- @asyncio .coroutine
147- def test_custom_swagger (test_client , loop ):
135+ async def test_custom_swagger (test_client , loop ):
148136 app = web .Application (loop = loop )
149137 app .router .add_route ('GET' , "/ping" , ping )
150138 description = "Test Custom Swagger"
@@ -155,16 +143,15 @@ def test_custom_swagger(test_client, loop):
155143 api_version = "1.0.0" ,
156144 contact = "my.custom.contact@example.com" )
157145
158- client = yield from test_client (app )
159- resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
146+ client = await test_client (app )
147+ resp1 = await client .get ('/api/v1/doc/swagger.json' )
160148 assert resp1 .status == 200
161- result = yield from resp1 .json ()
149+ result = await resp1 .json ()
162150 assert '/ping' in result ['paths' ]
163151 assert 'Test Custom Title' in result ['info' ]['title' ]
164152
165153
166- @asyncio .coroutine
167- def test_swagger_home_decorator (test_client , loop ):
154+ async def test_swagger_home_decorator (test_client , loop ):
168155 app = web .Application (loop = loop )
169156 app .router .add_route ('GET' , "/ping" , ping )
170157 description = "Test Custom Swagger"
@@ -176,16 +163,15 @@ def test_swagger_home_decorator(test_client, loop):
176163 contact = "my.custom.contact@example.com" ,
177164 swagger_home_decor = lambda x : x )
178165
179- client = yield from test_client (app )
180- resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
166+ client = await test_client (app )
167+ resp1 = await client .get ('/api/v1/doc/swagger.json' )
181168 assert resp1 .status == 200
182- result = yield from resp1 .json ()
169+ result = await resp1 .json ()
183170 assert '/ping' in result ['paths' ]
184171 assert 'Test Custom Title' in result ['info' ]['title' ]
185172
186173
187- @asyncio .coroutine
188- def test_swagger_def_decorator (test_client , loop ):
174+ async def test_swagger_def_decorator (test_client , loop ):
189175 app = web .Application (loop = loop )
190176 app .router .add_route ('GET' , "/ping" , ping )
191177 description = "Test Custom Swagger"
@@ -197,10 +183,10 @@ def test_swagger_def_decorator(test_client, loop):
197183 contact = "my.custom.contact@example.com" ,
198184 swagger_def_decor = lambda x : x )
199185
200- client = yield from test_client (app )
201- resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
186+ client = await test_client (app )
187+ resp1 = await client .get ('/api/v1/doc/swagger.json' )
202188 assert resp1 .status == 200
203- result = yield from resp1 .json ()
189+ result = await resp1 .json ()
204190 assert '/ping' in result ['paths' ]
205191 assert 'Test Custom Title' in result ['info' ]['title' ]
206192
@@ -211,128 +197,122 @@ def swagger_info():
211197 return yaml .full_load (open (filename ).read ())
212198
213199
214- @asyncio .coroutine
215- def test_swagger_info (test_client , loop , swagger_info ):
200+ async def test_swagger_info (test_client , loop , swagger_info ):
216201 app = web .Application (loop = loop )
217202 app .router .add_route ('GET' , "/ping" , ping )
218203 description = "Test Custom Swagger"
219204 setup_swagger (app ,
220205 swagger_url = "/api/v1/doc" ,
221206 swagger_info = swagger_info )
222207
223- client = yield from test_client (app )
224- resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
208+ client = await test_client (app )
209+ resp1 = await client .get ('/api/v1/doc/swagger.json' )
225210 assert resp1 .status == 200
226- result = yield from resp1 .json ()
211+ result = await resp1 .json ()
227212 assert '/example1' in result ['paths' ]
228213 assert '/example2' in result ['paths' ]
229214 assert 'API Title' in result ['info' ]['title' ]
230215
231216
232- @asyncio .coroutine
233- def test_undocumented_fn (test_client , loop ):
217+ async def test_undocumented_fn (test_client , loop ):
234218 app = web .Application (loop = loop )
235219 app .router .add_route ('GET' , "/undoc_ping" , undoc_ping )
236220 setup_swagger (app )
237- client = yield from test_client (app )
238- resp = yield from client .get ('/undoc_ping' )
221+ client = await test_client (app )
222+ resp = await client .get ('/undoc_ping' )
239223 assert resp .status == 200
240- swagger_resp1 = yield from client .get ('/api/doc/swagger.json' )
224+ swagger_resp1 = await client .get ('/api/doc/swagger.json' )
241225 assert swagger_resp1 .status == 200
242- result = yield from swagger_resp1 .json ()
226+ result = await swagger_resp1 .json ()
243227 assert not result ['paths' ]
244228
245229
246- @asyncio .coroutine
247- def test_wrong_method (test_client , loop ):
230+ async def test_wrong_method (test_client , loop ):
248231 app = web .Application (loop = loop )
249232 app .router .add_route ('POST' , "/post_ping" , ping )
250233 setup_swagger (app )
251- client = yield from test_client (app )
234+ client = await test_client (app )
252235 # GET
253- swagger_resp1 = yield from client .get ('/api/doc/swagger.json' )
236+ swagger_resp1 = await client .get ('/api/doc/swagger.json' )
254237 assert swagger_resp1 .status == 200
255- result = yield from swagger_resp1 .json ()
238+ result = await swagger_resp1 .json ()
256239 assert "/post_ping" in result ['paths' ]
257240 assert "post" in result ['paths' ]["/post_ping" ]
258- resp = yield from client .get ('/post_ping' )
241+ resp = await client .get ('/post_ping' )
259242 assert resp .status == 405
260243
261244
262- @asyncio .coroutine
263- def test_class_view (test_client , loop ):
245+ async def test_class_view (test_client , loop ):
264246 app = web .Application (loop = loop )
265247 app .router .add_route ('*' , "/class_view" , ClassView )
266248 setup_swagger (app )
267249
268- client = yield from test_client (app )
250+ client = await test_client (app )
269251 # GET
270- resp = yield from client .get ('/class_view' )
252+ resp = await client .get ('/class_view' )
271253 assert resp .status == 200
272- text = yield from resp .text ()
254+ text = await resp .text ()
273255 assert 'OK' in text
274- swagger_resp1 = yield from client .get ('/api/doc/swagger.json' )
256+ swagger_resp1 = await client .get ('/api/doc/swagger.json' )
275257 assert swagger_resp1 .status == 200
276- result = yield from swagger_resp1 .json ()
258+ result = await swagger_resp1 .json ()
277259 assert "/class_view" in result ['paths' ]
278260 assert "get" in result ['paths' ]["/class_view" ]
279261 assert "post" in result ['paths' ]["/class_view" ]
280262
281263 # POST
282- resp = yield from client .post ('/class_view' )
264+ resp = await client .post ('/class_view' )
283265 assert resp .status == 200
284- text = yield from resp .text ()
266+ text = await resp .text ()
285267 assert 'OK' in text
286- result = yield from swagger_resp1 .json ()
268+ result = await swagger_resp1 .json ()
287269 assert "/class_view" in result ['paths' ]
288270 assert "get" in result ['paths' ]["/class_view" ]
289271 assert "post" in result ['paths' ]["/class_view" ]
290272
291273 # Undocumented PATCH
292- resp = yield from client .patch ('/class_view' )
274+ resp = await client .patch ('/class_view' )
293275 assert resp .status == 200
294- text = yield from resp .text ()
276+ text = await resp .text ()
295277 assert 'OK' in text
296- result = yield from swagger_resp1 .json ()
278+ result = await swagger_resp1 .json ()
297279 assert "/class_view" in result ['paths' ]
298280 assert "patch" not in result ['paths' ]["/class_view" ]
299281
300282
301- @asyncio .coroutine
302- def test_data_defs (test_client , loop ):
283+ async def test_data_defs (test_client , loop ):
303284 TESTS_PATH = abspath (join (dirname (__file__ )))
304285 file = open (TESTS_PATH + "/data/example_data_definitions.json" )
305286 app = web .Application (loop = loop )
306287 app .router .add_route ('GET' , "/users" , users_with_data_def )
307288 setup_swagger (app , definitions = json .loads (file .read ()))
308289 file .close ()
309290
310- client = yield from test_client (app )
311- swagger_resp1 = yield from client .get ('/api/doc/swagger.json' )
291+ client = await test_client (app )
292+ swagger_resp1 = await client .get ('/api/doc/swagger.json' )
312293 assert swagger_resp1 .status == 200
313- result = yield from swagger_resp1 .json ()
294+ result = await swagger_resp1 .json ()
314295 assert 'User' in result ['definitions' ]
315296 assert 'Permission' in result ['definitions' ]
316297 assert result ['definitions' ]['User' ]['properties' ]['permissions' ]['items' ]['$ref' ] is not None
317298
318299
319- @asyncio .coroutine
320- def test_sub_app (test_client , loop ):
300+ async def test_sub_app (test_client , loop ):
321301 sub_app = web .Application (loop = loop )
322302 sub_app .router .add_route ('*' , "/class_view" , ClassView )
323303 setup_swagger (sub_app , api_base_url = '/sub_app' )
324304 app = web .Application (loop = loop )
325305 app .add_subapp (prefix = '/sub_app' , subapp = sub_app )
326306
327- client = yield from test_client (app )
307+ client = await test_client (app )
328308 # GET
329- resp = yield from client .get ('/sub_app/class_view' )
309+ resp = await client .get ('/sub_app/class_view' )
330310 assert resp .status == 200
331- text = yield from resp .text ()
311+ text = await resp .text ()
332312 assert 'OK' in text
333- swagger_resp1 = yield from client .get ('/sub_app/api/doc/swagger.json' )
313+ swagger_resp1 = await client .get ('/sub_app/api/doc/swagger.json' )
334314 assert swagger_resp1 .status == 200
335- result = yield from swagger_resp1 .json ()
315+ result = await swagger_resp1 .json ()
336316 assert "/class_view" in result ['paths' ]
337317 assert "get" in result ['paths' ]["/class_view" ]
338318 assert "post" in result ['paths' ]["/class_view" ]
0 commit comments