Commit 42698900 authored by Goran Pavlovic's avatar Goran Pavlovic
Browse files

Added few fixes, added tests

parent 066d800e
......@@ -42,7 +42,9 @@ Where to access to API Doc
By default, API will be generated at URL: :samp:`yourdomain.com/api/doc`.
You can modify the URI adding the parameter :samp:`swagger_url` in :samp:`setup_swagger`:
You can modify the URI adding the parameter :samp:`swagger_url` in :samp:`setup_swagger`.
You can specify UI version (Version 2 and 3 are supported) by adding the parameter :samp:`ui_version` in :samp:`ui_version`.
.. code-block:: python
......@@ -69,6 +71,6 @@ You can modify the URI adding the parameter :samp:`swagger_url` in :samp:`setup_
app = web.Application()
app.router.add_route('GET', "/ping", ping)
setup_swagger(app, swagger_url="/api/v1/doc") # <-- NEW Doc URI
setup_swagger(app, swagger_url="/api/v1/doc", ui_version=2) # <-- NEW Doc URI
web.run_app(app, host="127.0.0.1")
\ No newline at end of file
......@@ -8,6 +8,7 @@ from aiohttp import web
from aiohttp_swagger import *
async def ping(request):
"""
---
......@@ -104,6 +105,45 @@ async def test_ping(test_client, loop):
assert 'pong' in text
async def test_swagger_ui(test_client, loop):
TESTS_PATH = abspath(join(dirname(__file__)))
app = web.Application(loop=loop)
setup_swagger(app,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml")
client = await test_client(app)
resp1 = await client.get('/api/doc')
assert resp1.status == 200
retrieved = await resp1.text()
loaded = open(join(TESTS_PATH, "..", "aiohttp_swagger/swagger_ui/index.html")).read()
loaded = loaded.replace("##STATIC_PATH##", "/api/doc/swagger_static")
loaded = loaded.replace("##SWAGGER_CONFIG##", "/api/doc/swagger.json")
loaded = loaded.replace("##SWAGGER_VALIDATOR_URL##", '')
assert retrieved == loaded
async def test_swagger_ui3(test_client, loop):
TESTS_PATH = abspath(join(dirname(__file__)))
app = web.Application(loop=loop)
setup_swagger(app,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml",
ui_version=3
)
client = await test_client(app)
resp1 = await client.get('/api/doc')
assert resp1.status == 200
retrieved = await resp1.text()
loaded = open(join(TESTS_PATH, "..", "aiohttp_swagger/swagger_ui3/index.html")).read()
loaded = loaded.replace("##STATIC_PATH##", "/api/doc/swagger_static")
loaded = loaded.replace("##SWAGGER_CONFIG##", "/api/doc/swagger.json")
loaded = loaded.replace("##SWAGGER_VALIDATOR_URL##", '')
assert retrieved == loaded
async def test_swagger_file_url(test_client, loop):
TESTS_PATH = abspath(join(dirname(__file__)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment