Allow templates to be edited.

master
Pacman Ghost 6 years ago
parent a2407b095d
commit 9930ee946c
  1. 16
      vasl_templates/webapp/static/css/main.css
  2. 16
      vasl_templates/webapp/static/css/tabs-ob.css
  3. 8
      vasl_templates/webapp/static/css/tabs-scenario.css
  4. 45
      vasl_templates/webapp/static/main.js
  5. 58
      vasl_templates/webapp/static/snippets.js
  6. 13
      vasl_templates/webapp/templates/index.html
  7. 101
      vasl_templates/webapp/tests/test_generate.py
  8. 90
      vasl_templates/webapp/tests/test_template_packs.py
  9. 54
      vasl_templates/webapp/tests/utils.py

@ -20,12 +20,15 @@ body { height: 100% ; }
#tabs .ui-tabs-nav li img { position: relative ; top: 2px ; height: 1em ; }
.snippet-control-menu-item { font-size: 75% ; }
.ui-selectmenu-icon.ui-icon { margin-top: -8px; }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#tabs-scenario {
display: grid ; display: -ms-grid ;
grid-template-rows: 14em 1fr ; -ms-grid-rows: 14em 1fr ;
grid-template-columns: 25em 1fr ; -ms-grid-columns: 25em 1fr ;
grid-template-rows: 16em 1fr ; -ms-grid-rows: 14em 1fr ;
grid-template-columns: 28em 1fr ; -ms-grid-columns: 28em 1fr ;
}
#tabs-scenario fieldset.tr {
@ -80,6 +83,15 @@ input[type="text"] { margin-bottom: 0.25em ; }
/* -------------------------------------------------------------------- */
.ui-dialog-titlebar { padding: 0.2em 0.5em 0.2em 0.5em !important ; }
.ui-dialog-titlebar-close { margin-top: -10px !important ; }
.ui-dialog.edit-template .ui-dialog-buttonpane { border: none ; padding: 0 ; font-size: 75% ; }
#edit-template { padding: 2px ; }
.ui-dialog.edit-template textarea { resize: none ; width: calc(100% - 4px) ; height: 100% ; }
.ui-dialog.edit-template textarea { font-family: "Courier New" ; font-size: 80% ; }
.ui-dialog.edit-template button { margin: 0 0 0 5px ; padding: 0.1em 0.2em ; }
.ui-dialog.edit-ssr .ui-dialog-titlebar { display: none ; }
.ui-dialog.edit-ssr .ui-dialog-buttonpane { border: none ; padding: 0 ; font-size: 75% ; }
#edit-ssr { padding: 2px ; }

@ -1,20 +1,14 @@
.panel-obsetup {
height: 100% ;
display: grid ; display: -ms-grid ;
grid-template-rows: 1fr 2em ; -ms-grid-rows: 1fr 2em ;
grid-template-rows: 1fr 2.5em ; -ms-grid-rows: 1fr 2.5em ;
grid-template-columns: 1fr ; -ms-grid-columns: 1fr ;
}
/* FUDGE! IE hackamathon follows (nb: <label> doesn't work, we use <div> for labels instead :-/) */
.panel-obsetup .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; }
.panel-obsetup textarea { width: 100% ; height: 100% ; resize: none ; }
.panel-obsetup input[data-id='mol'] { float: left ; }
.panel-obsetup input[data-id='mol-p'] { float: left ; }
.panel-obsetup input[data-id='pf'] { float: left ; }
.panel-obsetup input[data-id='psk'] { float: left ; }
.panel-obsetup input[data-id='atmm'] { float: left ; }
.panel-obsetup input[data-id='baz'] { float: left ; }
.panel-obsetup input[data-id='piat'] { float: left ; }
.panel-obsetup input[data-id='ob_setup_1'] { float: right ; }
.panel-obsetup input[data-id='ob_setup_2'] { float: right ; }
.panel-obsetup div.r { float: right ; font-size: 75% ; }
.panel-obsetup .footer { font-size: 75% ; }
.panel-obsetup div.snippet-control { float: left ; margin: 0.25em 0.25em 0 0 ; }
.panel-obsetup .footer .r { display: block-inline ; float: right ; }
.panel-obsetup .footer .r div.snippet-control { float: none ; margin-right: 0 ; }

@ -13,7 +13,6 @@
#panel-scenario div.last_row { -ms-grid-row: 3 ; -ms-grid-column: 2 ; }
#panel-scenario .last_row .r { display: block-inline ; float: right ; font-size: 75% ; }
#panel-scenario input[data-id="scenario"] { height: 2em ; }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
@ -22,6 +21,7 @@
display: grid ; display: -ms-grid ;
grid-template-columns: 5em 1fr 3em 3em ; -ms-grid-columns: 5em 1fr 3em 3em ;
}
#panel-players .footer { grid-column-start: 1 ; grid-column-end: 5 ; }
/* FUDGE! IE hackamathon follows (nb: <label> doesn't work, we use <div> for labels instead :-/) */
#panel-players div[data-labelfor="ELR"] { -ms-grid-row: 1 ; -ms-grid-column: 3 ; }
#panel-players div[data-labelfor="SAN"] { -ms-grid-row: 1 ; -ms-grid-column: 4 ; }
@ -33,7 +33,7 @@
#panel-players select[name="PLAYER_2"] { -ms-grid-row: 3 ; -ms-grid-column: 2 ; }
#panel-players select[name="PLAYER_2_ELR"] { -ms-grid-row: 3 ; -ms-grid-column: 3 ; }
#panel-players select[name="PLAYER_2_SAN"] { -ms-grid-row: 3 ; -ms-grid-column: 4 ; }
#panel-players input[data-id="players"] { -ms-grid-row: 4 ; -ms-grid-column: 4 ; }
#panel-players .footer { -ms-grid-row: 4 ; -ms-grid-column: 1 ; -ms-grid-column-span: 4 ; }
#panel-players div[data-labelfor="ELR"] { margin-left: 0.25em ; }
#panel-players div[data-labelfor="SAN"] { margin-left: 0.25em ; }
@ -43,6 +43,9 @@
#panel-players select[name="PLAYER_2_ELR"] { margin-right: 0.25em ; }
#panel-players input[data-id="players"] { margin-top: 0.25em ; }
#panel-players .footer { margin-top: 0.25em ; font-size: 75% ; text-align: right ; }
#panel-players .footer input[type='button'] { margin: 0 ; }
/* -------------------------------------------------------------------- */
#panel-vc {
@ -55,7 +58,6 @@
#panel-vc textarea { width: 100% ; height: 100% ; resize: none ; }
#panel-vc .footer { text-align: right ; font-size: 75% ; }
#panel-vc input[data-id="victory_conditions"] { height: 2em ; }
/* -------------------------------------------------------------------- */

@ -163,11 +163,52 @@ $(document).ready( function () {
} ) ;
$(window).trigger( "resize" ) ;
// handle requests to generate HTML snippets
// replace all the "generate" buttons with "generate/edit" button/droplist's
$("input[type='button'].generate").each( function() {
var template_id = $(this).attr( "data-id" ) ;
var template_id2 = (template_id.substring(0,9) === "ob_setup_") ? "ob_setup" : template_id ;
var buf = [ "<div class='snippet-control' data-id='" + template_id + "'>",
$(this).prop( "outerHTML" ),
"<select data-id='" + template_id2 + "'>",
"<option value='edit' class='edit-template'>Edit</option>",
"</select>",
"</div>"
] ;
var $newElem = $( buf.join("") ) ;
$newElem.controlgroup() ;
$newElem.children("select").each( function() {
$(this).selectmenu( {
classes: {
"ui-selectmenu-button": "ui-button-icon-only",
"ui-selectmenu-menu": "snippet-control-menu-item",
},
} ) ;
} ) ;
$newElem.children(".ui-button-icon-only").css( "width", "1em" ) ;
$newElem.children(".ui-selectmenu-button").click( function() { $(this).blur() ; } ) ;
$(this).replaceWith( $newElem ) ;
} ) ;
// handle requests to generate/edit HTML snippets
$("input[type='button'].generate").click( function() {
generate_snippet( $(this) ) ;
} ) ;
$("div.snippet-control select").on( "selectmenuselect", function() {
edit_template( $(this).attr("data-id") ) ;
} ) ;
// add some dummy links for the test suite to edit templates
if ( getUrlParam( "edit_template_links" ) ) {
$("input[type='button'].generate").each( function() {
var template_id = $(this).attr( "data-id" ) ;
if ( template_id.substring(0,9) === "ob_setup_" )
template_id = "ob_setup" ;
$( "<a href='#' class='edit-template-link' data-id='" + template_id + "'" +
" onclick='edit_template(\"" + template_id + "\")'" +
"></a>"
).appendTo( "body" ) ;
} ) ;
}
} ) ;
// --------------------------------------------------------------------
@ -191,7 +232,7 @@ function on_player_change( $select )
for ( var nat in _NATIONALITY_SPECIFIC_BUTTONS ) {
for ( var i=0 ; i < _NATIONALITY_SPECIFIC_BUTTONS[nat].length ; ++i ) {
var button_id = _NATIONALITY_SPECIFIC_BUTTONS[nat][i] ;
$elem = $( "#panel-obsetup" + player_id + " input[type='button'][data-id='" + button_id + "']" ) ;
$elem = $( "#panel-obsetup" + player_id + " div.snippet-control[data-id='" + button_id + "']" ) ;
$elem.css( "display", nat == player_nat ? "block" : "none" ) ;
}
}

@ -117,15 +117,9 @@ function generate_snippet( $btn )
showWarningMsg( "Both players have the same nationality!" ) ;
// get the template to generate the snippet from
var templ ;
if ( template_id in gUserDefinedTemplates )
templ = gUserDefinedTemplates[template_id] ;
else if ( template_id in gDefaultTemplates )
templ = gDefaultTemplates[template_id] ;
else {
showErrorMsg( "Unknown template: <span class='pre'>" + escapeHTML(template_id) + "</span>" ) ;
var templ = get_template( template_id ) ;
if ( templ === null )
return ;
}
var func ;
try {
func = jinja.compile( templ ).render ;
@ -180,6 +174,54 @@ function unload_params()
return params ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function get_template( template_id )
{
// get the specified template
if ( template_id in gUserDefinedTemplates )
return gUserDefinedTemplates[template_id] ;
else if ( template_id in gDefaultTemplates )
return gDefaultTemplates[template_id] ;
showErrorMsg( "Unknown template: <span class='pre'>" + escapeHTML(template_id) + "</span>" ) ;
return null ;
}
// --------------------------------------------------------------------
function edit_template( template_id )
{
// get the specified template
var template = get_template( template_id ) ;
if ( template === null )
return ;
function on_template_change() {
// install the new template
gUserDefinedTemplates[template_id] = $("#edit-template textarea").val() ;
}
// let the user edit the template
$("#edit-template textarea").val( template ) ;
$("#edit-template").dialog( {
dialogClass: "edit-template",
title: "Editing template: " + escapeHTML(template_id),
modal: false,
minWidth: 400, minHeight: 200,
open: function() {
$(this).height( $(this).height() ) ; // fudge: force the textarea to resize
$("#edit-template").css( "overflow", "hidden" ) ;
$("#edit-template textarea").change( on_template_change ) ;
},
close: function() {
$("#edit-template textarea").off( "change", on_template_change ) ;
},
buttons: {
Close: function() { $(this).dialog( "close" ) ; },
},
} ) ;
}
// --------------------------------------------------------------------
function on_load_scenario()

@ -42,7 +42,7 @@
<div class="r">
<label for="SCENARIO_WIDTH">Width:</label>
<input type="text" class="param" name="SCENARIO_WIDTH" size="5">
<input type="button" class="generate" data-id="scenario" value="Go">
<input type="button" class="generate" data-id="scenario" value="Snippet">
</div>
</div>
</div>
@ -54,7 +54,7 @@
<div class="label" data-labelfor="PLAYER_2">Player 2:</div> <select name="PLAYER_2" class="param"></select>
<select name="PLAYER_2_ELR" class="param"></select>
<select name="PLAYER_2_SAN" class="param"></select>
<div></div> <div></div> <div></div> <input type="button" class="generate" data-id="players" value="Go">
<div class="footer"> <input type="button" class="generate" data-id="players" value="Snippet"> </div>
</div>
</fieldset>
<fieldset class="tr"> <legend>Victory Conditions</legend>
@ -63,7 +63,7 @@
<div class="footer">
<label for="VICTORY_CONDITIONS_WIDTH">Width:</label>
<input type="text" class="param" name="VICTORY_CONDITIONS_WIDTH" size="5">
<input type="button" class="generate" data-id="victory_conditions" value="Go">
<input type="button" class="generate" data-id="victory_conditions" value="Snippet">
</div>
</div>
</fieldset>
@ -80,7 +80,7 @@
</div>
<label for="SSR_WIDTH">Width:</label>
<input type="text" class="param" name="SSR_WIDTH" size="5">
<input type="button" class="generate" data-id="ssr" value="Go">
<input type="button" class="generate" data-id="ssr" value="Snippet">
</div>
</div>
</fieldset>
@ -98,10 +98,10 @@
<input type="button" class="generate" data-id="atmm" value="ATMM">
<input type="button" class="generate" data-id="baz" value="BAZ">
<input type="button" class="generate" data-id="piat" value="PIAT">
<input type="button" class="generate" data-id="ob_setup_1" value="Go">
<div class="r">
<label for="OB_SETUP_WIDTH_1">Width:</label>
<input type="text" class="param" name="OB_SETUP_WIDTH_1" size="5">
<input type="button" class="generate" data-id="ob_setup_1" value="Snippet">
</div>
</div>
</div>
@ -126,6 +126,7 @@
</div>
</div>
<div id="edit-template" style="display:none;"> <textarea></textarea> </div>
<div id="edit-ssr" style="display:none;"> <b>Enter the SSR content:</b> <textarea></textarea> </div>
<div id="ask" style="display:none;"></div>
@ -146,7 +147,7 @@ gGetAutoloadTemplatesUrl = "{{url_for('get_autoload_templates')}}" ;
gGetNationalitiesUrl = "{{url_for('get_nationalities')}}" ;
</script>
<script src="{{url_for('static',filename='main.js')}}"></script>
<script src="{{url_for('static',filename='generate.js')}}"></script>
<script src="{{url_for('static',filename='snippets.js')}}"></script>
<script src="{{url_for('static',filename='ssr.js')}}"></script>
<script src="{{url_for('static',filename='utils.js')}}"></script>

@ -1,40 +1,10 @@
""" Test HTML snippet generation. """
from vasl_templates.webapp.tests.utils import set_template_params, get_clipboard, get_stored_msg, find_child
from selenium.webdriver.common.keys import Keys
# ---------------------------------------------------------------------
def _test_snippet( webdriver, template_id, params, expected, expected2 ): #pylint: disable=unused-argument
"""Do a single test."""
# set the template parameters
set_template_params( params )
# generate the snippet
submit = find_child( "input.generate[data-id='{}']".format(template_id) )
submit.click()
snippet = get_clipboard()
lines = [ l.strip() for l in snippet.split("\n") ]
snippet = " | ".join( l for l in lines if l )
assert snippet == expected
# check warnings for mandatory parameters
last_warning = get_stored_msg( "_last-warning_" ) or ""
if isinstance( expected2, list):
# check for mandatory parameters
param_names = [ "scenario name", "scenario location", "scenario date" ]
for pname in param_names:
if pname in expected2:
assert pname in last_warning
else:
assert pname not in last_warning
elif isinstance(expected2, str):
# check for a specific error message
assert expected2 == last_warning
else:
# make sure there was no warning message
assert expected2 is None
assert not last_warning
from vasl_templates.webapp.tests.utils import 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
# ---------------------------------------------------------------------
@ -85,7 +55,7 @@ def test_scenario_snippets( webapp, webdriver ):
None
)
# ---------------------------------------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def test_vc_snippets( webapp, webdriver ):
"""Test HTML snippet generation."""
@ -118,7 +88,7 @@ def test_vc_snippets( webapp, webdriver ):
None
)
# ---------------------------------------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def test_players_snippets( webapp, webdriver ):
"""Test HTML snippet generation."""
@ -146,3 +116,62 @@ def test_players_snippets( webapp, webdriver ):
"player1=[british:British] ; ELR=[1] ; SAN=[2] | player2=[british:British] ; ELR=[3] ; SAN=[4]",
[ "Both players have the same nationality!" ],
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def _test_snippet( webdriver, template_id, params, expected, expected2 ): #pylint: disable=unused-argument
"""Do a single test."""
# set the template parameters
set_template_params( params )
# generate the snippet
submit = find_child( "input.generate[data-id='{}']".format(template_id) )
submit.click()
snippet = get_clipboard()
lines = [ l.strip() for l in snippet.split("\n") ]
snippet = " | ".join( l for l in lines if l )
assert snippet == expected
# check warnings for mandatory parameters
last_warning = get_stored_msg( "_last-warning_" ) or ""
if isinstance( expected2, list):
# check for mandatory parameters
param_names = [ "scenario name", "scenario location", "scenario date" ]
for pname in param_names:
if pname in expected2:
assert pname in last_warning
else:
assert pname not in last_warning
elif isinstance(expected2, str):
# check for a specific error message
assert expected2 == last_warning
else:
# make sure there was no warning message
assert expected2 is None
assert not last_warning
# ---------------------------------------------------------------------
def test_edit_templates( webapp, webdriver ):
"""Test editing templates."""
# initialize
webdriver.get( webapp.url_for( "main", edit_template_links=1 ) )
# try uploading a customized version of each template
def test_template( template_id, orig_template_id ):
"""Test editing a template."""
# edit the template
elem = find_child( "a.edit-template-link[data-id='{}']".format( template_id ) )
webdriver.execute_script( "$(arguments[0]).click();", elem )
elem = find_child( "#edit-template textarea" )
elem.clear()
elem.send_keys( "EDITED TEMPLATE: {}".format( orig_template_id ) )
elem.send_keys( Keys.ESCAPE )
# check that the new template is being used
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
assert get_clipboard() == "EDITED TEMPLATE: {}".format( orig_template_id )
for_each_template( test_template )

@ -5,24 +5,9 @@ import zipfile
import tempfile
import base64
from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.tests.utils import select_tab, select_menu_option, get_clipboard
from vasl_templates.webapp.tests.utils import select_menu_option, get_clipboard
from vasl_templates.webapp.tests.utils import get_stored_msg, set_stored_msg, dismiss_notifications, find_child
# standard templates
STD_TEMPLATES = {
"scenario": [ "scenario", "players", "victory_conditions", "ssr" ],
"ob1": [ "ob_setup_1" ],
}
# nationality-specific templates
NAT_TEMPLATES = {
"german": [ "pf", "psk", "atmm" ],
"russian": [ "mol", "mol-p" ],
"american": [ "baz" ],
"british": [ "piat" ],
}
from vasl_templates.webapp.tests.utils import for_each_template
# ---------------------------------------------------------------------
@ -32,52 +17,26 @@ def test_individual_files( webapp, webdriver ):
# initialize
webdriver.get( webapp.url_for( "main", store_msgs=1, template_pack_persistence=1 ) )
# generate a list of all the templates we need to test
templates_to_test = set()
dname = os.path.join( os.path.split(__file__)[0], "../data/default-templates" )
for fname in os.listdir(dname):
if os.path.splitext(fname)[1] != ".j2":
continue
templates_to_test.add( fname )
# initialize
def test_template( template_id ):
# try uploading a customized version of each template
def test_template( template_id, orig_template_id ):
"""Test uploading a customized version of the template."""
# make sure generating a snippet returns something
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( template_id ) )
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
assert get_clipboard() != ""
# upload a new template
fname = ("ob_setup" if template_id.startswith("ob_setup_") else template_id) + ".j2"
fname = template_id + ".j2"
set_stored_msg( "template_pack_persistence",
"{} | {}".format( fname, "UPLOADED TEMPLATE" )
)
select_menu_option( "template_pack" )
# make sure generating a snippet returns the new version
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( template_id ) )
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
assert get_clipboard() == "UPLOADED TEMPLATE"
templates_to_test.remove( fname )
# try uploading a customized version of each template
for tab_id,template_ids in STD_TEMPLATES.items():
select_tab( tab_id )
for template_id in template_ids:
test_template( template_id )
# try uploading a customized version of each nationality-specific template
for nat,template_ids in NAT_TEMPLATES.items():
select_tab( "scenario" )
sel = Select( find_child( "select[name='PLAYER_1']" ) )
sel.select_by_value( nat )
select_tab( "ob1" )
for template_id in template_ids:
test_template(template_id )
# make sure we tested everything
assert not templates_to_test
for_each_template( test_template )
# try uploading a template with an incorrect filename extension
set_stored_msg( "template_pack_persistence",
@ -110,9 +69,7 @@ def test_zip_files( webapp, webdriver ):
# check that the uploaded templates are being used
_check_snippets(
lambda tid: "Customized {}.".format(
"OB_SETUP" if tid.startswith("ob_setup_") else tid.upper()
)
lambda tid: "Customized {}.".format( tid.upper() )
)
# upload only part of template pack
@ -142,32 +99,21 @@ def test_autoload_template_pack( webapp, webdriver ):
# check that the autoload'ed templates are being used
_check_snippets(
lambda tid: "Autoload'ed {}.".format(
"OB_SETUP" if tid.startswith("ob_setup_") else tid.upper()
)
lambda tid: "Autoload'ed {}.".format( tid.upper() )
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def _check_snippets( func ):
"""Check that snippets are being generated as expected."""
for tab_id,template_ids in STD_TEMPLATES.items():
select_tab( tab_id )
for template_id in template_ids:
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( template_id ) )
elem.click()
assert get_clipboard() == func(template_id)
for nat,template_ids in NAT_TEMPLATES.items():
select_tab( "scenario" )
sel = Select( find_child( "select[name='PLAYER_1']" ) )
sel.select_by_value( nat )
select_tab( "ob1" )
for template_id in template_ids:
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( template_id ) )
elem.click()
assert get_clipboard() == func(template_id)
def test_template( template_id, orig_template_id ):
"""Test each template."""
dismiss_notifications()
elem = find_child( "input.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
assert get_clipboard() == func( template_id )
for_each_template( test_template )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

@ -1,5 +1,6 @@
""" Helper utilities. """
import os
import urllib.request
import json
import time
@ -9,10 +10,62 @@ from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
# standard templates
_STD_TEMPLATES = {
"scenario": [ "scenario", "players", "victory_conditions", "ssr" ],
"ob1": [ "ob_setup_1" ],
"ob2": [ "ob_setup_2" ],
}
# nationality-specific templates
_NAT_TEMPLATES = {
"german": [ "pf", "psk", "atmm" ],
"russian": [ "mol", "mol-p" ],
"american": [ "baz" ],
"british": [ "piat" ],
}
_webdriver = None
# ---------------------------------------------------------------------
def for_each_template( func ):
"""Test each template."""
# generate a list of all the templates we need to test
templates_to_test = set()
dname = os.path.join( os.path.split(__file__)[0], "../data/default-templates" )
for fname in os.listdir(dname):
fname,extn = os.path.splitext( fname )
if extn != ".j2":
continue
templates_to_test.add( fname )
# test the standard templates
for tab_id,template_ids in _STD_TEMPLATES.items():
select_tab( tab_id )
for template_id in template_ids:
template_id2 = "ob_setup" if template_id.startswith("ob_setup_") else template_id
func( template_id2, template_id )
if template_id != "ob_setup_2":
templates_to_test.remove( template_id2 )
# test the nationality-specific templates
# NOTE: The buttons are the same on the OB1 and OB2 tabs, so we only test for player 1.
for nat,template_ids in _NAT_TEMPLATES.items():
select_tab( "scenario" )
sel = Select( find_child( "select[name='PLAYER_1']" ) )
sel.select_by_value( nat )
select_tab( "ob1" )
for template_id in template_ids:
func( template_id, template_id )
templates_to_test.remove( template_id )
# make sure we tested everything
assert not templates_to_test
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def select_tab( tab_id ):
"""Select a tab in the main page."""
elem = find_child( "#tabs .ui-tabs-nav a[href='#tabs-{}']".format( tab_id ) )
@ -56,6 +109,7 @@ def set_template_params( params ):
elem.send_keys( val )
if key == "SCENARIO_DATE":
elem.send_keys( Keys.ESCAPE ) # nb: force the calendar popup to close :-/
wait_for( 5, lambda: find_child("#ui-datepicker-div").value_of_css_property("display") == "none" )
time.sleep( 0.25 )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Loading…
Cancel
Save