+
@@ -195,7 +202,7 @@ gOrdnanceListingsUrl = "{{url_for('get_ordnance_listings')}}" ;
-
+
diff --git a/vasl_templates/webapp/tests/fixtures/data/default-template-pack/ob_note.j2 b/vasl_templates/webapp/tests/fixtures/data/default-template-pack/ob_note.j2
new file mode 100644
index 0000000..e81d731
--- /dev/null
+++ b/vasl_templates/webapp/tests/fixtures/data/default-template-pack/ob_note.j2
@@ -0,0 +1 @@
+[{{PLAYER_NAME}}] [{{OB_NOTE}}]{%if OB_NOTE_WIDTH%} (width=[{{OB_NOTE_WIDTH}}]){%endif%}
diff --git a/vasl_templates/webapp/tests/fixtures/template-packs/full/ob_note.j2 b/vasl_templates/webapp/tests/fixtures/template-packs/full/ob_note.j2
new file mode 100644
index 0000000..548c725
--- /dev/null
+++ b/vasl_templates/webapp/tests/fixtures/template-packs/full/ob_note.j2
@@ -0,0 +1 @@
+Customized OB_NOTE.
diff --git a/vasl_templates/webapp/tests/fixtures/template-packs/new-default/ob_note.j2 b/vasl_templates/webapp/tests/fixtures/template-packs/new-default/ob_note.j2
new file mode 100644
index 0000000..4142ba5
--- /dev/null
+++ b/vasl_templates/webapp/tests/fixtures/template-packs/new-default/ob_note.j2
@@ -0,0 +1 @@
+New default OB_NOTE.
diff --git a/vasl_templates/webapp/tests/test_ob_setup.py b/vasl_templates/webapp/tests/test_ob.py
similarity index 66%
rename from vasl_templates/webapp/tests/test_ob_setup.py
rename to vasl_templates/webapp/tests/test_ob.py
index 6ff9b9b..f27d56e 100644
--- a/vasl_templates/webapp/tests/test_ob_setup.py
+++ b/vasl_templates/webapp/tests/test_ob.py
@@ -1,5 +1,6 @@
""" Test generating OB SETUP snippets. """
+import re
import types
from selenium.webdriver.support.ui import Select
@@ -10,48 +11,67 @@ from vasl_templates.webapp.tests.utils import select_tab, find_child, find_child
# ---------------------------------------------------------------------
+# NOTE: Handling of OB setups and OB notes is identical (the only difference
+# is in the template files, where OB setups have a colored header).
+
def test_ob_setup( webapp, webdriver ):
- """Test generating OB SETUP snippets."""
+ """Test generating OB setup snippets."""
+ _do_test_ob_entries( webapp, webdriver, "ob_setups" )
+
+def test_ob_notes( webapp, webdriver ):
+ """Test generating OB note snippets."""
+ _do_test_ob_entries( webapp, webdriver, "ob_notes" )
+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+def _do_test_ob_entries( webapp, webdriver, ob_type ):
+ """Test generating OB setup/notes."""
# initialize
webdriver.get( webapp.url_for( "main" ) )
+ colors = {
+ "german": "col=[OBCOL:german/OBCOL2:german]", #.format( ob_type ) ,
+ "russian": "col=[OBCOL:russian/OBCOL2:russian]" #.format( ob_type )
+ }
- # generate OB SETUP snippets for both players
+ # generate OB setup/note snippets for both players
def check_snippet( player_id, entry_no, expected ):
- """Generate the snippet for an OB setup."""
+ """Generate the snippet for an OB setup/note."""
select_tab( "ob{}".format( player_id ) )
- elems = find_children( "#ob_setup-sortable_{} li input[type='button']".format( player_id ) )
+ elems = find_children( "#{}-sortable_{} li input[type='button']".format( ob_type, player_id ) )
elems[entry_no].click()
+ if ob_type == "ob_notes":
+ expected = re.sub( r" \(col=.*?\)", "", expected )
assert get_clipboard() == expected
- add_ob_setup( webdriver, 1, "ob setup #1" )
- add_ob_setup( webdriver, 1, "ob setup #2", "2px" )
- add_ob_setup( webdriver, 2, "ob
setup #3", "3px" )
- check_snippet( 1, 0, "[German] [ob setup #1] (col=[OBCOL:german/OBCOL2:german])" )
- check_snippet( 1, 1, "[German] [ob setup #2] (col=[OBCOL:german/OBCOL2:german]) (width=[2px])" )
- check_snippet( 2, 0, "[Russian] [ob
setup #3] (col=[OBCOL:russian/OBCOL2:russian]) (width=[3px])" )
+ _do_add_ob_entry( webdriver, 1, ob_type, "{} #1".format(ob_type), None )
+ _do_add_ob_entry( webdriver, 1, ob_type, "{} #2".format(ob_type), "2px" )
+ _do_add_ob_entry( webdriver, 2, ob_type, "
{} #3".format(ob_type), "3px" )
+ check_snippet( 1, 0, "[German] [{} #1] ({})".format( ob_type, colors["german"] ) )
+ check_snippet( 1, 1, "[German] [{} #2] ({}) (width=[2px])".format( ob_type, colors["german"] ) )
+ check_snippet( 2, 0, "[Russian] [
{} #3] ({}) (width=[3px])".format( ob_type, colors["russian"] ) )
# make some changes and check the snippets again
- edit_ob_setup( webdriver, 2, 0, "updated ob setup #3", "" )
- edit_ob_setup( webdriver, 1, 1, "
updated ob setup #2", "200px" )
- edit_ob_setup( webdriver, 1, 0, None, "100px" )
- check_snippet( 2, 0, "[Russian] [updated ob setup #3] (col=[OBCOL:russian/OBCOL2:russian])" )
- check_snippet( 1, 1, "[German] [
updated ob setup #2] (col=[OBCOL:german/OBCOL2:german]) (width=[200px])" )
- check_snippet( 1, 0, "[German] [ob setup #1] (col=[OBCOL:german/OBCOL2:german]) (width=[100px])" )
-
- # delete an OB setup by dragging it into the trash
+ _do_edit_ob_entry( webdriver, 2, ob_type, 0, "updated {} #3".format(ob_type), "" )
+ _do_edit_ob_entry( webdriver, 1, ob_type, 1, "
updated {} #2".format(ob_type), "200px" )
+ _do_edit_ob_entry( webdriver, 1, ob_type, 0, None, "100px" )
+ check_snippet( 2, 0, "[Russian] [updated {} #3] ({})".format( ob_type, colors["russian"] ) )
+ check_snippet( 1, 1, "[German] [
updated {} #2] ({}) (width=[200px])".format( ob_type, colors["german"] ) )
+ check_snippet( 1, 0, "[German] [{} #1] ({}) (width=[100px])".format( ob_type, colors["german"] ) )
+
+ # delete an OB setup/note by dragging it into the trash
def count_entries( player_id ):
- """Count the number of OB setup's."""
- elems = find_children( "#ob_setup-sortable_{} li".format( player_id ) )
+ """Count the number of OB setup/notes."""
+ elems = find_children( "#{}-sortable_{} li".format( ob_type, player_id ) )
return len(elems)
select_tab( "ob1" )
assert count_entries(1) == 2
- elem = find_child( "#ob_setup-sortable_1 li[2]" )
- trash = find_child( "#ob_setup-trash_1" )
+ elem = find_child( "#{}-sortable_1 li[2]".format( ob_type ) )
+ trash = find_child( "#{}-trash_1".format( ob_type ) )
ActionChains(webdriver).drag_and_drop( elem, trash ).perform()
assert count_entries(1) == 1
- # delete an OB setup by emptying its caption
- edit_ob_setup( webdriver, 1, 0, "", None )
+ # delete an OB setup/note by emptying its caption
+ _do_edit_ob_entry( webdriver, 1, ob_type, 0, "", None )
click_dialog_button( "OK" ) # nb: confirm the deletion
assert count_entries(1) == 0
@@ -167,32 +187,47 @@ def test_nationality_specific( webapp, webdriver ):
# ---------------------------------------------------------------------
-def add_ob_setup( webdriver, player_id, caption, width=None ):
+def add_ob_setup( webdriver, player_id, caption, width ):
"""Add a new OB setup."""
+ _do_add_ob_entry( webdriver, player_id, "ob_setups", caption, width )
+
+def add_ob_note( webdriver, player_id, caption, width ):
+ """Add a new OB note."""
+ _do_add_ob_entry( webdriver, player_id, "ob_notes", caption, width )
+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+def _do_add_ob_entry( webdriver, player_id, ob_type, caption, width ):
+ """Add a new OB setup/note."""
select_tab( "ob{}".format( player_id ) )
- elem = find_child( "#ob_setup-add_{}".format( player_id ) )
+ elem = find_child( "#{}-add_{}".format( ob_type, player_id ) )
elem.click()
- edit_ob_setup( webdriver, player_id, None, caption, width )
+ _do_edit_ob_entry( webdriver, player_id, ob_type, None, caption, width )
-# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# ---------------------------------------------------------------------
def edit_ob_setup( webdriver, player_id, entry_no, caption, width ):
"""Edit an OB setup."""
+ _do_edit_ob_entry( webdriver, player_id, "ob_setups", entry_no, caption, width )
+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+def _do_edit_ob_entry( webdriver, player_id, ob_type, entry_no, caption, width ):
+ """Edit an OB setup/note."""
# locate the requested entry and start editing it
if entry_no is not None:
select_tab( "ob{}".format( player_id ) )
- elems = find_children( "#ob_setup-sortable_{} li".format( player_id ) )
+ elems = find_children( "#{}-sortable_{} li".format( ob_type, player_id ) )
elem = elems[ entry_no ]
ActionChains(webdriver).double_click( elem ).perform()
- # edit the OB setup
+ # edit the OB setup/note
if caption is not None:
- elem = find_child( "#edit-ob_setup textarea" )
+ elem = find_child( "#edit-simple_note textarea" )
elem.clear()
elem.send_keys( caption )
if width is not None:
- elem = find_child( "#edit-ob_setup input[type='text']" )
+ elem = find_child( "#edit-simple_note input[type='text']" )
elem.clear()
elem.send_keys( width )
click_dialog_button( "OK" )
diff --git a/vasl_templates/webapp/tests/test_scenario_persistence.py b/vasl_templates/webapp/tests/test_scenario_persistence.py
index 01f895e..9aef60f 100644
--- a/vasl_templates/webapp/tests/test_scenario_persistence.py
+++ b/vasl_templates/webapp/tests/test_scenario_persistence.py
@@ -34,14 +34,22 @@ def test_scenario_persistence( webapp, webdriver ):
"SSR_WIDTH": "103",
},
"ob1": {
- "OB_SETUP_1": [ { "caption": "ob setup 1a", "width": "" }, { "caption": "ob setup 1b", "width": "200px" } ],
+ "OB_SETUPS_1": [
+ { "caption": "ob setup 1a", "width": "" },
+ { "caption": "ob setup 1b", "width": "200px" }
+ ],
+ "OB_NOTES_1": [
+ { "caption": "ob note 1a", "width": "10em" },
+ { "caption": "ob note 1b", "width": "" }
+ ],
"VEHICLES_1": [ "a russian vehicle", "another russian vehicle" ],
"VEHICLES_WIDTH_1": "202",
"ORDNANCE_1": [ "a russian ordnance", "another russian ordnance" ],
"ORDNANCE_WIDTH_1": "203",
},
"ob2": {
- "OB_SETUP_2": [ { "caption": "ob setup 2", "width": "" } ],
+ "OB_SETUPS_2": [ { "caption": "ob setup 2", "width": "" } ],
+ "OB_NOTES_2": [ { "caption": "ob note 2", "width": "" } ],
"VEHICLES_2": [ "a german vehicle" ],
"VEHICLES_WIDTH_2": "302",
"ORDNANCE_2": [ "a german ordnance" ],
@@ -77,7 +85,9 @@ def test_scenario_persistence( webapp, webdriver ):
for field,val in scenario_params[tab_id].items():
if field == "SSR":
continue # nb: this requires special handling, we do it below
- if field in ("OB_SETUP_1","OB_SETUP_2"):
+ if field in ("OB_SETUPS_1","OB_SETUPS_2"):
+ continue # nb: this requires special handling, we do it below
+ if field in ("OB_NOTES_1","OB_NOTES_2"):
continue # nb: this requires special handling, we do it below
if field in ("VEHICLES_1","ORDNANCE_1","VEHICLES_2","ORDNANCE_2"):
continue # nb: this requires special handling, we do it below
@@ -91,8 +101,10 @@ def test_scenario_persistence( webapp, webdriver ):
assert elem.get_attribute("value") == val
ssrs = _get_ssrs()
assert ssrs == scenario_params["scenario"]["SSR"]
- assert _get_ob_setups(1) == [ obs["caption"] for obs in scenario_params["ob1"]["OB_SETUP_1"] ]
- assert _get_ob_setups(2) == [ obs["caption"] for obs in scenario_params["ob2"]["OB_SETUP_2"] ]
+ assert _get_ob_entries("ob_setups",1) == [ obs["caption"] for obs in scenario_params["ob1"]["OB_SETUPS_1"] ]
+ assert _get_ob_entries("ob_setups",2) == [ obs["caption"] for obs in scenario_params["ob2"]["OB_SETUPS_2"] ]
+ assert _get_ob_entries("ob_notes",1) == [ obs["caption"] for obs in scenario_params["ob1"]["OB_NOTES_1"] ]
+ assert _get_ob_entries("ob_notes",2) == [ obs["caption"] for obs in scenario_params["ob2"]["OB_NOTES_2"] ]
assert _get_vo("vehicle",1) == scenario_params["ob1"]["VEHICLES_1"]
assert _get_vo("ordnance",1) == scenario_params["ob1"]["ORDNANCE_1"]
assert _get_vo("vehicle",2) == scenario_params["ob2"]["VEHICLES_2"]
@@ -164,12 +176,12 @@ def _get_ssrs():
select_tab( "scenario" )
return [ c.text for c in find_children("#ssr-sortable li") ]
-def _get_ob_setups( player_id ):
- """Get the OB setup's from the UI."""
+def _get_ob_entries( ob_type, player_id ):
+ """Get the OB setup/notes from the UI."""
select_tab( "ob{}".format( player_id ) )
return [
c.text
- for c in find_children( "#ob_setup-sortable_{} li".format( player_id ) )
+ for c in find_children( "#{}-sortable_{} li".format( ob_type, player_id ) )
]
def _get_vo( vo_type, player_id ):
diff --git a/vasl_templates/webapp/tests/test_snippets.py b/vasl_templates/webapp/tests/test_snippets.py
index 4bdfd44..5832aa6 100644
--- a/vasl_templates/webapp/tests/test_snippets.py
+++ b/vasl_templates/webapp/tests/test_snippets.py
@@ -2,6 +2,7 @@
from selenium.webdriver.common.keys import Keys
+from vasl_templates.webapp.tests.test_ob import add_ob_setup, add_ob_note
from vasl_templates.webapp.tests.utils import select_tab, set_template_params, get_clipboard
from vasl_templates.webapp.tests.utils import get_stored_msg, dismiss_notifications, find_child
from vasl_templates.webapp.tests.utils import for_each_template, wait_for
@@ -171,8 +172,8 @@ def test_edit_templates( webapp, webdriver ):
elem.send_keys( Keys.ESCAPE )
def test_template( template_id, orig_template_id ):
"""Test editing a template."""
- if template_id == "ob_setup":
- return # nb: this requires special handling (done below)
+ if template_id in("ob_setup","ob_note"):
+ return # nb: these require special handling (done below)
# edit the template
elem = find_child( "a.edit-template-link[data-id='{}']".format( template_id ) )
webdriver.execute_script( "$(arguments[0]).click();", elem )
@@ -181,21 +182,33 @@ def test_edit_templates( webapp, webdriver ):
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
- wait_for( 2, # FUDGE! Work-around a weird timing problem on Linux :shrug:
+ wait_for( 5, # FUDGE! Work-around a weird timing problem on Linux :shrug:
lambda: get_clipboard() == "EDITED TEMPLATE: {}".format( orig_template_id )
)
for_each_template( test_template )
# customize the OB SETUP template
- select_tab( "ob2" )
- elem = find_child( "#tabs-ob2 input[type='button'][data-id='ob_setup']" )
+ select_tab( "ob1" )
+ elem = find_child( "#tabs-ob1 input[type='button'][data-id='ob_setup']" )
elem.click()
edit_template( "ob_setup" )
# check that the new template is being used
- from vasl_templates.webapp.tests.test_ob_setup import add_ob_setup
for player_id in range(1,2+1):
- add_ob_setup( webdriver, player_id, "ob setup (ignored)" )
- elem = find_child( "#ob_setup-sortable_{} li input[type='button']".format( player_id ) )
+ add_ob_setup( webdriver, player_id, "ob setup (ignored)", None )
+ elem = find_child( "#ob_setups-sortable_{} li input[type='button']".format( player_id ) )
elem.click()
assert get_clipboard() == "EDITED TEMPLATE: ob_setup"
+
+ # customize the OB NOTE template
+ select_tab( "ob2" )
+ elem = find_child( "#tabs-ob2 input[type='button'][data-id='ob_note']" )
+ elem.click()
+ edit_template( "ob_note" )
+
+ # check that the new template is being used
+ for player_id in range(1,2+1):
+ add_ob_note( webdriver, player_id, "ob note (ignored)", None )
+ elem = find_child( "#ob_notes-sortable_{} li input[type='button']".format( player_id ) )
+ elem.click()
+ assert get_clipboard() == "EDITED TEMPLATE: ob_note"
diff --git a/vasl_templates/webapp/tests/test_template_packs.py b/vasl_templates/webapp/tests/test_template_packs.py
index ebd2edb..41ed60c 100644
--- a/vasl_templates/webapp/tests/test_template_packs.py
+++ b/vasl_templates/webapp/tests/test_template_packs.py
@@ -8,7 +8,7 @@ import base64
from selenium.webdriver.support.ui import Select
from vasl_templates.webapp import snippets
-from vasl_templates.webapp.tests.test_ob_setup import add_ob_setup
+from vasl_templates.webapp.tests import test_ob
from vasl_templates.webapp.tests.utils import select_tab, select_menu_option, dismiss_notifications
from vasl_templates.webapp.tests.utils import get_clipboard, get_stored_msg, set_stored_msg
from vasl_templates.webapp.tests.utils import for_each_template, find_child, find_children
@@ -26,10 +26,11 @@ def test_individual_files( webapp, webdriver ):
"""Test uploading a customized version of the template."""
# make sure generating a snippet returns something
dismiss_notifications()
- if template_id == "ob_setup":
+ if template_id in ("ob_setup","ob_note"):
select_tab( "ob1" )
- add_ob_setup( webdriver, 1, "test ob setup" )
- elems = find_children( "#ob_setup-sortable_1 li input[type='button']" )
+ func = getattr( test_ob, "add_"+template_id )
+ func( webdriver, 1, "test {}".format(template_id), None )
+ elems = find_children( "#{}s-sortable_1 li input[type='button']".format( template_id ) )
elem = elems[0]
else:
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
@@ -149,21 +150,22 @@ def test_nationality_data( webapp, webdriver ):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-def _check_snippets( webdriver, func ):
+def _check_snippets( webdriver, expected ):
"""Check that snippets are being generated as expected."""
def test_template( template_id, orig_template_id ):
"""Test each template."""
dismiss_notifications()
- if template_id == "ob_setup":
+ if template_id in ("ob_setup","ob_note"):
select_tab( "ob1" )
- add_ob_setup( webdriver, 1, "test ob setup" )
- elems = find_children( "#ob_setup-sortable_1 li input[type='button']" )
+ func = getattr( test_ob, "add_"+template_id )
+ func( webdriver, 1, "test {}".format(template_id), None )
+ elems = find_children( "#{}s-sortable_1 li input[type='button']".format( template_id ) )
elem = elems[0]
else:
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
- assert get_clipboard() == func( template_id )
+ assert get_clipboard() == expected( template_id )
for_each_template( test_template )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/vasl_templates/webapp/tests/utils.py b/vasl_templates/webapp/tests/utils.py
index 894846c..b058bde 100644
--- a/vasl_templates/webapp/tests/utils.py
+++ b/vasl_templates/webapp/tests/utils.py
@@ -13,8 +13,8 @@ from selenium.common.exceptions import NoSuchElementException, StaleElementRefer
# standard templates
_STD_TEMPLATES = {
"scenario": [ "scenario", "players", "victory_conditions", "ssr" ],
- "ob1": [ "ob_setup_1", "vehicles_1", "ordnance_1" ],
- "ob2": [ "ob_setup_2", "vehicles_2", "ordnance_2" ],
+ "ob1": [ "ob_setup_1", "ob_note_1", "vehicles_1", "ordnance_1" ],
+ "ob2": [ "ob_setup_2", "ob_note_2", "vehicles_2", "ordnance_2" ],
}
# nationality-specific templates
@@ -47,6 +47,8 @@ def for_each_template( func ):
select_tab( tab_id )
if template_id.startswith( "ob_setup_" ):
template_id2 = "ob_setup"
+ elif template_id.startswith( "ob_note_" ):
+ template_id2 = "ob_note"
elif template_id.startswith( "vehicles_" ):
template_id2 = "vehicles"
elif template_id.startswith( "ordnance_" ):
@@ -54,7 +56,7 @@ def for_each_template( func ):
else:
template_id2 = template_id
func( template_id2, template_id )
- if template_id not in ("ob_setup_2","vehicles_2","ordnance_2"):
+ if template_id not in ("ob_setup_2","ob_note_2","vehicles_2","ordnance_2"):
templates_to_test.remove( template_id2 )
# test the nationality-specific templates
@@ -88,7 +90,7 @@ def select_menu_option( menu_id ):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-def set_template_params( params ):
+def set_template_params( params ): #pylint: disable=too-many-branches
"""Set template parameters."""
for key,val in params.items():
@@ -101,15 +103,24 @@ def set_template_params( params ):
add_ssr( _webdriver, ssr )
continue
- # check for OB set up (these require special handling)
- if key in ("OB_SETUP_1","OB_SETUP_2"):
+ # check for OB setups (these require special handling)
+ if key in ("OB_SETUPS_1","OB_SETUPS_2"):
# add them in (nb: we don't consider any existing OB setup's)
- from vasl_templates.webapp.tests.test_ob_setup import add_ob_setup #pylint: disable=cyclic-import
+ from vasl_templates.webapp.tests.test_ob import add_ob_setup #pylint: disable=cyclic-import
player_id = int( key[-1] )
for entry in val:
add_ob_setup( _webdriver, player_id, entry.get("caption",""), entry.get("width","") )
continue
+ # check for OB notes (these require special handling)
+ if key in ("OB_NOTES_1","OB_NOTES_2"):
+ from vasl_templates.webapp.tests.test_ob import add_ob_note #pylint: disable=cyclic-import
+ # add them in (nb: we don't consider any existing OB notes)
+ player_id = int( key[-1] )
+ for entry in val:
+ add_ob_note( _webdriver, player_id, entry.get("caption",""), entry.get("width","") )
+ continue
+
# check for vehicles/ordnance (these require special handling)
if key in ("VEHICLES_1","ORDNANCE_1","VEHICLES_2","ORDNANCE_2"):
# add them in (nb: we don't consider any existing vehicles/ordnance)