Beispiel #1
0
def test_ping(test_client, loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', "/ping", ping)

    client = yield from test_client(app)
    resp = yield from client.get('/ping')
    assert resp.status == 200
    text = yield from resp.text()
    assert 'pong' in text
Beispiel #2
0
def test_partial_swagger_file(test_client, loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', "/ping-partial", ping_partial)
    setup_swagger(app)

    client = yield from test_client(app)
    resp1 = yield from client.get('/api/doc/swagger.json')
    assert resp1.status == 200
    text = yield from resp1.text()
    result = json.loads(text)
    assert '/ping-partial' in result['paths']
Beispiel #3
0
def test_undocumented_fn(test_client, loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', "/undoc_ping", undoc_ping)
    setup_swagger(app)
    client = yield from test_client(app)
    resp = yield from client.get('/undoc_ping')
    assert resp.status == 200
    swagger_resp1 = yield from client.get('/api/doc/swagger.json')
    assert swagger_resp1.status == 200
    text = yield from swagger_resp1.text()
    result = json.loads(text)
    assert not result['paths']
Beispiel #4
0
def test_swagger_file_url(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 = yield from test_client(app)
    resp1 = yield from client.get('/api/doc/swagger.json')
    assert resp1.status == 200
    text = yield from resp1.text()
    result = json.loads(text)
    assert '/example1' in result['paths']
    assert '/example2' in result['paths']
    assert 'API Title' in result['info']['title']
Beispiel #5
0
def test_swagger_info(test_client, loop, swagger_info):
    app = web.Application(loop=loop)
    app.router.add_route('GET', "/ping", ping)
    description = "Test Custom Swagger"
    setup_swagger(app,
                  swagger_url="/api/v1/doc",
                  swagger_info=swagger_info)

    client = yield from test_client(app)
    resp1 = yield from client.get('/api/v1/doc/swagger.json')
    assert resp1.status == 200
    text = yield from resp1.text()
    result = json.loads(text)
    assert '/example1' in result['paths']
    assert '/example2' in result['paths']
    assert 'API Title' in result['info']['title']
Beispiel #6
0
def test_custom_swagger(test_client, loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', "/ping", ping)
    description = "Test Custom Swagger"
    setup_swagger(app,
                  swagger_url="/api/v1/doc",
                  description=description,
                  title="Test Custom Title",
                  api_version="1.0.0",
                  contact="*****@*****.**")

    client = yield from test_client(app)
    resp1 = yield from client.get('/api/v1/doc/swagger.json')
    assert resp1.status == 200
    text = yield from resp1.text()
    result = json.loads(text)
    assert '/ping' in result['paths']
    assert 'Test Custom Title' in result['info']['title']
Beispiel #7
0
def test_sub_app(test_client, loop):
    sub_app = web.Application(loop=loop)
    sub_app.router.add_route('*', "/class_view", ClassView)
    setup_swagger(sub_app, api_base_url='/sub_app')
    app = web.Application(loop=loop)
    app.add_subapp(prefix='/sub_app', subapp=sub_app)

    client = yield from test_client(app)
    # GET
    resp = yield from client.get('/sub_app/class_view')
    assert resp.status == 200
    text = yield from resp.text()
    assert 'OK' in text
    swagger_resp1 = yield from client.get('/sub_app/api/doc/swagger.json')
    assert swagger_resp1.status == 200
    text = yield from swagger_resp1.text()
    result = json.loads(text)
    assert "/class_view" in result['paths']
    assert "get" in result['paths']["/class_view"]
    assert "post" in result['paths']["/class_view"]
Beispiel #8
0
def test_class_view(test_client, loop):
    app = web.Application(loop=loop)
    app.router.add_route('*', "/class_view", ClassView)
    setup_swagger(app)

    client = yield from test_client(app)
    # GET
    resp = yield from client.get('/class_view')
    assert resp.status == 200
    text = yield from resp.text()
    assert 'OK' in text
    swagger_resp1 = yield from client.get('/api/doc/swagger.json')
    assert swagger_resp1.status == 200
    text = yield from swagger_resp1.text()
    result = json.loads(text)
    assert "/class_view" in result['paths']
    assert "get" in result['paths']["/class_view"]
    assert "post" in result['paths']["/class_view"]

    # POST
    resp = yield from client.post('/class_view')
    assert resp.status == 200
    text = yield from resp.text()
    assert 'OK' in text
    text = yield from swagger_resp1.text()
    result = json.loads(text)
    assert "/class_view" in result['paths']
    assert "get" in result['paths']["/class_view"]
    assert "post" in result['paths']["/class_view"]

    # Undocumented PATCH
    resp = yield from client.patch('/class_view')
    assert resp.status == 200
    text = yield from resp.text()
    assert 'OK' in text
    text = yield from swagger_resp1.text()
    result = json.loads(text)
    assert "/class_view" in result['paths']
    assert "patch" not in result['paths']["/class_view"]