From 0e0df4e3a6ede2e2099baa484fdab7b531a63433 Mon Sep 17 00:00:00 2001 From: Pacman Ghost Date: Wed, 7 Sep 2022 21:19:35 +1000 Subject: [PATCH] Tightened up some tests. --- conftest.py | 12 +++++++----- .../webapp/tests/control_tests_servicer.py | 13 +++++++++++++ vasl_templates/webapp/tests/test_html.py | 19 +++++++++++++++---- vasl_templates/webapp/tests/test_snippets.py | 6 +++--- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/conftest.py b/conftest.py index 7d6b961..f0d5176 100644 --- a/conftest.py +++ b/conftest.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 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vasl_templates/webapp/tests/control_tests_servicer.py b/vasl_templates/webapp/tests/control_tests_servicer.py index 98c633b..1d6e81c 100644 --- a/vasl_templates/webapp/tests/control_tests_servicer.py +++ b/vasl_templates/webapp/tests/control_tests_servicer.py @@ -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: diff --git a/vasl_templates/webapp/tests/test_html.py b/vasl_templates/webapp/tests/test_html.py index 458d95c..23b9972 100644 --- a/vasl_templates/webapp/tests/test_html.py +++ b/vasl_templates/webapp/tests/test_html.py @@ -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 "