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()
......@@ -148,6 +153,7 @@ async def app_set_ratelimit_headers(resp):
async def init_app_db(app):
"""Connect to databases"""'db connect')
app.db = await asyncpg.create_pool(**app.config['POSTGRES'])
......@@ -4,37 +4,48 @@ import os
import pytest
# this is very hacky.
from run import make_app, init_app_db, init_app_managers, set_blueprints
from run import app as main_app, set_blueprints
def _test_app():
app = make_app()
def _test_app(unused_tcp_port):
loop = asyncio.get_event_loop()
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
return main_app
def _test_cli(app):
"""Give a test client."""
return app.test_client()
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'
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