From 7b7520231177b909571979f8bd1ffea658525883 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Mon, 12 Nov 2018 04:10:31 -0300 Subject: [PATCH] tests: add basic test --- Pipfile | 2 +- Pipfile.lock | 8 ++++---- __init__.py | 0 run.py | 3 ++- tests/test_main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 __init__.py create mode 100644 tests/test_main.py diff --git a/Pipfile b/Pipfile index 6df5c34..fc2bac9 100644 --- a/Pipfile +++ b/Pipfile @@ -8,7 +8,7 @@ bcrypt = "==3.1.4" itsdangerous = "==0.24" asyncpg = "==0.16.0" websockets = "==6.0" -Quart = "==0.6.4" +Quart = "==0.6.9" Earl-ETF = "==2.1.2" logbook = "*" Cerberus = "==1.2" diff --git a/Pipfile.lock b/Pipfile.lock index fd3bdf1..47192c2 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "79cac6eb8d68f62bc18e7614f30098d2d4e5acdfcf4170cc1f95bd3abc6bea14" + "sha256": "fc9b7ad7152bf6e26291b295af92aa0a45e5140d7c87c543d769642b0c7c4919" }, "pipfile-spec": 6, "requires": { @@ -355,11 +355,11 @@ }, "quart": { "hashes": [ - "sha256:06ac9cfcc0387b596b1d81aeffd5ade1d48186d435760bbf43eeb4981d7c936c", - "sha256:419fcaf62052a45a0534e9f5ce94ca27ff5ba5577a1a8d41f561e9c839378884" + "sha256:cbb776a94168234a019ab432db86025d0b4dfe02d26378f7e618c7c2a9996ebe", + "sha256:d4e5fc3aed22f3a50be780e62cf35dfb4ba1c947692b86ab8b6744e915413786" ], "index": "pypi", - "version": "==0.6.4" + "version": "==0.6.9" }, "six": { "hashes": [ diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/run.py b/run.py index c1af61f..e5ec495 100644 --- a/run.py +++ b/run.py @@ -92,7 +92,6 @@ for bp, suffix in bps.items(): suffix = suffix or '' app.register_blueprint(bp, url_prefix=f'/api/v6{suffix}') - @app.before_request async def app_before_request(): await ratelimit_handler() @@ -188,6 +187,7 @@ async def app_before_serving(): ws_future = websockets.serve(_wrapper, host, port) await ws_future + log.info('started') @app.after_serving @@ -236,4 +236,5 @@ async def handle_500(err): @app.route('/') async def index(): + """sample index page.""" return 'hewwo' diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..d374c27 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,40 @@ +import asyncio +import sys +import os + +import pytest + +sys.path.append(os.getcwd()) + +from run import make_app, init_app_db, init_app_managers, set_blueprints + + +@pytest.fixture(name='app') +def _test_app(): + app = make_app() + set_blueprints(app) + loop = asyncio.get_event_loop() + loop.run_until_complete(init_app_db(app)) + init_app_managers(app) + return app + + +@pytest.fixture(name='test_cli') +def _test_cli(app): + return app.test_client() + + +@pytest.mark.asyncio +async def test_index(test_cli): + resp = await test_cli.get('/') + assert resp.status_code == 200 + + +@pytest.mark.asyncio +async def test_gw(test_cli): + resp = await test_cli.get('/api/v6/gateway/') + assert resp.status_code == 200 + rjson = await resp.json() + assert isinstance(rjson, dict) + assert 'gateway' in rjson + assert isinstance(rjson['gateway'], str)