def do_check_snippets( btn, date, expected, warning ): """Check that snippets are being generated correctly.""" # change the scenario date, check that the button is displayed correctly set_scenario_date( "{:02}/01/{:04}".format( date[1], date[0] ) ) select_tab( "ob1" ) classes = btn.get_attribute( "class" ) classes = classes.split() if classes else [] if warning: assert "inactive" in classes else: assert "inactive" not in classes # test snippet generation marker = set_stored_msg_marker( "_last-warning_" ) btn.click() wait_for_clipboard( 2, expected ) # check if a warning was issued last_warning = get_stored_msg( "_last-warning_" ) if warning: assert "are only available" in last_warning expected_image_url = "snippet-disabled.png" else: assert last_warning == marker expected_image_url = "snippet.png" wait_for( 2, lambda: expected_image_url in find_child( "img", btn ).get_attribute( "src" ) )
def _test_snippet(btn, params, expected, expected2): """Do a single test.""" # set the template parameters and generate the snippet set_template_params(params) marker = set_stored_msg_marker("_last-warning_") btn.click() def reformat(clipboard): #pylint: disable=missing-docstring lines = [l.strip() for l in clipboard.split("\n")] return " | ".join(l for l in lines if l) wait_for_clipboard(2, expected, transform=reformat) # check warnings for mandatory parameters last_warning = get_stored_msg("_last-warning_") if isinstance(expected2, list): # check for mandatory parameters param_names = ["scenario name", "scenario location", "scenario date"] for pname in param_names: if pname in expected2: assert pname in last_warning else: assert pname not in last_warning elif isinstance(expected2, str): # check for a specific error message assert expected2 == last_warning else: # make sure there was no warning message assert expected2 is None assert last_warning == marker
def check_snippet( width=None ): """Check the generated SSR snippet.""" generate_snippet_btn.click() val = "\n".join( "(*) [{}]".format(e) for e in expected ) if width: val += "\nwidth = [{}]".format( width ) wait_for_clipboard( 2, val, transform=lambda v: html.unescape(adjust_html(v)) )
def test_ma_notes(ma_note_q_present): #pylint: disable=missing-docstring expected = [("A", 'German Multi-Applicable Vehicle Note "A".')] if ma_note_q_present: expected.append(("Q", "Unavailable.")) btn = find_child("button[data-id='ob_vehicles_ma_notes_1']") btn.click() wait_for_clipboard(2, expected, transform=extract_ma_notes)
def _test_comments(nat, vo_type, vo_name, vals): """Generate and check comments for a series of dates.""" # load the specified vehicle/ordnance new_scenario() load_scenario({ "PLAYER_1": nat, "OB_{}_1".format(vo_type.upper()): [{ "name": vo_name }] }) # check the generated comments for each specified date for date, expected in vals: set_scenario_date(date) select_tab("ob1") btn = find_child("button[data-id='ob_{}_1']".format(vo_type)) btn.click() if expected.startswith("!"): expected, contains = expected[1:].strip(), False else: contains = True wait_for_clipboard(2, expected, transform=_extract_comments, contains=contains)
def test_template(template_id, orig_template_id): """Test uploading a customized version of the template.""" # upload a new template _ = upload_template_pack_file(template_id + ".j2", "UPLOADED TEMPLATE", False) # make sure generating a snippet returns the new version _ = _generate_snippet(webdriver, template_id, orig_template_id) wait_for_clipboard(2, "UPLOADED TEMPLATE")
def check_snippet(expected): """Generate and check the vehicle note snippet.""" sortable = find_child("#ob_vehicles-sortable_1") elems = find_children("li", sortable) assert len(elems) == 1 btn = find_child("img.snippet", elems[0]) btn.click() contains = True if isinstance(expected, str) else None wait_for_clipboard(2, expected, contains=contains)
def do_test( month, year, expected ): """Set the date and check the vehicle snippet.""" select_tab( "scenario" ) set_template_params( { "SCENARIO_DATE": "{:02d}/01/{}".format(month,year) } ) select_tab( "ob2" ) vehicles2.click() def reformat( clipboard ): #pylint: disable=missing-docstring mo = re.search( r"^- capabilities: (.*)$", clipboard, re.MULTILINE ) return mo.group( 1 ) wait_for_clipboard( 2, expected, transform=reformat )
def do_test(vehicles, expected): #pylint: disable=missing-docstring # add the specified vehicles new_scenario() set_player(1, "japanese") for veh in vehicles: add_vo(webdriver, "vehicles", 1, veh) # get the multi-applicable notes btn = find_child("button.generate[data-id='ob_vehicles_ma_notes_1']") btn.click() wait_for_clipboard(2, expected, transform=_extract_extn_ma_notes)
def test_extensions(webapp, webdriver): """Test handling of VASL counters in extensions.""" # initialize webapp.control_tests \ .set_data_dir( "{REAL}" ) \ .set_vasl_version( "random", "{REAL}" ) init_webapp(webapp, webdriver, scenario_persistence=1) # load the test scenario load_scenario({ "PLAYER_1": "russian", "OB_VEHICLES_1": [ { "id": "ru/v:078", "image_id": "f97:178/0" }, # Matilda II(b) (4FP variant) { "id": "ru/v:078", "image_id": "f97:184/0" }, # Matilda II(b) (6FP variant) { "id": "ru/v:004", "image_id": "547/0" }, # T-60 M40 (core module) { "id": "ru/v:004", "image_id": "f97:186/0" }, # T-60 M40 (KGS variant) ], }) # configure the user settings set_user_settings({ "scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET, "include-vasl-images-in-snippets": True, }) # generate a snippet for the vehicles select_tab("ob1") btn = find_child("button[data-id='ob_vehicles_1']") btn.click() wait_for_clipboard( 2, re.compile( '<img src="http://vasl-templates.org/.+/f97/matii2-4cmg.gif"' '.+' '<img src="http://vasl-templates.org/.+/f97/matii2-6cmg.gif"' '.+' '<img src="https://raw.githubusercontent.com/.+/ru/veh/T60M40.gif"' '.+' '<img src="http://vasl-templates.org/.+/f97/T60M40.gif"', re.DOTALL))
def do_test(snippet_id, expected1, expected2): #pylint: disable=missing-docstring # generate the snippet with online images enabled set_user_settings( {"scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET}) btn = find_child("button[data-id='{}']".format(snippet_id)) btn.click() wait_for_clipboard(2, expected1) # generate the snippet with online images disabled set_user_settings( {"scenario-images-source": SCENARIO_IMAGES_SOURCE_THIS_PROGRAM}) btn.click() wait_for_clipboard(2, expected2)
def test_multiple_images(webapp, webdriver): """Test handling of VASL counters that have multiple images.""" # initialize webapp.control_tests \ .set_data_dir( "{REAL}" ) \ .set_vasl_version( "random", None ) init_webapp(webapp, webdriver, scenario_persistence=1) # load the test scenario load_scenario({ "PLAYER_1": "british", "OB_VEHICLES_1": [{ "name": "2pdr Portee" }], }) # configure the user settings set_user_settings({ "scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET, "include-vasl-images-in-snippets": True, }) # generate a snippet for the vehicle (using the default image) select_tab("ob1") btn = find_child("button[data-id='ob_vehicles_1']") btn.click() wait_for_clipboard( 2, re.compile( r'<img src="https://raw.githubusercontent.com/.+/br/vehicles/portee.gif"' )) # select the second image for the vehicle sortable = find_child("#ob_vehicles-sortable_1") elems = find_children("li", sortable) assert len(elems) == 1 ActionChains(webdriver).double_click(elems[0]).perform() btn = wait_for_elem(2, "#edit-vo input.select-vo-image") btn.click() images = find_children(".ui-dialog.select-vo-image .vo-images img") assert len(images) == 2 images[1].click() click_dialog_button("OK") # generate a snippet for the vehicle (using the new image) btn = find_child("button[data-id='ob_vehicles_1']") btn.click() wait_for_clipboard( 2, re.compile( r'<img src="https://raw.githubusercontent.com/.+/br/vehicles/portee0.gif"' ))
def _check_vo_snippets(player_no, vo_type, expected): """Generate and check vehicle/ordnance snippets.""" select_tab("ob{}".format(player_no)) sortable = find_child("#ob_{}-sortable_{}".format(vo_type, player_no)) elems = find_children("li", sortable) assert len(elems) == len(expected) for i, elem in enumerate(elems): btn = find_child("img.snippet", elem) if expected[i]: btn.click() wait_for_clipboard(2, expected[i], transform=_extract_vo_note) else: assert btn is None
def check_scenario_date(expected): """Check the scenario date is being interpreted correctly.""" assert isinstance(expected, tuple) and len(expected) == 3 assert 1 <= expected[0] <= 31 and 1 <= expected[ 1] <= 12 and 1940 <= expected[2] <= 1945 # check the snippet snippet_btn.click() wait_for_clipboard( 2, "{}-{}-{}".format(expected[2], expected[0], expected[1])) # check the save file (should always be ISO-8601 format) saved_scenario = save_scenario() assert saved_scenario["SCENARIO_DATE"] == "{:04}-{:02}-{:02}".format( expected[2], expected[0], expected[1])
def test_extras_templates( webapp, webdriver ): """Test the extras templates.""" # initialize init_webapp( webapp, webdriver ) select_tab( "extras" ) # check that the extras templates were loaded correctly assert _get_extras_template_index() == [ ( "extras/minimal", None ), ( "Full template", "This is the caption." ), ( "select", None ), ] # check that the "full" template was loaded correctly _select_extras_template( webdriver, "extras/full" ) content = find_child( "#tabs-extras .right-panel" ) assert find_child( "div.name", content ).text == "Full template" assert find_child( "div.caption", content ).text == "This is the caption." assert find_child( "div.description", content ).text == "This is the description." params = find_children( "tr", content ) assert len(params) == 1 assert find_child( "td.caption", params[0] ).text == "The parameter:" textbox = find_child( "td.value input", params[0] ) assert textbox.get_attribute( "value" ) == "default-val" assert textbox.get_attribute( "size" ) == "10" assert textbox.get_attribute( "title" ) == "This is the parameter description." # generate the snippet snippet_btn = find_child( "button.generate", content ) snippet_btn.click() clipboard = wait_for_clipboard( 2, "param = default-val", contains=True ) assert "vasl-templates:comment" not in clipboard # nb: check that the comment was removed # check that the "minimal" template was loaded correctly _select_extras_template( webdriver, "extras/minimal" ) assert find_child( "div.name", content ).text == "extras/minimal" assert find_child( "div.caption", content ) is None assert find_child( "div.description", content ) is None params = find_children( "tr", content ) assert len(params) == 1 assert find_child( "td.caption", params[0] ).text == "PARAM:" textbox = find_child( "td.value input", params[0] ) assert textbox.get_attribute( "value" ) == "" # generate the snippet textbox.send_keys( "boo!" ) snippet_btn = find_child( "button.generate", content ) snippet_btn.click() clipboard = wait_for_clipboard( 2, "param = boo!", contains=True )
def do_test(player_no, nat, vo_type, vo_entries, expected): """Load the specified vehicles and check the resulting snippet.""" load_scenario({ "PLAYER_{}".format(player_no): nat, "OB_{}_{}".format(vo_type.upper(), player_no): [{ "name": v } for v in vo_entries], }) select_tab("ob{}".format(player_no)) btn = find_child("button.generate[data-id='ob_{}_ma_notes_{}']".format( vo_type, player_no)) btn.click() wait_for_clipboard(2, expected, transform=extract_ma_note_keys)
def test_template(template_id, orig_template_id): """Test editing a template.""" if template_id in ("scenario_note", "ob_setup", "ob_note"): return # nb: these require special handling (done below) if template_id in ("ob_vehicle_note", "ob_ordnance_note"): return # nb: we currently don't support editing these in the UI # edit the template elem = find_child( "a._edit-template-link_[data-id='{}']".format(template_id)) webdriver.execute_script("$(arguments[0]).click();", elem) edit_template(orig_template_id) # check that the new template is being used elem = find_child( "button.generate[data-id='{}']".format(orig_template_id)) elem.click() wait_for_clipboard(2, "EDITED TEMPLATE: {}".format(orig_template_id))
def check_snippet( sortable, entry_no, expected ): """Generate the snippet for an OB setup/note.""" elems = find_children( "li img.snippet", sortable ) elems[entry_no].click() if ob_type == "ob_notes": expected = re.sub( r" \(col=.*?\)", "", expected ) assert wait_for_clipboard( 2, expected, transform=adjust_html )
def test_vo_notes_image_cache(webapp, webdriver): """Test the vehicle/ordnance notes image cache.""" def init_test(): # initialize the webapp init_webapp(webapp, webdriver, scenario_persistence=1) _enable_vo_no_notes_as_images(True) # load the test scenario load_scenario({ "PLAYER_1": "japanese", "OB_VEHICLES_1": [ { "name": "japanese vehicle" }, ], }) # initialize webapp.control_tests.set_vo_notes_dir("{TEST}") init_test() # get the vehicle note snippet select_tab("ob1") elems = find_children("#ob_vehicles-sortable_1 li") assert len(elems) == 1 btn = find_child("img.snippet", elems[0]) btn.click() expected = ("japanese vehicle", "vehicles/japanese/note/2") snippet = wait_for_clipboard(2, expected, transform=_extract_vo_note) mo = re.search(r"<img src=\"(.+?)\">", snippet) url = mo.group(1) # get the vehicle note image (should be created) with urllib.request.urlopen(url) as resp: assert not resp.headers.get("X-WasCached") image_data = resp.read() # get the vehicle note image (should be re-created) with urllib.request.urlopen(url) as resp: assert not resp.headers.get("X-WasCached") assert resp.read() == image_data # enable image caching webapp.control_tests.set_app_config_val("VO_NOTES_IMAGE_CACHE_DIR", "{{TEMP_DIR}}") init_test() # get the vehicle note image (should be re-created) with urllib.request.urlopen(url) as resp: assert not resp.headers.get("X-WasCached") assert resp.read() == image_data # get the vehicle note image (should be cached) with urllib.request.urlopen(url) as resp: assert resp.headers.get("X-WasCached") assert resp.read() == image_data
def do_test(search_for, search_in, expected): """Test the IN operator.""" # install a new template elem = find_child( "a._edit-template-link_[data-id='victory_conditions']") webdriver.execute_script("$(arguments[0]).click();", elem) elem = find_child("#edit-template textarea") elem.clear() buf = [ "{%set HELLO_WORLD = \"Hello, world!\"%}", "{%set HELLO = \"hello\"%}", "{%if " + search_for + " in " + search_in + "%} YES {%else%} NO {%endif%}" ] template = "\n".join(buf) elem.send_keys(template) elem.send_keys(Keys.ESCAPE) # process the template elem = find_child("button.generate[data-id='victory_conditions']") elem.click() wait_for_clipboard(2, "YES" if expected else "NO")
def test_include_vasl_images_in_snippets(webapp, webdriver): """Test including VASL counter images in snippets.""" # initialize webapp.control_tests.set_data_dir("{REAL}") init_webapp(webapp, webdriver) set_user_settings( {"scenario-images-source": SCENARIO_IMAGES_SOURCE_THIS_PROGRAM}) # add a vehicle set_player(1, "german") add_vo(webdriver, "vehicles", 1, "PzKpfw IB") # enable "show VASL images in snippets" select_menu_option("user_settings") elem = find_child( ".ui-dialog.user-settings input[name='include-vasl-images-in-snippets']" ) assert not elem.is_selected() elem.click() click_dialog_button("OK") _check_cookies(webdriver, "include-vasl-images-in-snippets", True) # make sure that it took effect snippet_btn = find_child("button[data-id='ob_vehicles_1']") snippet_btn.click() wait_for_clipboard(2, "/counter/2524/front", contains=True) # disable "show VASL images in snippets" select_menu_option("user_settings") elem = find_child( ".ui-dialog.user-settings input[name='include-vasl-images-in-snippets']" ) assert elem.is_selected() elem.click() click_dialog_button("OK") _check_cookies(webdriver, "include-vasl-images-in-snippets", False) # make sure that it took effect snippet_btn.click() wait_for_clipboard(2, "/counter/2524/front", contains=False)
def test_edit_extras_template( webapp, webdriver ): """Test editing an extras templates.""" # initialize init_webapp( webapp, webdriver ) select_tab( "extras" ) # edit the "minimal" template _select_extras_template( webdriver, "extras/minimal" ) content = find_child( "#tabs-extras .right-panel" ) assert find_child( "div.caption", content ) is None webdriver.execute_script( "edit_template('extras/minimal')", content ) textarea = find_child( "#edit-template textarea" ) template = textarea.get_attribute( "value" ) \ .replace( "<html>", "<html>\n<!-- vasl-templates:caption Modified minimal. -->" ) \ .replace( "<div>", "<div>\nadded = {{ADDED:added-val}}" ) textarea.clear() textarea.send_keys( template ) textarea.send_keys( Keys.ESCAPE ) # generate the template (we should still be using the old template) snippet_btn = find_child( "button.generate", content ) snippet_btn.click() wait_for_clipboard( 2, "param =", contains=True ) # switch to another template, then back again _select_extras_template( webdriver, "extras/full" ) _select_extras_template( webdriver, "extras/minimal" ) # make sure the new template was loaded assert find_child( "div.caption", content ).text == "Modified minimal." params = find_children( "tr", content ) assert len(params) == 2 assert find_child( "td.caption", params[0] ).text == "ADDED:" textbox = find_child( "td.value input", params[0] ) assert textbox.get_attribute( "value" ) == "added-val" # generate the template (we should be using the new template) snippet_btn = find_child( "button.generate", content ) snippet_btn.click() wait_for_clipboard( 2, "added = added-val\nparam =", contains=True )
def do_test(enable_user_files): #pylint: disable=missing-docstring # initialize webapp.control_tests.set_user_files_dir( "user-files/" if enable_user_files else None) init_webapp(webapp, webdriver) # set the victory conditions elem = find_child("textarea[name='VICTORY_CONDITIONS']") elem.send_keys("my image: {{USER_FILES}}/subdir/placeholder.png") btn = find_child("button.generate[data-id='victory_conditions']") btn.click() def get_user_file_url(clipboard): #pylint: disable=missing-docstring # nb: the test template wraps {{VICTORY_CONDITIONS}} in square brackets :-/ mo = re.search(r"http://.+?/([^]]+)", clipboard) return "/" + mo.group(1) wait_for_clipboard(2, "/user/subdir/placeholder.png", transform=get_user_file_url)
def test_droplists( webapp, webdriver ): """Test droplist's in extras templates.""" # initialize init_webapp( webapp, webdriver ) select_tab( "extras" ) # load the "droplist" template _select_extras_template( webdriver, "extras/droplist" ) content = find_child( "#tabs-extras .right-panel" ) params = find_children( "tr", content ) assert len(params) == 1 sel = Select( find_child( "td.value select", params[0] ) ) vals = get_droplist_vals( sel ) assert vals == [ ("item 1","item 1"), ("item 2","item 2"), ("item 3","item 3") ] # generate the snippet for each droplist choice for i in range(1,3+1): select_droplist_val( sel, "item {}".format(i) ) snippet_btn = find_child( "button.generate", content ) snippet_btn.click() wait_for_clipboard( 2, "Selected: item {}".format(i) )
def test_special_cases(webapp, webdriver): """Test special cases.""" # initialize webapp.control_tests.set_vo_notes_dir("{TEST}") init_webapp(webapp, webdriver, scenario_persistence=1) # check that Italian Multi-Applicable Ordnance (only) Note R has a line-through load_scenario({ "PLAYER_1": "italian", "OB_ORDNANCE_1": [{ "name": "Cannone-aa da 90/53" }], "OB_VEHICLES_1": [{ "name": "SMV L40 47/32" }], }) select_tab("ob1") btn = find_child("button.generate[data-id='ob_ordnance_ma_notes_1']") btn.click() wait_for_clipboard(2, ["N", "<s>R</s>"], transform=extract_ma_note_keys) btn = find_child("button.generate[data-id='ob_vehicles_ma_notes_1']") btn.click() wait_for_clipboard(2, ["N", "R"], transform=extract_ma_note_keys)
def _check_snippet( vo_type, player_no ): """Check the generated vehicle/ordnance snippet.""" # check the snippet select_tab( "ob{}".format( player_no ) ) btn = find_child( "button[data-id='ob_{}_{}']".format( vo_type, player_no ) ) btn.click() def reformat( clipboard ): #pylint: disable=missing-docstring return [ mo.group(1) for mo in re.finditer( r"^\[\*\] (.*):" , clipboard, re.MULTILINE ) ] clipboard = wait_for_clipboard( 2, _expected[(vo_type,player_no)], transform=reformat ) # check the snippet width expected = _width[ (vo_type,player_no) ] mo = re.search( r"width={}$".format( expected if expected else "" ), clipboard, re.MULTILINE ) assert mo
def do_test( vo_type ): """Run the test.""" vo_type0 = vo_type[:-1] if vo_type.endswith("s") else vo_type # test a full example add_vo( webdriver, vo_type, 1, "a german {}".format(vo_type0) ) btn = find_child( "button[data-id='ob_{}_1']".format( vo_type ) ) btn.click() caps = '"XYZ" "IR" "A1" "H2"' if vo_type == "vehicles": caps += ' "CS 5"' expected = [ '[German] ; width=', '[*] a german {}: #=1'.format( vo_type0 ), '- notes: "A" "B†"', '- capabilities: {}'.format( caps ), '- raw capabilities: {}'.format( caps ), ] wait_for_clipboard( 2, "\n".join(expected) ) delete_vo( vo_type, 1, "a german {}".format(vo_type0), webdriver ) # test a partial example add_vo( webdriver, vo_type, 1, "another german {}".format(vo_type0) ) btn = find_child( "button[data-id='ob_{}_1']".format( vo_type ) ) btn.click() caps = '"XYZ"' if vo_type == "vehicles": caps += ' "<span class=\'brewup\'>cs 4</span>"' expected = [ '[German] ; width=', '[*] another german {}: #=2'.format( vo_type0 ), '- capabilities: {}'.format( caps ), '- raw capabilities: {}'.format( caps ), ] if vo_type == "vehicles": expected.insert( 2, '- notes: "<s>b</s>" "C"' ) wait_for_clipboard( 2, "\n".join(expected) ) delete_vo( vo_type, 1, "another german {}".format(vo_type0), webdriver ) # test a minimal example add_vo( webdriver, vo_type, 1, "name only" ) btn = find_child( "button[data-id='ob_{}_1']".format( vo_type ) ) btn.click() expected = [ '[German] ; width=', '[*] name only: #=', '- capabilities:', '- raw capabilities:', ] wait_for_clipboard( 2, "\n".join(expected) )
def check_snippet( expected ): """Check the vehicle's snippet.""" snippet_btn.click() wait_for_clipboard( 2, expected, transform=extract_comments )
def test_extra_ma_notes(webapp, webdriver): """Test handling of Landing Craft and Allied/Axis Minor common vehicles/ordnance.""" # initialize webapp.control_tests.set_vo_notes_dir("{TEST}") init_webapp(webapp, webdriver, scenario_persistence=1) # load the test scenario load_scenario({ "PLAYER_1": "dutch", "OB_VEHICLES_1": [{ "name": "dutch vehicle" }, { "name": "common allied minor vehicle" }], "OB_ORDNANCE_1": [{ "name": "dutch ordnance" }, { "name": "common allied minor ordnance" }], "PLAYER_2": "romanian", "OB_VEHICLES_2": [{ "name": "romanian vehicle" }, { "name": "common axis minor vehicle" }], "OB_ORDNANCE_2": [{ "name": "romanian ordnance" }, { "name": "common axis minor ordnance" }], }) # test Allied Minor vehicles/ordnance select_tab("ob1") btn = find_child("button.generate[data-id='ob_vehicles_ma_notes_1']") btn.click() wait_for_clipboard(2, [ ("A", 'Dutch Multi-Applicable Vehicle Note "A".'), ("Du", 'Allied Minor Multi-Applicable Vehicle Note "Du".'), ], transform=extract_ma_notes) btn = find_child("button.generate[data-id='ob_ordnance_ma_notes_1']") btn.click() wait_for_clipboard(2, [ ("A", 'Dutch Multi-Applicable Ordnance Note "A".'), ("Du", 'Allied Minor Multi-Applicable Ordnance Note "Du".'), ], transform=extract_ma_notes) # test Axis Minor vehicles/ordnance select_tab("ob2") btn = find_child("button.generate[data-id='ob_vehicles_ma_notes_2']") btn.click() wait_for_clipboard(2, [ ("A", 'Romanian Multi-Applicable Vehicle Note "A".'), ("Ro", 'Axis Minor Multi-Applicable Vehicle Note "Ro".'), ], transform=extract_ma_notes) btn = find_child("button.generate[data-id='ob_ordnance_ma_notes_2']") btn.click() wait_for_clipboard(2, [ ("A", 'Romanian Multi-Applicable Ordnance Note "A".'), ("Ro", 'Axis Minor Multi-Applicable Ordnance Note "Ro".'), ], transform=extract_ma_notes) # test Landing Craft load_scenario({ "PLAYER_1": "american", "OB_VEHICLES_1": [{ "name": "M10 GMC" }, { "name": "landing craft" }], "PLAYER_2": "japanese", "OB_VEHICLES_2": [{ "name": "japanese vehicle" }, { "name": "Daihatsu" }], }) select_tab("ob1") btn = find_child("button.generate[data-id='ob_vehicles_ma_notes_1']") btn.click() wait_for_clipboard(2, [ ("A", 'American Multi-Applicable Vehicle Note "A".'), ("N", "Unavailable."), ("Y", "Unavailable."), "Landing Craft", ("A", 'Landing Craft Multi-Applicable Note "A".'), ], transform=extract_ma_notes) select_tab("ob2") btn = find_child("button.generate[data-id='ob_vehicles_ma_notes_2']") btn.click() wait_for_clipboard(2, [ ("A", 'Japanese Multi-Applicable Vehicle Note "A".'), "Landing Craft", ("B", 'Landing Craft Multi-Applicable Note "B".'), ], transform=extract_ma_notes)
def test_include_flags_in_snippets(webapp, webdriver): """Test including flags in snippets.""" # initialize webapp.control_tests.set_data_dir("{REAL}") init_webapp(webapp, webdriver) # prepare the scenario set_player(1, "german") select_tab("ob1") sortable = find_child("#ob_setups-sortable_1") add_simple_note(sortable, "OB setup note", None) # enable "show flags in snippets" select_menu_option("user_settings") elem = find_child( ".ui-dialog.user-settings input[name='include-flags-in-snippets']") assert not elem.is_selected() elem.click() click_dialog_button("OK") _check_cookies(webdriver, "include-flags-in-snippets", True) # make sure that it took effect ob_setup_snippet_btn = find_child("li img.snippet", sortable) ob_setup_snippet_btn.click() wait_for_clipboard(2, "/flags/german", contains=True) # make sure it also affects vehicle/ordnance snippets ob_vehicles_snippet_btn = find_child( "button.generate[data-id='ob_vehicles_1']") ob_vehicles_snippet_btn.click() wait_for_clipboard(2, "/flags/german", contains=True) ob_ordnance_snippet_btn = find_child( "button.generate[data-id='ob_ordnance_1']") ob_ordnance_snippet_btn.click() wait_for_clipboard(2, "/flags/german", contains=True) # disable "show flags in snippets" select_menu_option("user_settings") elem = find_child( ".ui-dialog.user-settings input[name='include-flags-in-snippets']") assert elem.is_selected() elem.click() click_dialog_button("OK") _check_cookies(webdriver, "include-flags-in-snippets", False) # make sure that it took effect ob_setup_snippet_btn.click() wait_for_clipboard(2, "/flags/german", contains=False) # make sure it also affects vehicle/ordnance snippets ob_vehicles_snippet_btn.click() wait_for_clipboard(2, "/flags/german", contains=False) ob_ordnance_snippet_btn.click() wait_for_clipboard(2, "/flags/german", contains=False)