-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
99 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
|
||
from bottle import Bottle, run | ||
from bottle import Bottle | ||
from bottle import run | ||
|
||
app = Bottle() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
from multiprocessing import Process | ||
from pathlib import Path | ||
|
||
import pytest | ||
from common import kwargs_list, mode_list, send_requests | ||
from common import kwargs_list | ||
from common import mode_list | ||
from sanic import Sanic | ||
from sanic import response | ||
from sanic_testing.testing import SanicTestClient | ||
|
||
|
||
def server_process(port, mode, **kwargs): | ||
from sanic import Sanic, response | ||
@pytest.fixture(scope="module") | ||
def app(): | ||
app = Sanic("test_sanic") | ||
return app | ||
|
||
app = Sanic(__name__) | ||
|
||
@pytest.mark.parametrize('mode', mode_list) | ||
@pytest.mark.parametrize('kwargs', kwargs_list) | ||
def test_sanic(app, port, mode, kwargs): | ||
# app = Sanic(f"server_{port}") | ||
|
||
@app.get(r'/hello/world') | ||
async def index_handler(request): | ||
return response.text('Hello World!!!') | ||
|
||
if kwargs["config_rel_url"]: | ||
@app.get(kwargs["config_rel_url"]) | ||
async def swagger_config_handler(request): | ||
return response.json(Path(kwargs["config_path"]).read_text()) | ||
|
||
if mode == 'auto': | ||
from swagger_ui import api_doc | ||
api_doc(app, **kwargs) | ||
else: | ||
from swagger_ui import sanic_api_doc | ||
sanic_api_doc(app, **kwargs) | ||
app.run(host='localhost', port=port) | ||
|
||
url_prefix = kwargs["url_prefix"] | ||
if url_prefix.endswith("/"): | ||
url_prefix = url_prefix[:-1] | ||
|
||
@pytest.mark.parametrize('mode', mode_list) | ||
@pytest.mark.parametrize('kwargs', kwargs_list) | ||
def test_sanic(port, mode, kwargs): | ||
proc = Process(target=server_process, args=(port, mode), kwargs=kwargs) | ||
proc.start() | ||
send_requests(port, mode, kwargs) | ||
proc.terminate() | ||
client = SanicTestClient(app) | ||
_, resp = client.get("/hello/world") | ||
# print(resp.text) | ||
assert resp.status == 200, resp.text | ||
|
||
_, resp = client.get(url_prefix) | ||
# print(resp.text) | ||
assert resp.status == 200, resp.text | ||
|
||
_, resp = client.get(f"{url_prefix}/static/LICENSE") | ||
# print(resp.text) | ||
assert resp.status == 200, resp.text | ||
|
||
if kwargs.get("editor"): | ||
_, resp = client.get(f"{url_prefix}/editor") | ||
# print(resp.text) | ||
assert resp.status == 200, resp.text | ||
else: | ||
_, resp = client.get(f"{url_prefix}/editor") | ||
# print(resp.text) | ||
assert resp.status == 404, resp.text | ||
|
||
_, resp = client.get(f"{url_prefix}/swagger.json") | ||
# print(resp.text) | ||
assert resp.status == 200, resp.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters