Make sure the tests start with no warnings or errors.

master
Pacman Ghost 3 years ago
parent 9ae6864262
commit 41476c80e5
  1. 24
      asl_rulebook2/webapp/tests/test_startup.py
  2. 18
      asl_rulebook2/webapp/tests/utils.py

@ -1,7 +1,6 @@
""" Test the startup process. """
from asl_rulebook2.webapp.tests.utils import init_webapp, \
wait_for_warning_msg, wait_for_error_msg, find_children
from asl_rulebook2.webapp.tests.utils import init_webapp, find_children
# ---------------------------------------------------------------------
@ -10,13 +9,11 @@ def test_load_content_docs( webapp, webdriver ):
# test handling of an invalid data directory
webapp.control_tests.set_data_dir( "_unknown_" )
init_webapp( webapp, webdriver )
wait_for_error_msg( 2, "Invalid data directory.", contains=True )
init_webapp( webapp, webdriver, errors=["Invalid data directory."] )
# test handling of an invalid index file
webapp.control_tests.set_data_dir( "invalid-index" )
init_webapp( webapp, webdriver )
wait_for_error_msg( 2, "Couldn't load \"test.index\".", contains=True )
init_webapp( webapp, webdriver, errors=["Couldn't load \"test.index\"."] )
# NOTE: If we can't load the index file, the content doc is useless and we don't load it at all.
# If any of the associated files are invalid, the content doc is loaded (i.e. a tab will be shown
# for it), and we degrade gracefully.
@ -24,14 +21,12 @@ def test_load_content_docs( webapp, webdriver ):
# test handling of an invalid targets file
webapp.control_tests.set_data_dir( "invalid-targets" )
init_webapp( webapp, webdriver )
wait_for_warning_msg( 2, "Couldn't load \"test.targets\".", contains=True )
init_webapp( webapp, webdriver, warnings=["Couldn't load \"test.targets\"."] )
assert len( find_children( "#content .tabbed-page" ) ) == 1
# test handling of an invalid footnotes file
webapp.control_tests.set_data_dir( "invalid-footnotes" )
init_webapp( webapp, webdriver )
wait_for_warning_msg( 2, "Couldn't load \"test.footnotes\".", contains=True )
init_webapp( webapp, webdriver, warnings=["Couldn't load \"test.footnotes\"."] )
assert len( find_children( "#content .tabbed-page" ) ) == 1
# ---------------------------------------------------------------------
@ -41,15 +36,12 @@ def test_init_search( webapp, webdriver ):
# test handling of an invalid search replacements file
webapp.control_tests.set_data_dir( "invalid-search-replacements" )
init_webapp( webapp, webdriver )
wait_for_warning_msg( 2, "Can't load user search replacements.", contains=True )
init_webapp( webapp, webdriver, warnings=["Can't load user search replacements."] )
# test handling of an invalid search aliases file
webapp.control_tests.set_data_dir( "invalid-search-aliases" )
init_webapp( webapp, webdriver )
wait_for_warning_msg( 2, "Can't load user search aliases.", contains=True )
init_webapp( webapp, webdriver, warnings=["Can't load user search aliases."] )
# test handling of an invalid search synonyms file
webapp.control_tests.set_data_dir( "invalid-search-synonyms" )
init_webapp( webapp, webdriver )
wait_for_warning_msg( 2, "Can't load user search synonyms.", contains=True )
init_webapp( webapp, webdriver, warnings=["Can't load user search synonyms."] )

@ -2,6 +2,8 @@
import sys
import os
import urllib.request
import json
import uuid
from selenium.webdriver.support.ui import WebDriverWait
@ -17,6 +19,10 @@ _webdriver = None
def init_webapp( webapp, webdriver, **options ):
"""Initialize the webapp."""
# initialize
expected_warnings = options.pop( "warnings", [] )
expected_errors = options.pop( "errors", [] )
# initialize
global _webapp, _webdriver
_webapp = webapp
@ -37,6 +43,18 @@ def init_webapp( webapp, webdriver, **options ):
webdriver.get( webapp.url_for( "main", **options ) )
_wait_for_webapp()
# make sure there were no errors or warnings
startup_msgs = json.load(
urllib.request.urlopen( webapp.url_for( "get_startup_msgs" ) )
)
errors = startup_msgs.pop( "error", [] )
errors = [ e[0] for e in errors ]
assert set( errors ) == set( expected_errors )
warnings = startup_msgs.pop( "warning", [] )
warnings = [ w[0] for w in warnings ]
assert set( warnings ) == set( expected_warnings )
assert not startup_msgs
# reset the user settings
webdriver.delete_all_cookies()

Loading…
Cancel
Save