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
Beispiel #2
0
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)
Beispiel #3
0
def test_snippet_ids(webapp, webdriver):
    """Check that snippet ID's are generated correctly."""

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

    # load a scenario (so that we get some sortable's)
    scenario_data = {
        "SCENARIO_NOTES": [{
            "caption": "Scenario note #1"
        }],
        "OB_SETUPS_1": [{
            "caption": "OB setup note #1"
        }],
        "OB_NOTES_1": [{
            "caption": "OB note #1"
        }],
        "OB_SETUPS_2": [{
            "caption": "OB setup note #2"
        }],
        "OB_NOTES_2": [{
            "caption": "OB note #2"
        }],
    }
    load_scenario(scenario_data)

    def check_snippet(btn):
        """Generate a snippet and check that it has an ID."""
        btn.click()
        wait_for_clipboard(2, "<!-- vasl-templates:id ", contains=True)

    def do_test(scenario_date):
        """Check each generated snippet has an ID."""

        # configure the scenario
        set_scenario_date(scenario_date)

        # check each snippet
        snippet_btns = find_snippet_buttons()
        for tab_id, btns in snippet_btns.items():
            select_tab(tab_id)
            for btn in btns:
                check_snippet(btn)

    # test snippets with German/Russian
    do_test("")
    do_test("10/01/1943")
    do_test("01/01/1944")

    # test snippets with British/American
    new_scenario()
    load_scenario_params(
        {"scenario": {
            "PLAYER_1": "british",
            "PLAYER_2": "american"
        }})
    do_test("")
    do_test("11/01/1942")
Beispiel #4
0
 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 do_test():  #pylint: disable=missing-docstring

        # initialize
        init_webapp(webapp,
                    webdriver,
                    vsav_persistence=1,
                    scenario_persistence=1)

        # do the test
        # NOTE: The test scenario contains hidden/concealed units belonging to the Russians and Germans,
        # but because the owning user is test/password, they should be ignored (unless you configure VASSAL
        # with these credentials, so don't do that :-/).
        new_scenario()
        analyze_vsav("hip-concealed.vsav", [[], []], [[], []],
                     ["No vehicles/ordnance were imported."])
    def check(asa_id):
        """Check the current state of the scenario."""

        # check that the ASL Scenario Archive scenario ID has been set
        wait_for(2, lambda: get_asa_id() == asa_id)

        # check that the ASL Scenario Archive scenario ID is saved correctly
        saved_scenario = save_scenario()
        assert saved_scenario["ASA_ID"] == asa_id

        # reset the scenario
        new_scenario()
        assert get_asa_id() == ""

        # check that the ASL Scenario Archive scenario ID is loaded correctly
        load_scenario(saved_scenario)
        assert get_asa_id() == asa_id
def test_unknown_nats(webapp, webdriver):
    """Test importing scenarios with unknown player nationalities."""

    # initialize
    init_webapp(webapp, webdriver)

    # test importing a scenario with 2 completely unknown player nationalities
    set_player(1, "french")
    set_player(2, "italian")
    dlg = _do_scenario_search("Unknown players", ["4a"], webdriver)
    _click_import_button(dlg)
    _check_warnings([],
                    ["Unknown player: Eastasia", "Unknown player: Oceania"])
    expected_bgraphs = {
        "asa": [{
            "name": "Eastasia",
            "wins": 2,
            "percentage": 67
        }, {
            "name": "Oceania",
            "wins": 1,
            "percentage": 33
        }]
    }
    assert _unload_balance_graphs(dlg) == expected_bgraphs
    find_child("button.confirm-import", dlg).click()
    wait_for(2, lambda: not find_child("#scenario-search").is_displayed())
    assert get_player_nat(1) == "french"
    assert get_player_nat(2) == "italian"

    # test matching nationalities (partial name matches)
    new_scenario()
    dlg = _do_scenario_search("partial nationality matches", ["4b"], webdriver)
    find_child("button.import", dlg).click()
    wait_for(2, lambda: not find_child("#scenario-search").is_displayed())
    assert get_player_nat(1) == "russian"
    assert get_player_nat(2) == "japanese"

    # test nationality mapping
    new_scenario()
    dlg = _do_scenario_search("nationality mapping", ["4c"], webdriver)
    find_child("button.import", dlg).click()
    wait_for(2, lambda: not find_child("#scenario-search").is_displayed())
    assert get_player_nat(1) == "british"
    assert get_player_nat(2) == "british~canadian"
    def do_test(theater, expected):  #pylint: disable=missing-docstring

        # initialize
        webapp.control_tests.set_data_dir("{REAL}")
        init_webapp(webapp,
                    webdriver,
                    vsav_persistence=1,
                    scenario_persistence=1)

        # do the test
        new_scenario()
        load_scenario_params({
            "scenario": {
                "SCENARIO_THEATER": theater,
                "PLAYER_1": "american",
            }
        })
        analyze_vsav("vo-entry-selection-for-theater.vsav", [[], expected],
                     [[], []], ["Imported 4 American ordnance."])
    def do_test():  #pylint: disable=missing-docstring

        # initialize
        webapp.control_tests.set_data_dir("{REAL}")
        init_webapp(webapp,
                    webdriver,
                    vsav_persistence=1,
                    scenario_persistence=1)

        # do the test
        new_scenario()
        set_player(1, "american")
        set_player(2, "croatian")
        analyze_vsav("reverse-remapped-gpids-650.vsav",
                     [["am/v:044"], ["am/o:002", "am/o:021"]],
                     [["cr/v:002", "cr/v:003"], ["cr/o:000"]], [
                         "Imported 1 American vehicle and 2 ordnance.",
                         "Imported 2 Croatian vehicles and 1 ordnance."
                     ])
def test_unknown_theaters(webapp, webdriver):
    """Test importing scenarios with unknown theaters."""

    # initialize
    init_webapp(webapp, webdriver)

    # search for the "MTO" scenario (this has a theater mapping)
    set_theater("Korea")
    dlg = _do_scenario_search("MTO", ["3a"], webdriver)
    _click_import_button(dlg)
    wait_for(2, lambda: not dlg.is_displayed())
    assert get_theater() == "ETO"

    # search for the "Africa" scenario (this has no theater mapping)
    new_scenario()
    set_theater("Korea")
    dlg = _do_scenario_search("Africa", ["3b"], webdriver)
    _click_import_button(dlg)
    _check_warnings([], ["Unknown theater: Africa"])
    find_child("button.confirm-import", dlg).click()
    assert get_theater() == "other"
    def do_test():  #pylint: disable=missing-docstring

        # initialize
        webapp.control_tests.set_data_dir("{REAL}")
        init_webapp(webapp,
                    webdriver,
                    vsav_persistence=1,
                    scenario_persistence=1)

        # analyze a basic scenario
        new_scenario()
        set_player(1, "german")
        set_player(2, "russian")
        analyze_vsav("basic.vsav", [["ge/v:033", "ge/v:066"], ["ge/o:029"]],
                     [["ru/v:064"], ["ru/o:002", "ru/o:006"]], [
                         "Imported 2 German vehicles and 1 ordnance.",
                         "Imported 1 Russian vehicle and 2 ordnance."
                     ])

        # try again with different nationalities
        new_scenario()
        set_player(1, "french")
        set_player(2, "british")
        analyze_vsav("basic.vsav", [[], []], [[], []],
                     ["No vehicles/ordnance were imported."])

        # analyze a scenario with landing craft
        new_scenario()
        set_player(1, "american")
        set_player(2, "japanese")
        analyze_vsav(
            "landing-craft.vsav",
            [[("sh/v:000", "397/0"), ("sh/v:000", "399/0"),
              ("sh/v:006", "413/0"),
              ("sh/v:006", "415/0")], []], [["sh/v:007", "sh/v:008"], []],
            ["Imported 4 American vehicles.", "Imported 2 Japanese vehicles."])

        # analyze a scenario with common vehicles/ordnance
        new_scenario()
        set_player(1, "belgian")
        set_player(2, "romanian")
        analyze_vsav("common-vo.vsav",
                     [["be/v:000", "alc/v:011"], ["be/o:001", "alc/o:012"]],
                     [["ro/v:000", "axc/v:027"], ["ro/o:003", "axc/o:002"]], [
                         "Imported 2 Belgian vehicles and 2 ordnance.",
                         "Imported 2 Romanian vehicles and 2 ordnance."
                     ])
        # try again with the Yugoslavians/Croatians
        new_scenario()
        set_player(1, "yugoslavian")
        set_player(2, "croatian")
        analyze_vsav("common-vo.vsav", [["alc/v:011"], ["alc/o:012"]],
                     [["axc/v:027"], ["axc/o:002"]], [
                         "Imported 1 Yugoslavian vehicle and 1 ordnance.",
                         "Imported 1 Croatian vehicle and 1 ordnance."
                     ])
        # try again with the Germans/Russians
        new_scenario()
        analyze_vsav("common-vo.vsav", [[], []], [[], []],
                     ["No vehicles/ordnance were imported."])

        # analyze a scenario using counters from an extension
        new_scenario()
        set_player(1, "american")
        set_player(2, "japanese")
        analyze_vsav("extensions-bfp.vsav", [["am/v:906"], ["am/o:900"]],
                     [["ja/v:902"], ["ja/o:902"]], [
                         "Imported 1 American vehicle and 1 ordnance.",
                         "Imported 1 Japanese vehicle and 1 ordnance."
                     ])
def test_import_warnings(webapp, webdriver):  #pylint: disable=too-many-statements
    """Test warnings when importing a scenario."""

    # initialize
    init_webapp(webapp, webdriver, scenario_persistence=1)

    # import a scenario on top of an empty scenario
    dlg = _do_scenario_search("full", [1], webdriver)
    find_child("button.import", dlg).click()
    wait_for(2, lambda: not dlg.is_displayed())

    def check_warnings(expected):  #pylint: disable=missing-docstring
        warnings = find_children(".warnings input[type='checkbox']", dlg)
        return [w.get_attribute("name") for w in warnings] == expected

    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

    # do the tests
    do_test("SCENARIO_NAME", "scenario_name", "Full content scenario")
    do_test("SCENARIO_ID", "scenario_display_id", "FCS-1")
    do_test("SCENARIO_LOCATION", "scenario_location", "Some place")
    do_test("SCENARIO_DATE",
            "scenario_date_iso",
            "12/31/1945",
            curr_val="01/02/1940")
    do_test("SCENARIO_THEATER", None, "PTO", curr_val="Burma")
    do_test("PLAYER_1", None, "dutch", curr_val="german")
    do_test("PLAYER_1_DESCRIPTION", "defender_desc", "1st Dutch Army")
    do_test("PLAYER_2", None, "romanian", curr_val="german")
    do_test("PLAYER_2_DESCRIPTION", "attacker_desc", "1st Romanian Army")

    # test importing a scenario on top of existing OB owned by the same nationality
    new_scenario()
    load_scenario({
        "PLAYER_1": "dutch",
    })
    dlg = _do_scenario_search("full", [1], webdriver)
    find_child("button.import", dlg).click()
    check_warnings([])
    wait_for(2, lambda: not dlg.is_displayed())

    # test importing a scenario on top of existing OB owned by the same nationality
    new_scenario()
    load_scenario({
        "PLAYER_1": "dutch",
        "OB_SETUPS_1": [{
            "caption": "Dutch setup note"
        }]
    })
    dlg = _do_scenario_search("full", [1], webdriver)
    find_child("button.import", dlg).click()
    wait_for(2, lambda: not dlg.is_displayed())

    # test importing a scenario on top of existing OB owned by the different nationality
    new_scenario()
    load_scenario({
        "PLAYER_1": "german",
        "OB_SETUPS_1": [{
            "caption": "German setup note"
        }]
    })
    dlg = _do_scenario_search("full", [1], webdriver)
    find_child("button.import", dlg).click()
    warnings = wait_for(
        2, lambda: find_children(".warnings input[type='checkbox']", dlg))
    assert [w.get_attribute("name") for w in warnings] == ["defender_name"]
    assert not warnings[0].is_selected()
    wait_for(2, lambda: warnings[0].is_displayed)
    time.sleep(0.1)  # nb: wait for the slide to finish :-/
    warnings[0].click()
    find_child("button.confirm-import", dlg).click()
    assert not dlg.is_displayed()
    assert get_player_nat(1) == "dutch"