Beispiel #1
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>]"
Beispiel #2
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
Beispiel #3
0
    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" )
        )
Beispiel #4
0
def test_players_snippets(webapp, webdriver):
    """Test HTML snippet generation."""

    # initialize
    init_webapp(webapp, webdriver)
    select_tab("scenario")
    btn = find_child("button.generate[data-id='players']")

    # generate a PLAYERS snippet
    _test_snippet( btn, {
        "PLAYER_1": "french",
        "PLAYER_1_ELR": "1",
        "PLAYER_1_SAN": "2",
        "PLAYER_1_DESCRIPTION": "Froggy Army",
        "PLAYER_2": "british",
        "PLAYER_2_ELR": "3",
        "PLAYER_2_SAN": "4",
        "PLAYER_2_DESCRIPTION": "Barmy Army",
    },
        "player1=[french:French] ; ELR=[1] ; SAN=[2] ; description=[Froggy Army]" \
            " | player2=[british:British] ; ELR=[3] ; SAN=[4] ; description=[Barmy Army]",
        None
    )

    # generate a PLAYERS snippet with both players the same nationality
    _test_snippet( btn, {
        "PLAYER_1": "british",
        },
        "player1=[british:British] ; ELR=[1] ; SAN=[2] ; description=[]" \
            " | player2=[british:British] ; ELR=[3] ; SAN=[4] ; description=[Barmy Army]",
        [ "Both players have the same nationality!" ],
    )
Beispiel #5
0
def test_loading_ssrs(webapp, webdriver):
    """Test loading SSR's."""

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

    # initialize
    select_tab("scenario")
    sortable = find_child("#ssr-sortable")

    def do_test(ssrs):  # pylint: disable=missing-docstring
        load_scenario({"SSR": ssrs})
        assert get_sortable_entry_text(sortable) == ssrs

    # load a scenario that has SSR's into a UI with no SSR's
    do_test(["ssr 1", "ssr 2"])

    # load a scenario that has more SSR's than are currently in the UI
    do_test(["ssr 5", "ssr 6", "ssr 7", "ssr 8"])

    # load a scenario that has fewer SSR's than are currently in the UI
    do_test(["ssr 10", "ssr 11"])

    # load a scenario that has no SSR's into a UI that has SSR's
    do_test([])
Beispiel #6
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 #7
0
 def _set_width( vo_type, player_no, width ):
     """Set the snippet width."""
     select_tab( "ob{}".format( player_no ) )
     elem = find_child( "input[name='OB_{}_WIDTH_{}']".format( vo_type.upper(), player_no ) )
     elem.clear()
     if width is not None:
         elem.send_keys( str(width) )
     _width[ (vo_type,player_no) ] = width
Beispiel #8
0
def test_duplicate_vo_entries( webapp, webdriver ):
    """Test adding duplicate vehicles/ordnance."""

    # initialize
    init_webapp( webapp, webdriver )
    set_player( 1, "german" )
    select_tab( "ob1" )

    def get_available_vo_entries():
        """Get the available vehicles/ordnance for selection."""
        entries = find_children( "#select-vo .select2-results li" )
        return [ e.text for e in entries ]

    def do_test( vo_type, vo_name ): #pylint: disable=missing-docstring

        # start to add a vehicle/ordnance
        add_btn = find_child( "#ob_" + vo_type + "-add_1" )
        add_btn.click()
        assert vo_name in get_available_vo_entries()

        # add the vehicle/ordnance
        elem = find_child( ".ui-dialog .select2-search__field" )
        elem.send_keys( vo_name )
        elem.send_keys( Keys.RETURN )

        # make sure it was added to the player's OB
        sortable = find_child( "#ob_" + vo_type + "-sortable_1" )
        assert get_sortable_vo_names( sortable ) == [ vo_name ]

        # add the vehicle/ordnance, dismiss the warning
        add_btn.click()
        elem = find_child( ".ui-dialog .select2-search__field" )
        elem.send_keys( vo_name )
        elem.send_keys( Keys.RETURN )
        elem = find_child( "#ask" )
        assert "already in the OB" in elem.text
        click_dialog_button( "Cancel", find_child(".ui-dialog.ask") )
        click_dialog_button( "Cancel" )

        # make sure the player's OB is unchanged
        assert get_sortable_vo_names( sortable ) == [ vo_name ]

        # add the vehicle/ordnance, accept the warning
        add_btn.click()
        elem = find_child( ".ui-dialog .select2-search__field" )
        elem.send_keys( vo_name )
        elem.send_keys( Keys.RETURN )
        elem = find_child( "#ask" )
        assert "already in the OB" in elem.text
        click_dialog_button( "OK", find_child(".ui-dialog.ask") )

        # make sure the vehicle/ordnance was added to the player's OB
        assert get_sortable_vo_names( sortable ) == [ vo_name, vo_name ]

    # do the test
    do_test( "vehicles", "a german vehicle" )
    do_test( "ordnance", "name only" )
Beispiel #9
0
def test_online_images(webapp, webdriver):
    """Test using online images in VASL scenarios."""

    # 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": "german",
        "OB_VEHICLES_1": [{
            "name": "PzKpfw IVH"
        }],
    })

    # configure the user settings
    set_user_settings({
        "include-flags-in-snippets": True,
        "custom-list-bullets": True,
        "include-vasl-images-in-snippets": True,
    })

    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)

    # test player flags
    do_test(
        "players",
        re.compile(
            r'<img src="http://vasl-templates.org/.+/flags/german.png"'),
        re.compile(r'<img src="http://[a-z0-9.]+:\d+/flags/german"'))

    # test custom list bullets
    do_test("ssr",
            re.compile(r'url\("http://vasl-templates.org/.+/bullet.png"\)'),
            re.compile(r'url\("http://[a-z0-9.]+:\d+/.+/bullet.png"\)'))

    # test VASL counter images
    select_tab("ob1")
    do_test(
        "ob_vehicles_1",
        re.compile(
            r'<img src="https://raw.githubusercontent.com/.+/ge/veh/pzivh.gif"'
        ), re.compile(r'<img src="http://[a-z0-9.]+:\d+/counter/2584/front"'))
Beispiel #10
0
 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 )
Beispiel #11
0
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)
Beispiel #12
0
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
Beispiel #13
0
 def _delete_vo( vo_type, player_no, name, webdriver ):
     """Delete a vehicle/ordnance."""
     # check the hint
     select_tab( "ob{}".format( player_no ) )
     _check_hint( vo_type, player_no )
     # delete the vehicle/ordnance
     delete_vo( vo_type, player_no, name, webdriver )
     _expected[ (vo_type,player_no) ].remove( name )
     # check the snippet and hint
     _check_snippet( vo_type, player_no )
     _check_hint( vo_type, player_no )
Beispiel #14
0
 def _add_vo( vo_type, player_no, name ):
     """Add a vehicle/ordnance."""
     # check the hint
     select_tab( "ob{}".format( player_no ) )
     _check_hint( vo_type, player_no )
     # add the vehicle/ordnance
     add_vo( webdriver, vo_type, player_no, name )
     _expected[ (vo_type,player_no) ].append( name )
     # check the snippet and hint
     _check_snippet( vo_type, player_no )
     _check_hint( vo_type, player_no )
Beispiel #15
0
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))
Beispiel #16
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)" ]
Beispiel #17
0
    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)
Beispiel #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"'
        ))
Beispiel #19
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" )
Beispiel #20
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).")
Beispiel #21
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
Beispiel #22
0
 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)
Beispiel #23
0
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 )
Beispiel #24
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)
Beispiel #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()
Beispiel #26
0
def add_vo( webdriver, vo_type, player_no, name ): #pylint: disable=unused-argument
    """Add a vehicle/ordnance."""

    # add the vehicle/ordnance
    select_tab( "ob{}".format( player_no ) )
    elem = find_child( "#ob_{}-add_{}".format( vo_type, player_no ) )
    elem.click()
    # FUDGE! Locating the vehicle/ordnance by name and selecting it is finicky, I suspect
    # because select2 is sensitive about where the mouse is, and we sometimes end up
    # selecting the wrong item :-/ Selecting by name won't work if there are multiple items
    # that start with the same thing, but that shouldn't be a problem.
    dlg = find_child( "#select-vo" )
    elem = find_child( "input", dlg )
    elem.send_keys( name )
    entries = find_children( ".select2-results li", dlg )
    assert len(entries) == 1
    click_dialog_button( "OK" )
Beispiel #27
0
 def do_test(nat, veh_expected, ord_expected):
     """Do the test."""
     # set the specified player
     set_player(1, nat)
     select_tab("ob1")
     # check that the Multi-Applicable Notes controls are visible/hidden
     fieldset = find_child("#tabs-ob1 fieldset[name='ob_vehicles_1']")
     assert find_child(".snippets-notes",
                       fieldset).is_displayed() == veh_expected
     assert find_child("label[for='ob']",
                       fieldset).is_displayed() == veh_expected
     fieldset = find_child("#tabs-ob1 fieldset[name='ob_ordnance_1']")
     assert find_child(".snippets-notes",
                       fieldset).is_displayed() == ord_expected
     assert find_child("label[for='ob']",
                       fieldset).is_displayed() == ord_expected
     # the OB snippet controls should always be visible
     assert find_child(".snippets-ob", fieldset).is_displayed()
Beispiel #28
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)
Beispiel #29
0
    def do_test( month, year, expected ): #pylint: disable=missing-docstring

        # set the specified year
        set_template_params( {
            "SCENARIO_DATE": "{}/01/{}".format( month, year ) if year else ""
        } )

        # select the "count remaining" template and check what's been highlighted
        select_tab( "extras" )
        _select_extras_template( webdriver, "extras/count-remaining" )
        for count_type in expected:
            table = find_child( "table.{}".format( count_type ) )
            cells = []
            for row in find_children( "tr", table ):
                row = list( find_children( "td", row ) )
                assert len(row) == 2
                bgd_col = row[1].value_of_css_property( "background-color" )
                assert bgd_col.startswith( ( "rgb(", "rgba(" ) )
                cells.append( bgd_col != "rgba(0, 0, 0, 0)" )
            assert cells == expected[count_type]
Beispiel #30
0
 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