parent
9b2bdac85b
commit
3778e181b9
@ -0,0 +1,22 @@ |
||||
""" Manage the startup process. """ |
||||
|
||||
from flask import jsonify |
||||
|
||||
from asl_articles import app |
||||
|
||||
_startup_msgs = { |
||||
"info": [], |
||||
"warning": [], |
||||
"error": [] |
||||
} |
||||
|
||||
# --------------------------------------------------------------------- |
||||
|
||||
@app.route( "/startup-messages" ) |
||||
def get_startup_msgs(): |
||||
"""Return any messages logged during startup.""" |
||||
return jsonify( _startup_msgs ) |
||||
|
||||
def log_startup_msg( msg_type, msg, *args, **kwargs ): |
||||
"""Log a startup message.""" |
||||
_startup_msgs[ msg_type ].append( msg.format( *args, **kwargs ) ) |
@ -0,0 +1,36 @@ |
||||
""" Test the startup process. """ |
||||
|
||||
import asl_articles.startup |
||||
|
||||
from asl_articles.tests.utils import init_tests, wait_for, find_child, set_toast_marker, check_toast |
||||
|
||||
# --------------------------------------------------------------------- |
||||
|
||||
def test_startup_messages( webdriver, flask_app, dbconn ): |
||||
"""Test startup messages.""" |
||||
|
||||
# initialize |
||||
init_tests( webdriver, flask_app, dbconn ) |
||||
startup_msgs = asl_articles.startup._startup_msgs #pylint: disable=protected-access |
||||
|
||||
def do_test( msg_type ): |
||||
|
||||
# check that the startup message was shown in the UI correctly |
||||
set_toast_marker( msg_type ) |
||||
assert startup_msgs[ msg_type ] == [] |
||||
asl_articles.startup.log_startup_msg( msg_type, "TEST: {}", msg_type ) |
||||
webdriver.refresh() |
||||
expected = startup_msgs[ msg_type ][0] |
||||
wait_for( 2, lambda: check_toast( msg_type, expected ) ) |
||||
startup_msgs[ msg_type ] = [] |
||||
|
||||
# check if the webapp started up or not |
||||
if msg_type == "error": |
||||
assert not find_child( "#search-form" ) |
||||
else: |
||||
assert find_child( "#search-form" ) |
||||
|
||||
# test each type of startup message |
||||
do_test( "info" ) |
||||
do_test( "warning" ) |
||||
do_test( "error" ) |
Loading…
Reference in new issue