Give the default content doc a different ID to its parent content set.

master
Pacman Ghost 3 years ago
parent f6a8c04ff2
commit 458378c532
  1. 7
      asl_rulebook2/webapp/content.py
  2. 2
      asl_rulebook2/webapp/tests/test_basic.py
  3. 8
      asl_rulebook2/webapp/tests/test_content_sets.py
  4. 36
      asl_rulebook2/webapp/tests/test_linkify_ruleids.py
  5. 8
      asl_rulebook2/webapp/tests/test_search.py

@ -126,6 +126,9 @@ def load_content_sets( startup_msgs, logger ):
matches.add( fname[1:-1] )
return matches
def make_cdoc_id( cset_id, key ):
return "{}!{}".format( cset_id, key )
# load each content set
logger.info( "Loading content sets: %s", data_dir )
fspec = os.path.join( data_dir, "*.index" )
@ -145,13 +148,13 @@ def load_content_sets( startup_msgs, logger ):
continue # nb: we can't do anything without an index file
# load the main content doc
fname_stem = os.path.splitext( fname2 )[0]
cdoc_id = cset_id # nb: because this the main content document
cdoc_id = make_cdoc_id( cset_id, "" )
content_doc = load_content_doc( fname_stem, fname_stem, cdoc_id )
content_set[ "content_docs" ][ cdoc_id ] = content_doc
# load any associated content docs
for fname_stem2 in find_assoc_cdocs( fname_stem ):
# nb: we assume there's only one space between the two filename stems :-/
cdoc_id2 = "{}!{}".format( cdoc_id, slugify(fname_stem2) )
cdoc_id2 = make_cdoc_id( cset_id, slugify(fname_stem2) )
content_doc = load_content_doc(
"{} ({})".format( fname_stem, fname_stem2 ),
fname_stem2,

@ -23,4 +23,4 @@ def test_hello( webapp, webdriver ):
# check that the content docs loaded correctly
content_docs = get_content_docs()
assert content_docs == [ "simple" ]
assert content_docs == [ "simple!" ]

@ -53,8 +53,8 @@ def test_targets( webapp, webdriver ):
# test clicking on ruleid's
do_test( "4b", "content-set-1!linked" )
do_test( "1a", "content-set-1" )
do_test( "cs2d", "content-set-2" )
do_test( "1a", "content-set-1!" )
do_test( "cs2d", "content-set-2!" )
select_tabbed_page( "content", "empty" )
do_test( "1b", "content-set-1!linked" )
@ -116,8 +116,8 @@ def test_chapters( webapp, webdriver ):
assert expected in get_last_error_msg()
# click on some chapter entries
do_test( 1, 2, ( "content-set-1", "6a" ) )
do_test( 4, 0, ( "content-set-2", "cs2a" ) )
do_test( 1, 2, ( "content-set-1!", "6a" ) )
do_test( 4, 0, ( "content-set-2!", "cs2a" ) )
do_test( 2, 1, ( "content-set-1!linked", "2b" ) )
# try to show an unknown target

@ -18,13 +18,13 @@ def test_index_entry( webdriver, webapp ):
results = _do_search( "CCPh", True )
assert len(results) == 1
sr_elem = find_child( "#search-results .sr" )
_check_ruleid( find_child(".subtitle",sr_elem), ("asl-rulebook","A11") )
_check_ruleid( find_child(".subtitle",sr_elem), ("asl-rulebook!","A11") )
# test ruleid's in an index entry's content
results = _do_search( "also want to", False )
assert len(results) == 1
sr_elem = find_child( "#search-results .sr" )
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook","A3.8") )
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook!","A3.8") )
_dismiss_rule_info_popup()
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -55,18 +55,18 @@ def test_qa( webdriver, webapp ):
results = _do_search( "wp", True )
assert len(results) == 3
sr_elem = find_children( "#search-results .sr" )[ 1 ]
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook","A24.31") )
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook!","A24.31") )
_dismiss_rule_info_popup()
_check_ruleid( find_child(".question",sr_elem), ("asl-rulebook","A24.3") )
_check_ruleid( find_child(".question",sr_elem), ("asl-rulebook!","A24.3") )
_dismiss_rule_info_popup()
_check_ruleid( find_child(".answer",sr_elem), ("asl-rulebook","A24.31") )
_check_ruleid( find_child(".answer",sr_elem), ("asl-rulebook!","A24.31") )
_dismiss_rule_info_popup()
# test ruleid's in a Q+A entry in the rule info popup
expected = [
( ".caption", ("asl-rulebook","A24.31") ),
( ".question", ("asl-rulebook","A24.3") ),
( ".answer", ("asl-rulebook","A24.31") )
( ".caption", ("asl-rulebook!","A24.31") ),
( ".question", ("asl-rulebook!","A24.3") ),
( ".answer", ("asl-rulebook!","A24.31") )
]
for sel, target in expected:
_do_search( "A24.31", False )
@ -88,14 +88,14 @@ def test_errata( webdriver, webapp ):
results = _do_search( "errata", True )
assert len(results) == 2
sr_elem = find_children( "#search-results .sr" )[ 1 ]
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook","A3.8") )
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook!","A3.8") )
_dismiss_rule_info_popup()
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook","A.2") )
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook!","A.2") )
# test ruleid's in an errata in the rule info popup
expected = [
( ".caption", ("asl-rulebook","A3.8") ),
( ".content", ("asl-rulebook","A.2") )
( ".caption", ("asl-rulebook!","A3.8") ),
( ".content", ("asl-rulebook!","A.2") )
]
for sel, target in expected:
_do_search( "errata", False )
@ -116,9 +116,9 @@ def test_user_annotations( webdriver, webapp ):
results = _do_search( "is there anything", False )
assert len(results) == 1
sr_elem = find_child( "#search-results .sr" )
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook","A24.3") )
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook!","A24.3") )
_dismiss_rule_info_popup()
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook","A24.31") )
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook!","A24.31") )
_dismiss_rule_info_popup()
# ---------------------------------------------------------------------
@ -134,11 +134,11 @@ def test_asop( webdriver, webapp ):
results = _do_search( "first/next", False )
assert len(results) == 1
sr_elem = find_child( "#search-results .sr" )
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook","A11.3-.34") )
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook!","A11.3-.34") )
# click through to the ASOP section and check the ruleid there
find_child( ".caption", sr_elem ).click()
_check_ruleid( find_child("#asop .section"), ("asl-rulebook","A11.3-.34") )
_check_ruleid( find_child("#asop .section"), ("asl-rulebook!","A11.3-.34") )
# check the ruleid in the ASOP chapter
refresh_webapp( webdriver ) # nb: clear the ASOP overrides
@ -146,14 +146,14 @@ def test_asop( webdriver, webapp ):
open_asop_chapter( "close-combat" )
sections = find_children( "#asop .section" )
assert len(sections) == 4
_check_ruleid( sections[1], ("asl-rulebook","A11.3-.34") )
_check_ruleid( sections[1], ("asl-rulebook!","A11.3-.34") )
# check the ruleid in the ASOP section
refresh_webapp( webdriver )
select_tabbed_page( "nav", "asop" )
open_asop_section( "close-combat", 1 )
section = find_child( "#asop .section" )
_check_ruleid( section, ("asl-rulebook","A11.3-.34") )
_check_ruleid( section, ("asl-rulebook!","A11.3-.34") )
# ---------------------------------------------------------------------

@ -104,7 +104,7 @@ def test_targets( webapp, webdriver ):
# click on a target
elem = find_child( "#search-results {}".format( sel ) )
elem.click()
wait_for( 2, lambda: get_curr_target() == ( "simple", expected ) )
wait_for( 2, lambda: get_curr_target() == ( "simple!", expected ) )
# do the tests
do_test( "CC", ".sr .ruleids .ruleid a", "A3.8" )
@ -124,21 +124,21 @@ def test_target_search( webapp, webdriver ):
assert len(results) > 0
results = do_search( "D1.4" )
assert len(results) == 0 # nb: previous search results should be removed
wait_for( 2, lambda: get_curr_target() == ( "simple", "D1.4" ) )
wait_for( 2, lambda: get_curr_target() == ( "simple!", "D1.4" ) )
# search for a target
results = do_search( "astral plane" )
assert results is None # nb: this is the "no results" message
results = do_search( "E11.21" )
assert len(results) == 0 # nb: the "no results" message should be cleared
wait_for( 2, lambda: get_curr_target() == ( "simple", "E11.21" ) )
wait_for( 2, lambda: get_curr_target() == ( "simple!", "E11.21" ) )
# search for a target
results = do_search( "*" )
assert isinstance( results, str ) # nb: this is an error message
results = do_search( "a4.7" )
assert len(results) == 0 # nb: the error message should be cleared
wait_for( 2, lambda: get_curr_target() == ( "simple", "A4.7" ) )
wait_for( 2, lambda: get_curr_target() == ( "simple!", "A4.7" ) )
# ---------------------------------------------------------------------

Loading…
Cancel
Save