Tightened up some tests.

master
Pacman Ghost 2 years ago
parent d78ac34c1f
commit 0e0df4e3a6
  1. 12
      conftest.py
  2. 13
      vasl_templates/webapp/tests/control_tests_servicer.py
  3. 19
      vasl_templates/webapp/tests/test_html.py
  4. 6
      vasl_templates/webapp/tests/test_snippets.py

@ -70,6 +70,13 @@ def pytest_configure( config ):
import vasl_templates.webapp.tests
vasl_templates.webapp.tests.pytest_options = config.option
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@pytest.fixture( scope="session" )
def monkeypatch():
"""Override the default monkeypatch fixture."""
assert False, "Don't use monkeypatch!" # it won't work when testing against a remote server
# ---------------------------------------------------------------------
_webapp = None
@ -184,11 +191,6 @@ def _make_webapp():
elif _pytest_options.webdriver == "chrome":
app.config[ "WEBDRIVER_PATH" ] = "chromedriver"
# NOTE: Trumboyg adds a lot of buttons to the UI, which slows Selenium down a lot
# when it's searching for elements, so we run tests with a minimal configuration.
app.config[ "TRUMBOWYG_BUTTONS_VICTORY_CONDITIONS" ] = [ "viewHTML" ]
app.config[ "TRUMBOWYG_BUTTONS_SIMPLE_NOTE_DIALOG" ] = [ "viewHTML" ]
return app
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

@ -167,6 +167,19 @@ class ControlTestsServicer( BaseControlTestsServicer ): #pylint: disable=too-man
# detect problems there, as well as in the front-end), and enable them only when needed.
self.setAppConfigVal( SetAppConfigValRequest( key="_DISABLE_LANDING_CRAFT_", boolVal=True ), ctx )
# NOTE: Trumboyg adds a lot of buttons to the UI, which slows Selenium down a lot when
# searching for elements. We run tests with a minimal configuration, and tests that need
# specific buttons can override this.
self.setAppConfigVal( SetAppConfigValRequest( key="TRUMBOWYG_BUTTONS_VICTORY_CONDITIONS",
strVal='[ "viewHTML" ]' ), ctx
)
self.setAppConfigVal( SetAppConfigValRequest( key="TRUMBOWYG_BUTTONS_SIMPLE_NOTE_DIALOG",
strVal='[ "viewHTML" ]' ), ctx
)
self.setAppConfigVal( SetAppConfigValRequest( key="TRUMBOWTRUMBOWYG_BUTTONS_HTML_TEXTBOX_DIALOG",
strVal='[ "viewHTML" ]' ), ctx
)
# return our capabilities to the caller
caps = []
if _ORIG_CHAPTER_H_NOTES_DIR:

@ -80,16 +80,16 @@ def test_sanitize_load_scenario( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_sanitize_save_scenario( webapp, webdriver, monkeypatch ):
def test_sanitize_save_scenario( webapp, webdriver ):
"""Test sanitization of HTML content when saving scenarios."""
# initialize
monkeypatch.setitem( webapp.config, "TRUMBOWYG_TAG_BLACKLIST", "[]" )
webapp.control_tests.set_vo_notes_dir( "{TEST}" )
init_webapp( webapp, webdriver, no_sanitize_load=1, scenario_persistence=1 )
# load a scenario with unsafe content
load_scenario( _make_scenario_params( False ) )
_check_scenario_params()
# unload the scenario
params = save_scenario()
@ -153,13 +153,12 @@ def test_sanitize_save_scenario( webapp, webdriver, monkeypatch ):
# ---------------------------------------------------------------------
def test_sanitize_update_vsav( webapp, webdriver, monkeypatch ):
def test_sanitize_update_vsav( webapp, webdriver ):
"""Test sanitization of HTML content when updating a VASL save file."""
def do_test():
# initialize
monkeypatch.setitem( webapp.config, "TRUMBOWYG_TAG_BLACKLIST", "[]" )
webapp.control_tests \
.set_data_dir( "{REAL}" ) \
.set_vo_notes_dir( "{TEST}" )
@ -168,6 +167,7 @@ def test_sanitize_update_vsav( webapp, webdriver, monkeypatch ):
# load a scenario with unsafe content
load_scenario( _make_scenario_params( True ) )
_check_scenario_params()
# update the VSAV, then dump it
fname = os.path.join( os.path.split(__file__)[0], "fixtures/update-vsav/empty.vsav" )
@ -387,3 +387,14 @@ def _make_scenario_params( real_vo ):
} )
return params
def _check_scenario_params():
"""Check that the test scenario parameters were loaded correctly."""
# NOTE: We have to be careful when loading unsafe content into the UI, and make sure that it doesn't
# get sanitized as it is loaded. Loading unsafe content into an HTML textbox is not an issue, but
# for Trumbowyg controls (i.e. VICTORY_CONDITIONS), we have to consider its tag blacklist. However,
# this only kicks in when we switch between modes, so if we just load the raw content in, and don't
# switch modes, we should be OK.
elem = find_child( "div.html-textbox[name='SCENARIO_NAME']" )
assert "<script>" in elem.get_attribute( "innerHTML" )
assert "<applet>" in unload_trumbowyg( "VICTORY_CONDITIONS" )

@ -521,12 +521,12 @@ def test_snippet_images( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_player_flags_in_trumbowyg( webapp, webdriver, monkeypatch ):
def test_player_flags_in_trumbowyg( webapp, webdriver ):
"""Test inserting images for player flags into Trumbowyg HTML editor controls."""
# initialize
monkeypatch.setitem( webapp.config, "TRUMBOWYG_BUTTONS_VICTORY_CONDITIONS" ,
[ "flags", "viewHTML" ]
webapp.control_tests.set_app_config_val( "TRUMBOWYG_BUTTONS_VICTORY_CONDITIONS",
'[ "flags", "viewHTML" ]'
)
init_webapp( webapp, webdriver )

Loading…
Cancel
Save