1
1
import asyncio
2
2
import json
3
+ import pathlib
3
4
import pytest
4
5
import yaml
5
6
from os .path import join , dirname , abspath
@@ -101,7 +102,8 @@ def test_swagger_file_url(test_client, loop):
101
102
102
103
app = web .Application (loop = loop )
103
104
setup_swagger (app ,
104
- swagger_from_file = TESTS_PATH + "/data/example_swagger.yaml" )
105
+ swagger_from_file = TESTS_PATH + "/data/example_swagger.yaml" ,
106
+ json_only = True )
105
107
106
108
client = yield from test_client (app )
107
109
resp1 = yield from client .get ('/api/doc/swagger.json' )
@@ -117,7 +119,7 @@ def test_swagger_file_url(test_client, loop):
117
119
def test_partial_swagger_file (test_client , loop ):
118
120
app = web .Application (loop = loop )
119
121
app .router .add_route ('GET' , "/ping-partial" , ping_partial )
120
- setup_swagger (app )
122
+ setup_swagger (app , json_only = True )
121
123
122
124
client = yield from test_client (app )
123
125
resp1 = yield from client .get ('/api/doc/swagger.json' )
@@ -137,7 +139,8 @@ def test_custom_swagger(test_client, loop):
137
139
description = description ,
138
140
title = "Test Custom Title" ,
139
141
api_version = "1.0.0" ,
140
-
142
+
143
+ json_only = True )
141
144
142
145
client = yield from test_client (app )
143
146
resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -159,7 +162,8 @@ def test_swagger_home_decorator(test_client, loop):
159
162
title = "Test Custom Title" ,
160
163
api_version = "1.0.0" ,
161
164
162
- swagger_home_decor = lambda x : x )
165
+ swagger_home_decor = lambda x : x ,
166
+ json_only = True )
163
167
164
168
client = yield from test_client (app )
165
169
resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -181,7 +185,8 @@ def test_swagger_def_decorator(test_client, loop):
181
185
title = "Test Custom Title" ,
182
186
api_version = "1.0.0" ,
183
187
184
- swagger_def_decor = lambda x : x )
188
+ swagger_def_decor = lambda x : x ,
189
+ json_only = True )
185
190
186
191
client = yield from test_client (app )
187
192
resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -205,7 +210,8 @@ def test_swagger_info(test_client, loop, swagger_info):
205
210
description = "Test Custom Swagger"
206
211
setup_swagger (app ,
207
212
swagger_url = "/api/v1/doc" ,
208
- swagger_info = swagger_info )
213
+ swagger_info = swagger_info ,
214
+ json_only = True )
209
215
210
216
client = yield from test_client (app )
211
217
resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -221,7 +227,7 @@ def test_swagger_info(test_client, loop, swagger_info):
221
227
def test_undocumented_fn (test_client , loop ):
222
228
app = web .Application (loop = loop )
223
229
app .router .add_route ('GET' , "/undoc_ping" , undoc_ping )
224
- setup_swagger (app )
230
+ setup_swagger (app , json_only = True )
225
231
client = yield from test_client (app )
226
232
resp = yield from client .get ('/undoc_ping' )
227
233
assert resp .status == 200
@@ -235,7 +241,7 @@ def test_undocumented_fn(test_client, loop):
235
241
def test_class_view (test_client , loop ):
236
242
app = web .Application (loop = loop )
237
243
app .router .add_route ('*' , "/class_view" , ClassView )
238
- setup_swagger (app )
244
+ setup_swagger (app , json_only = True )
239
245
240
246
client = yield from test_client (app )
241
247
# GET
@@ -277,7 +283,7 @@ def test_class_view(test_client, loop):
277
283
def test_sub_app (test_client , loop ):
278
284
sub_app = web .Application (loop = loop )
279
285
sub_app .router .add_route ('*' , "/class_view" , ClassView )
280
- setup_swagger (sub_app , api_base_url = '/sub_app' )
286
+ setup_swagger (sub_app , api_base_url = '/sub_app' , json_only = True )
281
287
app = web .Application (loop = loop )
282
288
app .add_subapp (prefix = '/sub_app' , subapp = sub_app )
283
289
@@ -294,3 +300,22 @@ def test_sub_app(test_client, loop):
294
300
assert "/class_view" in result ['paths' ]
295
301
assert "get" in result ['paths' ]["/class_view" ]
296
302
assert "post" in result ['paths' ]["/class_view" ]
303
+
304
+
305
+ @asyncio .coroutine
306
+ def test_swagger_defined_paths (test_client , loop ):
307
+ app1 = web .Application (loop = loop )
308
+ setup_swagger (app1 , json_only = True )
309
+ urls1 = [r .get_info () for r in app1 .router .resources ()]
310
+ assert urls1 == [{'path' : '/api/doc/swagger.json' }]
311
+
312
+ app2 = web .Application (loop = loop )
313
+ setup_swagger (app2 )
314
+ urls2 = [r .get_info () for r in app2 .router .resources ()]
315
+ assert urls2 == [
316
+ {'path' : '/api/doc/swagger.json' },
317
+ {'path' : '/api/doc' },
318
+ {'path' : '/api/doc/' },
319
+ {'directory' : pathlib .Path ('aiohttp_swagger/swagger_ui' ).absolute (),
320
+ 'prefix' : '/api/doc/swagger_static' },
321
+ ]
0 commit comments