コード例 #1
0
def _do_test_ob_entries( webapp, webdriver, ob_type ):
    """Test generating OB setup/notes."""

    # initialize
    init_webapp( webapp, webdriver )
    sortable1 = find_child( "#{}-sortable_1".format( ob_type ) )
    sortable2 = find_child( "#{}-sortable_2".format( ob_type ) )

    # generate OB setup/note snippets for both players
    select_tab( "ob1" )
    add_simple_note( sortable1, "{} #1".format(ob_type), None )
    add_simple_note( sortable1, "{} #2".format(ob_type), "2px" )
    select_tab( "ob2" )
    add_simple_note( sortable2, "<i>{}</i> #3".format(ob_type), "3px" )

    # check that snippets are generated correctly
    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 )
    select_tab( "ob1" )
    check_snippet( sortable1, 0,
        "[German] [{} #1] (col=[OBCOL:german/OBCOL-BORDER:german])".format( ob_type )
    )
    check_snippet( sortable1, 1,
        "[German] [{} #2] (col=[OBCOL:german/OBCOL-BORDER:german]) (width=[2px])".format( ob_type )
    )
    select_tab( "ob2" )
    check_snippet( sortable2, 0,
        "[Russian] [<i>{}</i> #3] (col=[OBCOL:russian/OBCOL-BORDER:russian]) (width=[3px])".format( ob_type )
    )

    # make some changes and check the snippets again
    edit_simple_note( sortable2, 0, "updated {} #3".format(ob_type), "" )
    select_tab( "ob1" )
    edit_simple_note( sortable1, 1, "<i>updated {} #2</i>".format(ob_type), "200px" )
    edit_simple_note( sortable1, 0, None, "100px" )
    select_tab( "ob2" )
    check_snippet( sortable2, 0,
        "[Russian] [updated {} #3] (col=[OBCOL:russian/OBCOL-BORDER:russian])".format( ob_type )
    )
    select_tab( "ob1" )
    check_snippet( sortable1, 1,
        "[German] [<i>updated {} #2</i>] (col=[OBCOL:german/OBCOL-BORDER:german]) (width=[200px])".format( ob_type )
    )
    check_snippet( sortable1, 0,
        "[German] [{} #1] (col=[OBCOL:german/OBCOL-BORDER:german]) (width=[100px])".format( ob_type )
    )

    # delete an OB setup/note by dragging it into the trash
    assert get_sortable_entry_count( sortable1 ) == 2
    drag_sortable_entry_to_trash( sortable1, 1 )
    assert get_sortable_entry_count( sortable1 ) == 1

    # delete an OB setup/note by emptying its caption
    edit_simple_note( sortable1, 0, "", None )
    assert get_sortable_entry_count( sortable1 ) == 0
コード例 #2
0
    def do_test():  #pylint: disable=missing-docstring

        # initialize
        init_webapp(webapp, webdriver, vlog_persistence=1, lfa_persistence=1)

        # analyze the log file
        _analyze_vlogs("custom-labels.vlog")

        # download the data
        marker = set_stored_msg_marker("_lfa-download_")
        find_child("#lfa button.download").click()
        wait_for(2, lambda: get_stored_msg("_lfa-download_") != marker)
        data = get_stored_msg("_lfa-download_")

        # check the results
        data = data.split("\n")
        rows = list(csv.reader(data, quoting=csv.QUOTE_NONNUMERIC))
        assert rows == [[
            "Log file", "Phase", "Player", "Type", "Die 1", "Die 2"
        ], ["custom-labels.vlog", "", "test", "Other", 5, 3],
                        ["", "", "test", "Other", 3, ""],
                        ["", "Custom Label 1", "test", "Other", 6, 6],
                        ["", "", "test", "RS", 6, ""],
                        ["", "Axis 1 PFPh", "test", "Other", 4, 4],
                        ["", "", "test", "RS", 6, ""],
                        ["", "Custom label 2", "test", "Other", 2, 1],
                        ["", "", "test", "RS", 1, ""]]
コード例 #3
0
    def do_test():  #pylint: disable=missing-docstring

        # initialize
        init_webapp(webapp, webdriver, vlog_persistence=1, lfa_tables=1)

        # analyze the log file
        _analyze_vlogs("3d6.vlog")

        # check the results
        #   IFT 6,6
        #   RS  2
        #   3d6 3,4,1
        #   IFT 6,5
        #   TH  6,2
        #   3d6 2,4,2
        lfa = _get_chart_data(1)
        assert lfa["timePlot"] == [["", "test (5)"], ["", "12"], ["", "7"],
                                   ["", "11"], ["", "8"], ["", "6"]]
        _select_roll_type("3d6 (DR)")
        lfa = _get_chart_data()
        assert lfa["timePlot"] == [["", "test (2)"], ["", "7"], ["", "6"]]
        _select_roll_type("3d6 (dr)")
        lfa = _get_chart_data()
        assert lfa["timePlot"] == [["", "test (2)"], ["", "1"], ["", "2"]]

        # close the analysis window
        find_child("#lfa button.ui-dialog-titlebar-close").click()
コード例 #4
0
def _find_scenario_card():
    """Find the currently-displayed scenario card."""
    if find_child("#scenario-search").is_displayed():
        return find_child("#scenario-search .scenario-card")
    if find_child("#scenario-info-dialog").is_displayed():
        return find_child("#scenario-info-dialog .scenario-card")
    return None
コード例 #5
0
def test_import_scenario(webapp, webdriver):
    """Test importing a scenario."""

    # initialize
    init_webapp(webapp, webdriver)

    # import the "full" scenario
    dlg = _do_scenario_search("full", [1], webdriver)
    find_child("button.import", dlg).click()
    wait_for(
        2, lambda: _check_scenario(SCENARIO_NAME="Full content scenario",
                                   SCENARIO_ID="FCS-1",
                                   SCENARIO_LOCATION="Some place",
                                   PLAYER_1="dutch",
                                   PLAYER_1_DESCRIPTION="1st Dutch Army",
                                   PLAYER_2="romanian",
                                   PLAYER_2_DESCRIPTION="1st Romanian Army",
                                   THEATER="PTO"))

    # import the "empty" scenario
    _unlink_scenario()
    dlg = _do_scenario_search("Untitled", ["no-content"], webdriver)
    _import_scenario_and_confirm(dlg)
    # NOTE: Since there are no players defined in the scenario, what's on-screen will be left unchanged.
    wait_for(
        2, lambda: _check_scenario(SCENARIO_NAME=
                                   "Untitled scenario (#no-content)",
                                   SCENARIO_ID="",
                                   SCENARIO_LOCATION="",
                                   PLAYER_1="dutch",
                                   PLAYER_1_DESCRIPTION="",
                                   PLAYER_2="romanian",
                                   PLAYER_2_DESCRIPTION="",
                                   THEATER="ETO"))
コード例 #6
0
    def do_test(param_name,
                expected_warning,
                expected_val,
                curr_val="CURR-VAL"):  #pylint: disable=missing-docstring

        # start with a new scenario
        new_scenario()

        # set the scenario parameter
        set_template_params({param_name: curr_val})

        # import a scenario
        _do_scenario_search("full", [1], webdriver)
        _click_import_button(find_child("#scenario-search"))

        # check if any warnings were expected
        elem = find_child("[name='{}']".format(param_name))
        if expected_warning:
            # yup - make sure they are being shown
            wait_for(2, lambda: check_warnings([expected_warning]))
            # cancel the import
            find_child("button.cancel-import", dlg).click()
            wait_for(2,
                     lambda: not find_child(".warnings", dlg).is_displayed())
            # do the import again, and accept it
            _import_scenario_and_confirm(dlg)
            assert elem.get_attribute("value") == expected_val
        else:
            # nope - check that the import was done
            wait_for(2, lambda: not dlg.is_displayed())
            # assert not dlg.is_displayed()
            assert elem.get_attribute("value") == expected_val
コード例 #7
0
def _unlink_scenario():
    """Unlink the scenario from the ASL Scenario Archive."""
    find_child("button.scenario-search").click()
    wait_for_elem(2, "#scenario-info-dialog")
    btn = find_children(".ui-dialog .ui-dialog-buttonpane button")[1]
    assert btn.text == "Unlink"
    btn.click()
コード例 #8
0
 def change_field(param):
     """Make a change to a field."""
     # make a change to the specified field
     if param in SIMPLE_NOTES:
         target = find_child(SIMPLE_NOTES[param])
         add_simple_note(target, "changed value", None)
         return target
     if param in VEHICLE_ORDNANCE:
         info = VEHICLE_ORDNANCE[param]
         target = find_child(info[0])
         mo = re.search(r"([a-z]+)-", info[0])
         add_vo(webdriver, mo.group(1), info[1], info[2])
         return target
     target = next(e for e in [
         find_child("{}[name='{}']".format(ctype, param))
         for ctype in ["input", "select", "textarea"]
     ] if e)
     if target.tag_name in ("input", "textarea"):
         prev_val = target.get_attribute("value")
         new_val = "01/01/2000" if param == "SCENARIO_DATE" else "changed value"
         if target.is_displayed():
             target.clear()
             target.send_keys(new_val)
         else:
             webdriver.execute_script("arguments[0].value = arguments[1]",
                                      target, new_val)
         return target, prev_val, new_val
     elif target.tag_name == "select":
         sel = Select(target)
         prev_val = sel.first_selected_option.get_attribute("value")
         select_droplist_index(sel, 2)
         new_val = sel.first_selected_option.get_attribute("value")
         return target, prev_val, new_val
     assert False
     return None
コード例 #9
0
    def do_test():  #pylint: disable=missing-docstring

        # initialize
        init_webapp(webapp, webdriver, vlog_persistence=1, lfa_persistence=1)

        # analyze the log file
        _analyze_vlogs("download-test.vlog")

        # download the data
        marker = set_stored_msg_marker("_lfa-download_")
        find_child("#lfa button.download").click()
        wait_for(2, lambda: get_stored_msg("_lfa-download_") != marker)
        data = get_stored_msg("_lfa-download_")

        # check the results
        data = data.split("\n")
        rows = list(csv.reader(data, quoting=csv.QUOTE_NONNUMERIC))
        assert rows == [[
            "Log file", "Phase", "Player", "Type", "Die 1", "Die 2"
        ], ["download-test.vlog", "", 'Joey "The Lips" Blow', "IFT", 4, 1],
                        ["", "", 'Joey "The Lips" Blow', "IFT", 2, 5],
                        ["", "", 'Joey "The Lips" Blow', "RS", 2, ""],
                        ["", "UN 1 PFPh", "\u65e5\u672c Guy", "IFT", 4, 6],
                        ["", "", "\u65e5\u672c Guy", "IFT", 2, 6],
                        ["", "", "\u65e5\u672c Guy", "RS", 3, ""],
                        ["", "UN 1 MPh", 'Joey "The Lips" Blow', "IFT", 2, 6],
                        ["", "", 'Joey "The Lips" Blow', "IFT", 2, 3],
                        ["", "", 'Joey "The Lips" Blow', "RS", 3, ""]]
コード例 #10
0
def test_scenario_notes_snippets(webapp, webdriver):
    """Test HTML snippet generation."""

    # initialize
    init_webapp(webapp, webdriver)
    select_tab("scenario")

    sortable = find_child("#scenario_notes-sortable")
    add_simple_note(sortable, "scenario <i>note</i> #1", None)
    add_simple_note(sortable, "scenario note #2", "100px")
    assert generate_sortable_entry_snippet(
        sortable, 0) == adjust_html("[scenario <i>note</i> #1]")
    assert generate_sortable_entry_snippet(
        sortable, 1) == "[scenario note #2] (width=[100px])"

    # delete a scenario note by dragging it into the trash
    assert get_sortable_entry_count(sortable) == 2
    drag_sortable_entry_to_trash(sortable, 0)
    assert get_sortable_entry_count(sortable) == 1

    # delete scenario note by emptying its caption
    edit_simple_note(sortable, 0, "", None)
    assert get_sortable_entry_count(sortable) == 0

    # add a scenario note with non-English content and HTML special characters
    sortable = find_child("#scenario_notes-sortable")
    add_simple_note(sortable, "japan <\u65e5\u672c>", None)
    assert generate_sortable_entry_snippet(sortable,
                                           0) == "[japan <\u65e5\u672c>]"
コード例 #11
0
def _generate_snippet(webdriver, template_id, orig_template_id):
    """Generate a snippet for the specified template."""

    if template_id == "scenario_note":
        # create a scenario note and generate a snippet for it
        sortable = find_child("#scenario_notes-sortable")
        add_simple_note(sortable, "test scenario note", None)
        elems = find_children("li img.snippet", sortable)
        elem = elems[0]
    elif template_id in ("ob_setup", "ob_note"):
        # create a OB setup/note and generate a snippet for it
        select_tab("ob1")
        sortable = find_child("#{}s-sortable_1".format(template_id))
        add_simple_note(sortable, "test {}".format(template_id), None)
        elems = find_children(
            "#{}s-sortable_1 li img.snippet".format(template_id))
        elem = elems[0]
    elif template_id in ("ob_vehicle_note", "ob_ordnance_note"):
        # create a vehicle/ordnance and generate a snippet for its note
        mo = re.search(r"^ob_([a-z]+)_note_(\d)$", orig_template_id)
        vo_type, player_no = mo.group(1), int(mo.group(2))
        vo_type0 = "vehicles" if vo_type == "vehicle" else vo_type
        player_nat = "german" if player_no == 1 else "russian"
        sortable = find_child("#ob_{}-sortable_{}".format(vo_type0, player_no))
        add_vo(webdriver, vo_type0, player_no,
               "a {} {}".format(player_nat, vo_type))
        elems = find_children("li img.snippet", sortable)
        elem = elems[0]
    else:
        # generate a snippet for the specified template
        elem = find_child(
            "button.generate[data-id='{}']".format(orig_template_id))
    elem.click()
    return elem
コード例 #12
0
def _analyze_vlogs(fnames):
    """Analyze log file(s)."""

    # initialize
    if isinstance(fnames, str):
        fnames = [fnames]
    select_menu_option("analyze_vlog")
    dlg = wait_for_elem(2, ".ui-dialog.lfa-upload")

    # add each log file
    for fno, fname in enumerate(fnames):
        fname = os.path.join(
            os.path.split(__file__)[0], "fixtures/analyze-vlog/" + fname)
        with open(fname, "rb") as fp:
            vlog_data = fp.read()
        set_stored_msg(
            "_vlog-persistence_", "{}|{}".format(
                os.path.split(fname)[1],
                base64.b64encode(vlog_data).decode("utf-8")))
        find_child("#lfa-upload .{}".format("hint" if fno == 0 else "files"),
                   dlg).click()
        wait_for(2, lambda: get_stored_msg("_vlog-persistence_") == "")

    # start the analysis
    find_child("button.ok", dlg).click()
    wait_for_elem(30, "#lfa")
コード例 #13
0
 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)
コード例 #14
0
 def check_color_pickers(expected):
     """Check which color pickers are being presented to the user."""
     find_child("#lfa .options button.player-colors").click()
     popup = wait_for_elem(2, "#lfa .player-colors-popup")
     player_names = [
         e.text for e in find_children(".row .caption", popup) if e.text
     ]
     assert player_names.pop() == "expected results"
     assert player_names == expected
コード例 #15
0
def _select_log_file(fname):
    """Select one of the log files being analyzed."""
    find_child("#lfa .banner .select-file").click()
    popup = wait_for_elem(2, "#lfa .select-file-popup")
    for row in find_children(".row", popup):
        if find_child("label", row).text == fname:
            find_child("input[type='radio']", row).click()
            return
    assert False, "Couldn't find file: " + fname
コード例 #16
0
 def unload_report():
     """Unload the hotness popup."""
     find_child("#lfa .hotness img.dice").click()
     wait_for_elem(2, "#lfa .hotness-popup")
     report = {}
     for key in ("2s", "12s", "snipers"):
         report[key] = unload_table(
             "//div[@class='hotness-popup']//table[@class='{}']//tr".format(
                 key))
     return report
コード例 #17
0
def _get_scenario_info():
    """Open the scenario info and unload the information."""
    btn = find_child("button.scenario-search")
    assert find_child("img", btn).get_attribute("src").endswith("/info.gif")
    btn.click()
    wait_for_elem(2, "#scenario-info-dialog")
    card = _unload_scenario_card()
    btn = find_children(".ui-dialog .ui-dialog-buttonpane button")[0]
    assert btn.text == "OK"
    btn.click()
    return card
コード例 #18
0
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"'
        ))
コード例 #19
0
def test_html_names( webapp, webdriver ):
    """Test handling of vehicles/ordnance that have HTML in their name."""

    # initialize
    webapp.control_tests.set_data_dir( "{REAL}" )
    init_webapp( webapp, webdriver )

    def get_available_ivfs():
        """Get the PzKw IVF's available for selection."""
        entries = find_children( "#select-vo .select2-results li" )
        entries = [ e.text for e in entries ]
        return [ e for e in entries if "IVF" in e ]

    # start to add a vehicle - make sure the two PzKw IVF's are available
    set_player( 1, "german" )
    select_tab( "ob1" )
    add_vehicle_btn = find_child( "#ob_vehicles-add_1" )
    add_vehicle_btn.click()
    assert get_available_ivfs() == [ "PzKpfw IVF1 (MT)", "PzKpfw IVF2 (MT)" ]

    # add the PzKw IVF2
    elem = find_child( ".ui-dialog .select2-search__field" )
    elem.send_keys( "IVF2" )
    elem.send_keys( Keys.RETURN )

    # make sure it was added to the player's OB
    vehicles_sortable = find_child( "#ob_vehicles-sortable_1" )
    assert get_sortable_vo_names( vehicles_sortable ) == [ "PzKpfw IVF2" ]

    # start to add another vehicle - make sure both PzKw IVF's are still available
    add_vehicle_btn.click()
    assert get_available_ivfs() == [ "PzKpfw IVF1 (MT)", "PzKpfw IVF2 (MT)" ]

    # add the PzKw IVF1
    elem = find_child( ".ui-dialog .select2-search__field" )
    elem.send_keys( "IVF1" )
    elem.send_keys( Keys.RETURN )

    # make sure it was added to the player's OB
    assert get_sortable_vo_names( vehicles_sortable ) == [ "PzKpfw IVF2", "PzKpfw IVF1" ]

    # start to add another vehicle - make sure both PzKw IVF's are still available
    add_vehicle_btn.click()
    assert get_available_ivfs() == [ "PzKpfw IVF1 (MT)", "PzKpfw IVF2 (MT)" ]
    elem = find_child( ".ui-dialog .select2-search__field" )
    elem.send_keys( Keys.ESCAPE )

    # delete the PzKw IVF2
    delete_vo( "vehicles", 1, "PzKpfw IVF2" , webdriver )

    # start to add another vehicle - make sure both PzKw IVF's are still available
    add_vehicle_btn.click()
    assert get_available_ivfs() == [ "PzKpfw IVF1 (MT)", "PzKpfw IVF2 (MT)" ]
コード例 #20
0
 def do_test():  #pylint: disable=missing-docstring
     init_webapp(webapp,
                 webdriver,
                 vsav_persistence=1,
                 scenario_persistence=1)
     dlg = _do_scenario_search("full", [1], webdriver)
     find_child("button.import", dlg).click()
     last_asa_upload = do_upload(prep_upload2, False)
     assert isinstance(last_asa_upload["vt_setup"], dict)
     assert last_asa_upload["vasl_setup"][:2] == b"PK"
     assert last_asa_upload["screenshot"][:2] == b"\xff\xd8" \
       and last_asa_upload["screenshot"][-2:] == b"\xff\xd9" # nb: these are the magic numbers for JPEG's
コード例 #21
0
def test_vo_notes_as_images(webapp, webdriver):
    """Test showing vehicle/ordnance notes as HTML/images."""

    # initialize
    webapp.control_tests.set_vo_notes_dir("{TEST}")
    init_webapp(webapp, webdriver, scenario_persistence=1)

    # load the test vehicle
    load_scenario({
        "PLAYER_1": "greek",
        "OB_VEHICLES_1": [{
            "name": "HTML note"
        }],
    })
    select_tab("ob1")

    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)

    # generate the vehicle snippet (should get the raw HTML)
    check_snippet("This is an HTML vehicle note (202).")

    # enable "show vehicle/ordnance notes as images"
    select_menu_option("user_settings")
    elem = find_child(
        ".ui-dialog.user-settings input[name='vo-notes-as-images']")
    assert not elem.is_selected()
    elem.click()
    click_dialog_button("OK")
    _check_cookies(webdriver, "vo-notes-as-images", True)

    # generate the vehicle snippet (should get a link to return an image)
    check_snippet(re.compile(r"http://.+?:\d+/vehicles/greek/note/202"))

    # disable "show vehicle/ordnance notes as images"
    select_menu_option("user_settings")
    elem = find_child(
        ".ui-dialog.user-settings input[name='vo-notes-as-images']")
    assert elem.is_selected()
    elem.click()
    click_dialog_button("OK")
    _check_cookies(webdriver, "vo-notes-as-images", False)

    # generate the vehicle snippet (should get the raw HTML)
    check_snippet("This is an HTML vehicle note (202).")
コード例 #22
0
def test_ssr( webapp, webdriver ):
    """Test generating SSR snippets."""

    # initialize
    init_webapp( webapp, webdriver )
    select_tab( "scenario" )
    sortable = find_child( "#ssr-sortable" )

    # initialize
    expected = []
    generate_snippet_btn = find_child( "button[data-id='ssr']" )
    def add_ssr( val ):
        """Add a new SSR."""
        expected.append( val )
        add_simple_note( sortable, val, None )
        check_snippet()
    def edit_ssr( ssr_no, val ):
        """Edit an existing SSR."""
        expected[ssr_no] = val
        edit_simple_note( sortable, ssr_no, val, None )
        check_snippet()
    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)) )

    # add an SSR and generate the SSR snippet
    add_ssr( "This is my first SSR." )

    # add an SSR that contains HTML
    add_ssr( "This snippet contains <b>bold</b> and <i>italic</i> text." )

    # add a multi-line SSR
    add_ssr( "line 1\nline 2\nline 3" )

    # edit one of the SSR's
    edit_ssr( 1, "This SSR was <i>modified</i>." )

    # delete one of the SSR's
    assert get_sortable_entry_count(sortable) == 3
    drag_sortable_entry_to_trash( sortable, 1 )
    assert get_sortable_entry_count(sortable) == 2
    del expected[1]
    check_snippet()

    # set the snippet width
    elem = find_child( "input[name='SSR_WIDTH']" )
    elem.send_keys( "300px" )
    check_snippet( "300px" )
コード例 #23
0
    def do_test(tab_id, param):
        """Test checking for a dirty scenario."""

        # change the specified field
        check_is_dirty(False)
        select_tab(tab_id)
        state = change_field(param)
        check_is_dirty(True)

        # make sure we get asked to confirm a "new scenario" operation
        select_menu_option("new_scenario")
        wait_for(2, lambda: find_child("#ask") is not None)
        elem = find_child("#ask")
        assert "This scenario has been changed" in elem.text

        # cancel the confirmation request, make sure the change we made is still there
        click_dialog_button("Cancel")
        select_tab(tab_id)
        check_field(param, state)
        check_is_dirty(True)

        # revert the change
        revert_field(param, state)
        check_is_dirty(False)

        # we should now be able to reset the scenario without a confirmation
        _ = set_stored_msg_marker("_last-info_")
        select_menu_option("new_scenario")
        wait_for(
            2,
            lambda: get_stored_msg("_last-info_") == "The scenario was reset.")

        # change the field again
        select_tab(tab_id)
        state = change_field(param)
        check_is_dirty(True)

        # make sure we get asked to confirm a "load scenario" operation
        select_menu_option("load_scenario")
        wait_for(2, lambda: find_child("#ask") is not None)
        elem = find_child("#ask")
        assert "This scenario has been changed" in elem.text

        # cancel the confirmation request, make sure the change we made is still there
        click_dialog_button("Cancel")
        select_tab(tab_id)
        check_field(param, state)
        check_is_dirty(True)

        # revert the change
        revert_field(param, state)
        check_is_dirty(False)
コード例 #24
0
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
コード例 #25
0
def delete_vo( vo_type, player_no, name, webdriver ):
    """Delete a vehicle/ordnance."""

    # delete the vehicle/ordnance
    select_tab( "ob{}".format( player_no ) )
    sortable = find_child( "#ob_{}-sortable_{}".format( vo_type, player_no ) )
    elems = [
        c for c in find_children( "li .vo-name", sortable )
        if c.text == name
    ]
    assert len(elems) == 1
    elem = elems[0]
    trash = find_child( "#ob_{}-trash_{}".format( vo_type, player_no ) )
    ActionChains(webdriver).drag_and_drop( elem, trash ).perform()
コード例 #26
0
def test_hide_unavailable_ma_notes(webapp, webdriver):
    """Test showing/hiding unavailable multi-applicable notes."""

    # initialize
    webapp.control_tests.set_vo_notes_dir("{TEST}")
    init_webapp(webapp, webdriver, scenario_persistence=1)

    # load the test vehicle
    load_scenario({
        "PLAYER_1": "german",
        "OB_VEHICLES_1": [{
            "name": "missing multi-applicable note"
        }]
    })
    select_tab("ob1")

    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)

    # generate the multi-applicable notes
    test_ma_notes(True)

    # enable "hide unavailable multi-applicable notes"
    select_menu_option("user_settings")
    elem = find_child(
        ".ui-dialog.user-settings input[name='hide-unavailable-ma-notes']")
    assert not elem.is_selected()
    elem.click()
    click_dialog_button("OK")
    _check_cookies(webdriver, "hide-unavailable-ma-notes", True)

    # generate the multi-applicable notes
    test_ma_notes(False)

    # disable "hide unavailable multi-applicable notes"
    select_menu_option("user_settings")
    elem = find_child(
        ".ui-dialog.user-settings input[name='hide-unavailable-ma-notes']")
    assert elem.is_selected()
    elem.click()
    click_dialog_button("OK")
    _check_cookies(webdriver, "hide-unavailable-ma-notes", False)

    # generate the multi-applicable notes
    test_ma_notes(True)
コード例 #27
0
    def do_upload(prep_upload, expect_ask):
        """Upload the scenario to our test endpoint."""

        # show the scenario card
        find_child("button.scenario-search").click()
        wait_for(2, _find_scenario_card)

        # open the upload dialog
        find_child(".ui-dialog.scenario-info button.upload").click()
        dlg = wait_for_elem(2, ".ui-dialog.scenario-upload")
        if prep_upload:
            prep_upload(dlg)

        # start the upload
        webapp.control_tests.reset_last_asa_upload()
        find_child("button.upload", dlg).click()
        if expect_ask:
            dlg = wait_for_elem(2, ".ui-dialog.ask")
            find_child("button.ok", dlg).click()

        # wait for the upload to be processed
        last_asa_upload = wait_for(5, webapp.control_tests.get_last_asa_upload)
        assert last_asa_upload["user"] == user_name
        assert last_asa_upload["token"] == api_token
        return last_asa_upload
コード例 #28
0
    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) )
コード例 #29
0
def init_webapp(webdriver, webapp_url, options):
    """Initialize the webapp."""
    log("Initializing the webapp.")
    url = webapp_url + "?" + "&".join("{}=1".format(opt) for opt in options)
    url += "&store_msgs=1"  # nb: stop notification balloons from building up
    webdriver.get(url)
    wait_for(5, lambda: find_child("#_page-loaded_", webdriver) is not None)
コード例 #30
0
 def prep_upload2(dlg):
     """Prepare the upload."""
     assert asa_upload["user"] == user_name
     assert asa_upload["token"] == api_token
     # send the VSAV data to the front-end
     fname = os.path.join(os.path.dirname(__file__),
                          "fixtures/update-vsav/full.vsav")
     with open(fname, "rb") as fp:
         vsav_data = fp.read()
     set_stored_msg("_vsav-persistence_",
                    base64.b64encode(vsav_data).decode("utf-8"))
     find_child(".vsav-container", dlg).click()
     # wait for the files to be prepared
     wait_for(
         60, lambda: "loader.gif" not in find_child(
             ".screenshot-container .preview img").get_attribute("src"))