Commit 1711192a authored by Luna's avatar Luna 😻

tests.test_main: fix testing

parent 7bd8b456
......@@ -63,6 +63,9 @@ def make_app():
def set_blueprints(app_):
"""Set the blueprints for a given app instance"""
log.debug('blueprint setup')
bps = {
gateway: None,
auth: '/auth',
......@@ -91,6 +94,8 @@ def set_blueprints(app_):
suffix = suffix or ''
app_.register_blueprint(bp, url_prefix=f'/api/v6{suffix}')
log.debug('blueprint setup: OK')
app = make_app()
set_blueprints(app)
......@@ -148,6 +153,7 @@ async def app_set_ratelimit_headers(resp):
async def init_app_db(app):
"""Connect to databases"""
log.info('db connect')
app.db = await asyncpg.create_pool(**app.config['POSTGRES'])
......
......@@ -4,37 +4,48 @@ import os
import pytest
# this is very hacky.
sys.path.append(os.getcwd())
from run import make_app, init_app_db, init_app_managers, set_blueprints
from run import app as main_app, set_blueprints
@pytest.fixture(name='app')
def _test_app():
app = make_app()
set_blueprints(app)
def _test_app(unused_tcp_port):
set_blueprints(main_app)
loop = asyncio.get_event_loop()
loop.run_until_complete(init_app_db(app))
init_app_managers(app)
return app
# reassign an unused tcp port for websockets
# since the config might give a used one.
main_app.config['WS_PORT'] = unused_tcp_port
# make sure we're calling the before_serving hooks
loop.run_until_complete(main_app.startup())
return main_app
@pytest.fixture(name='test_cli')
def _test_cli(app):
"""Give a test client."""
return app.test_client()
@pytest.mark.asyncio
async def test_index(test_cli):
"""Test if the main index page works."""
resp = await test_cli.get('/')
assert resp.status_code == 200
assert (await resp.get_data()).decode() == 'hewwo'
@pytest.mark.asyncio
async def test_gw(test_cli):
resp = await test_cli.get('/api/v6/gateway/')
"""Test if the gateway route is sane."""
resp = await test_cli.get('/api/v6/gateway')
assert resp.status_code == 200
rjson = await resp.json()
rjson = await resp.json
assert isinstance(rjson, dict)
assert 'gateway' in rjson
assert isinstance(rjson['gateway'], str)
assert 'url' in rjson
assert isinstance(rjson['url'], str)
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