8
8
from aiohttp_swagger import *
9
9
10
10
11
- @asyncio .coroutine
12
- def ping (request ):
11
+ async def ping (request ):
13
12
"""
14
13
---
15
14
description: This end-point allow to test that service is up.
@@ -26,13 +25,11 @@ def ping(request):
26
25
return web .Response (text = "pong" )
27
26
28
27
29
- @asyncio .coroutine
30
- def undoc_ping (request ):
28
+ async def undoc_ping (request ):
31
29
return web .Response (text = "pong" )
32
30
33
31
34
- @asyncio .coroutine
35
- def users_with_data_def (request ):
32
+ async def users_with_data_def (request ):
36
33
"""
37
34
---
38
35
description: This endpoint returns user which is defined though data definition during initialization.
@@ -53,8 +50,7 @@ class ClassView(web.View):
53
50
def _irrelevant_method (self ):
54
51
pass
55
52
56
- @asyncio .coroutine
57
- def get (self ):
53
+ async def get (self ):
58
54
"""
59
55
---
60
56
description: Get resources
@@ -70,8 +66,7 @@ def get(self):
70
66
"""
71
67
return web .Response (text = "OK" )
72
68
73
- @asyncio .coroutine
74
- def post (self ):
69
+ async def post (self ):
75
70
"""
76
71
---
77
72
description: Post resources
@@ -87,64 +82,57 @@ def post(self):
87
82
"""
88
83
return web .Response (text = "OK" )
89
84
90
- @asyncio .coroutine
91
- def patch (self ):
85
+ async def patch (self ):
92
86
"""
93
87
This method is undocumented in the swagger sense.
94
88
"""
95
89
return web .Response (text = "OK" )
96
90
97
91
98
92
@swagger_path (abspath (join (dirname (__file__ ))) + '/data/partial_swagger.yaml' )
99
- @asyncio .coroutine
100
- def ping_partial (request ):
93
+ async def ping_partial (request ):
101
94
return web .Response (text = "pong" )
102
95
103
96
104
- @asyncio .coroutine
105
- def test_ping (test_client , loop ):
97
+ async def test_ping (test_client , loop ):
106
98
app = web .Application (loop = loop )
107
99
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' )
111
102
assert resp .status == 200
112
- text = yield from resp .text ()
103
+ text = await resp .text ()
113
104
assert 'pong' in text
114
105
115
106
116
- @asyncio .coroutine
117
- def test_swagger_file_url (test_client , loop ):
107
+ async def test_swagger_file_url (test_client , loop ):
118
108
TESTS_PATH = abspath (join (dirname (__file__ )))
119
109
120
110
app = web .Application (loop = loop )
121
111
setup_swagger (app ,
122
112
swagger_from_file = TESTS_PATH + "/data/example_swagger.yaml" )
123
113
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' )
126
116
assert resp1 .status == 200
127
- result = yield from resp1 .json ()
117
+ result = await resp1 .json ()
128
118
assert '/example1' in result ['paths' ]
129
119
assert '/example2' in result ['paths' ]
130
120
assert 'API Title' in result ['info' ]['title' ]
131
121
132
122
133
- @asyncio .coroutine
134
- def test_partial_swagger_file (test_client , loop ):
123
+ async def test_partial_swagger_file (test_client , loop ):
135
124
app = web .Application (loop = loop )
136
125
app .router .add_route ('GET' , "/ping-partial" , ping_partial )
137
126
setup_swagger (app )
138
127
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' )
141
130
assert resp1 .status == 200
142
- result = yield from resp1 .json ()
131
+ result = await resp1 .json ()
143
132
assert '/ping-partial' in result ['paths' ]
144
133
145
134
146
- @asyncio .coroutine
147
- def test_custom_swagger (test_client , loop ):
135
+ async def test_custom_swagger (test_client , loop ):
148
136
app = web .Application (loop = loop )
149
137
app .router .add_route ('GET' , "/ping" , ping )
150
138
description = "Test Custom Swagger"
@@ -155,16 +143,15 @@ def test_custom_swagger(test_client, loop):
155
143
api_version = "1.0.0" ,
156
144
157
145
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' )
160
148
assert resp1 .status == 200
161
- result = yield from resp1 .json ()
149
+ result = await resp1 .json ()
162
150
assert '/ping' in result ['paths' ]
163
151
assert 'Test Custom Title' in result ['info' ]['title' ]
164
152
165
153
166
- @asyncio .coroutine
167
- def test_swagger_home_decorator (test_client , loop ):
154
+ async def test_swagger_home_decorator (test_client , loop ):
168
155
app = web .Application (loop = loop )
169
156
app .router .add_route ('GET' , "/ping" , ping )
170
157
description = "Test Custom Swagger"
@@ -176,16 +163,15 @@ def test_swagger_home_decorator(test_client, loop):
176
163
177
164
swagger_home_decor = lambda x : x )
178
165
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' )
181
168
assert resp1 .status == 200
182
- result = yield from resp1 .json ()
169
+ result = await resp1 .json ()
183
170
assert '/ping' in result ['paths' ]
184
171
assert 'Test Custom Title' in result ['info' ]['title' ]
185
172
186
173
187
- @asyncio .coroutine
188
- def test_swagger_def_decorator (test_client , loop ):
174
+ async def test_swagger_def_decorator (test_client , loop ):
189
175
app = web .Application (loop = loop )
190
176
app .router .add_route ('GET' , "/ping" , ping )
191
177
description = "Test Custom Swagger"
@@ -197,10 +183,10 @@ def test_swagger_def_decorator(test_client, loop):
197
183
198
184
swagger_def_decor = lambda x : x )
199
185
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' )
202
188
assert resp1 .status == 200
203
- result = yield from resp1 .json ()
189
+ result = await resp1 .json ()
204
190
assert '/ping' in result ['paths' ]
205
191
assert 'Test Custom Title' in result ['info' ]['title' ]
206
192
@@ -211,128 +197,122 @@ def swagger_info():
211
197
return yaml .full_load (open (filename ).read ())
212
198
213
199
214
- @asyncio .coroutine
215
- def test_swagger_info (test_client , loop , swagger_info ):
200
+ async def test_swagger_info (test_client , loop , swagger_info ):
216
201
app = web .Application (loop = loop )
217
202
app .router .add_route ('GET' , "/ping" , ping )
218
203
description = "Test Custom Swagger"
219
204
setup_swagger (app ,
220
205
swagger_url = "/api/v1/doc" ,
221
206
swagger_info = swagger_info )
222
207
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' )
225
210
assert resp1 .status == 200
226
- result = yield from resp1 .json ()
211
+ result = await resp1 .json ()
227
212
assert '/example1' in result ['paths' ]
228
213
assert '/example2' in result ['paths' ]
229
214
assert 'API Title' in result ['info' ]['title' ]
230
215
231
216
232
- @asyncio .coroutine
233
- def test_undocumented_fn (test_client , loop ):
217
+ async def test_undocumented_fn (test_client , loop ):
234
218
app = web .Application (loop = loop )
235
219
app .router .add_route ('GET' , "/undoc_ping" , undoc_ping )
236
220
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' )
239
223
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' )
241
225
assert swagger_resp1 .status == 200
242
- result = yield from swagger_resp1 .json ()
226
+ result = await swagger_resp1 .json ()
243
227
assert not result ['paths' ]
244
228
245
229
246
- @asyncio .coroutine
247
- def test_wrong_method (test_client , loop ):
230
+ async def test_wrong_method (test_client , loop ):
248
231
app = web .Application (loop = loop )
249
232
app .router .add_route ('POST' , "/post_ping" , ping )
250
233
setup_swagger (app )
251
- client = yield from test_client (app )
234
+ client = await test_client (app )
252
235
# GET
253
- swagger_resp1 = yield from client .get ('/api/doc/swagger.json' )
236
+ swagger_resp1 = await client .get ('/api/doc/swagger.json' )
254
237
assert swagger_resp1 .status == 200
255
- result = yield from swagger_resp1 .json ()
238
+ result = await swagger_resp1 .json ()
256
239
assert "/post_ping" in result ['paths' ]
257
240
assert "post" in result ['paths' ]["/post_ping" ]
258
- resp = yield from client .get ('/post_ping' )
241
+ resp = await client .get ('/post_ping' )
259
242
assert resp .status == 405
260
243
261
244
262
- @asyncio .coroutine
263
- def test_class_view (test_client , loop ):
245
+ async def test_class_view (test_client , loop ):
264
246
app = web .Application (loop = loop )
265
247
app .router .add_route ('*' , "/class_view" , ClassView )
266
248
setup_swagger (app )
267
249
268
- client = yield from test_client (app )
250
+ client = await test_client (app )
269
251
# GET
270
- resp = yield from client .get ('/class_view' )
252
+ resp = await client .get ('/class_view' )
271
253
assert resp .status == 200
272
- text = yield from resp .text ()
254
+ text = await resp .text ()
273
255
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' )
275
257
assert swagger_resp1 .status == 200
276
- result = yield from swagger_resp1 .json ()
258
+ result = await swagger_resp1 .json ()
277
259
assert "/class_view" in result ['paths' ]
278
260
assert "get" in result ['paths' ]["/class_view" ]
279
261
assert "post" in result ['paths' ]["/class_view" ]
280
262
281
263
# POST
282
- resp = yield from client .post ('/class_view' )
264
+ resp = await client .post ('/class_view' )
283
265
assert resp .status == 200
284
- text = yield from resp .text ()
266
+ text = await resp .text ()
285
267
assert 'OK' in text
286
- result = yield from swagger_resp1 .json ()
268
+ result = await swagger_resp1 .json ()
287
269
assert "/class_view" in result ['paths' ]
288
270
assert "get" in result ['paths' ]["/class_view" ]
289
271
assert "post" in result ['paths' ]["/class_view" ]
290
272
291
273
# Undocumented PATCH
292
- resp = yield from client .patch ('/class_view' )
274
+ resp = await client .patch ('/class_view' )
293
275
assert resp .status == 200
294
- text = yield from resp .text ()
276
+ text = await resp .text ()
295
277
assert 'OK' in text
296
- result = yield from swagger_resp1 .json ()
278
+ result = await swagger_resp1 .json ()
297
279
assert "/class_view" in result ['paths' ]
298
280
assert "patch" not in result ['paths' ]["/class_view" ]
299
281
300
282
301
- @asyncio .coroutine
302
- def test_data_defs (test_client , loop ):
283
+ async def test_data_defs (test_client , loop ):
303
284
TESTS_PATH = abspath (join (dirname (__file__ )))
304
285
file = open (TESTS_PATH + "/data/example_data_definitions.json" )
305
286
app = web .Application (loop = loop )
306
287
app .router .add_route ('GET' , "/users" , users_with_data_def )
307
288
setup_swagger (app , definitions = json .loads (file .read ()))
308
289
file .close ()
309
290
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' )
312
293
assert swagger_resp1 .status == 200
313
- result = yield from swagger_resp1 .json ()
294
+ result = await swagger_resp1 .json ()
314
295
assert 'User' in result ['definitions' ]
315
296
assert 'Permission' in result ['definitions' ]
316
297
assert result ['definitions' ]['User' ]['properties' ]['permissions' ]['items' ]['$ref' ] is not None
317
298
318
299
319
- @asyncio .coroutine
320
- def test_sub_app (test_client , loop ):
300
+ async def test_sub_app (test_client , loop ):
321
301
sub_app = web .Application (loop = loop )
322
302
sub_app .router .add_route ('*' , "/class_view" , ClassView )
323
303
setup_swagger (sub_app , api_base_url = '/sub_app' )
324
304
app = web .Application (loop = loop )
325
305
app .add_subapp (prefix = '/sub_app' , subapp = sub_app )
326
306
327
- client = yield from test_client (app )
307
+ client = await test_client (app )
328
308
# GET
329
- resp = yield from client .get ('/sub_app/class_view' )
309
+ resp = await client .get ('/sub_app/class_view' )
330
310
assert resp .status == 200
331
- text = yield from resp .text ()
311
+ text = await resp .text ()
332
312
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' )
334
314
assert swagger_resp1 .status == 200
335
- result = yield from swagger_resp1 .json ()
315
+ result = await swagger_resp1 .json ()
336
316
assert "/class_view" in result ['paths' ]
337
317
assert "get" in result ['paths' ]["/class_view" ]
338
318
assert "post" in result ['paths' ]["/class_view" ]
0 commit comments