From a0fe6fbdcc600563c3a41d7b16616fdbd51a73df Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 18 Oct 2018 07:39:17 +0000 Subject: [PATCH] Tweaked how the tests check the clipboard. --- vasl_templates/webapp/tests/test_user_settings.py | 13 ++++++------- vasl_templates/webapp/tests/utils.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/vasl_templates/webapp/tests/test_user_settings.py b/vasl_templates/webapp/tests/test_user_settings.py index a34e882..95aad87 100644 --- a/vasl_templates/webapp/tests/test_user_settings.py +++ b/vasl_templates/webapp/tests/test_user_settings.py @@ -3,9 +3,8 @@ import json from vasl_templates.webapp.tests.utils import \ - init_webapp, find_child, _get_clipboard, \ - wait_for, wait_for_clipboard, select_tab, select_menu_option, click_dialog_button, \ - add_simple_note + init_webapp, find_child, wait_for_clipboard, \ + select_tab, select_menu_option, click_dialog_button, add_simple_note from vasl_templates.webapp.tests.test_vehicles_ordnance import add_vo from vasl_templates.webapp.config.constants import DATA_DIR as REAL_DATA_DIR @@ -44,7 +43,7 @@ def test_include_vasl_images_in_snippets( webapp, webdriver, monkeypatch ): # make sure that it took effect snippet_btn.click() - wait_for( 2, lambda: "/counter/2524/front" not in _get_clipboard() ) + wait_for_clipboard( 2, "/counter/2524/front", contains=False ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -91,13 +90,13 @@ def test_include_flags_in_snippets( webapp, webdriver, monkeypatch ): # make sure that it took effect ob_setup_snippet_btn.click() - wait_for( 2, lambda: "/flags/german" not in _get_clipboard() ) + wait_for_clipboard( 2, "/flags/german", contains=False ) # make sure it also affects vehicle/ordnance snippets ob_vehicles_snippet_btn.click() - wait_for( 2, lambda: "/flags/german" not in _get_clipboard() ) + wait_for_clipboard( 2, "/flags/german", contains=False ) ob_ordnance_snippet_btn.click() - wait_for( 2, lambda: "/flags/german" not in _get_clipboard() ) + wait_for_clipboard( 2, "/flags/german", contains=False ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vasl_templates/webapp/tests/utils.py b/vasl_templates/webapp/tests/utils.py index 327bddd..d68a8b9 100644 --- a/vasl_templates/webapp/tests/utils.py +++ b/vasl_templates/webapp/tests/utils.py @@ -426,7 +426,7 @@ def wait_for_elem( timeout, elem_id, parent=None ): wait_for( timeout, check_elem ) return args["elem"] -def wait_for_clipboard( timeout, expected, contains=False, transform=None ): +def wait_for_clipboard( timeout, expected, contains=None, transform=None ): """Wait for the clipboard to hold an expected value.""" args = { "last-clipboard": "" } def check_clipboard(): #pylint: disable=missing-docstring @@ -434,7 +434,14 @@ def wait_for_clipboard( timeout, expected, contains=False, transform=None ): args["last-clipboard"] = clipboard if transform: clipboard = transform( clipboard ) - return expected in clipboard if contains else expected == clipboard + if contains is None: + return expected == clipboard + elif contains is True: + return expected in clipboard + elif contains is False: + return expected not in clipboard + assert False + return False try: wait_for( timeout, check_clipboard ) return args["last-clipboard"]