def test_clean_html( webdriver, flask_app, dbconn ): """Test cleaning HTML content.""" # initialize init_tests( webdriver, flask_app, dbconn ) replace = [ "[\u00ab\u00bb\u201c\u201d\u201e\u201f foo\u2014bar \u2018\u2019\u201a\u201b\u2039\u203a]", "[\"\"\"\"\"\" foo - bar '''''']" ] # create a publisher with HTML content create_publisher( { "name": "name: <span onclick='boo!'> <b>bold</b> <xxx>xxx</xxx> <i>italic</i> {}".format( replace[0] ), "description": "bad stuff here: <script>HCF</script> {}".format( replace[0] ) }, toast_type="warning" ) # check that the HTML was cleaned sr = check_search_result( None, _check_sr, [ "name: bold xxx italic {}".format( replace[1] ), "bad stuff here: {}".format( replace[1] ), None ] ) assert find_child( ".name", sr ).get_attribute( "innerHTML" ) \ == "name: <span> <b>bold</b> xxx <i>italic</i> {}</span>".format( replace[1] ) assert check_toast( "warning", "Some values had HTML cleaned up.", contains=True ) # update the publisher with new HTML content edit_publisher( sr, { "name": "<div onclick='...'>updated</div>" }, toast_type="warning" ) results = get_search_results() assert len(results) == 1 wait_for( 2, lambda: find_child( ".name", sr ).text == "updated" ) assert check_toast( "warning", "Some values had HTML cleaned up.", contains=True )
def edit_article(sr, vals, toast_type="info", expected_error=None, expected_constraints=None): #pylint: disable=too-many-branches """Edit a article's details.""" # initialize if sr: select_sr_menu_option(sr, "edit") else: pass # nb: we assume that the dialog is already on-screen dlg = wait_for_elem(2, "#article-form") # update the specified article's details _update_values(dlg, vals) set_toast_marker(toast_type) find_child("button.ok", dlg).click() # check what happened if expected_error: # we were expecting an error, confirm the error message check_error_msg(expected_error) return dlg # nb: the dialog is left on-screen elif expected_constraints: # we were expecting constraint warnings, confirm them check_constraint_warnings("Do you want to update this article?", expected_constraints, "cancel") return dlg # nb: the dialog is left on-screen else: # we were expecting the update to work, confirm this expected = "updated OK" if sr else "created OK" wait_for(2, lambda: check_toast(toast_type, expected, contains=True)) wait_for_not_elem(2, "#article-form") return None
def create_article(vals, toast_type="info", expected_error=None, expected_constraints=None, dlg=None): """Create a new article.""" # initialize set_toast_marker(toast_type) # create the new article if not dlg: select_main_menu_option("new-article") dlg = wait_for_elem(2, "#article-form") _update_values(dlg, vals) find_child("button.ok", dlg).click() # check what happened if expected_error: # we were expecting an error, confirm the error message check_error_msg(expected_error) return dlg # nb: the dialog is left on-screen elif expected_constraints: # we were expecting constraint warnings, confirm them check_constraint_warnings("Do you want to create this article?", expected_constraints, "cancel") return dlg # nb: the dialog is left on-screen else: # we were expecting the create to work, confirm this wait_for(2, lambda: check_toast(toast_type, "created OK", contains=True)) wait_for_not_elem(2, "#article-form") return None
def test_delete_article(webdriver, flask_app, dbconn): """Test deleting articles.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="articles.json") # start to delete an article, but cancel the operation article_name = "Smoke Gets In Your Eyes" results = do_search(SEARCH_ALL_ARTICLES) result_names = get_search_result_names(results) sr = find_search_result(article_name, results) select_sr_menu_option(sr, "delete") check_ask_dialog(("Delete this article?", article_name), "cancel") # check that search results are unchanged on-screen results2 = get_search_results() assert results2 == results # check that the search results are unchanged in the database results3 = do_search(SEARCH_ALL_ARTICLES) assert get_search_result_names(results3) == result_names # delete the article sr = find_search_result(article_name, results3) select_sr_menu_option(sr, "delete") set_toast_marker("info") check_ask_dialog(("Delete this article?", article_name), "ok") wait_for(2, lambda: check_toast("info", "The article was deleted.")) # check that search result was removed on-screen wait_for(2, lambda: article_name not in get_search_result_names()) # check that the search result was deleted from the database results = do_search(SEARCH_ALL_ARTICLES) assert article_name not in get_search_result_names(results)
def test_delete_publication(webdriver, flask_app, dbconn): """Test deleting publications.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="publications.json") # start to delete a publication, but cancel the operation article_title = "ASL Journal (2)" results = do_search(SEARCH_ALL_PUBLICATIONS) result_names = get_search_result_names(results) sr = find_search_result(article_title, results) select_sr_menu_option(sr, "delete") check_ask_dialog(("Delete this publication?", article_title), "cancel") # check that search results are unchanged on-screen results2 = get_search_results() assert results2 == results # check that the search results are unchanged in the database results3 = do_search(SEARCH_ALL_PUBLICATIONS) assert get_search_result_names(results3) == result_names # delete the publication sr = find_search_result(article_title, results3) select_sr_menu_option(sr, "delete") set_toast_marker("info") check_ask_dialog(("Delete this publication?", article_title), "ok") wait_for(2, lambda: check_toast("info", "The publication was deleted.")) # check that search result was removed on-screen wait_for(2, lambda: article_title not in get_search_result_names()) # check that the search result was deleted from the database results = do_search(SEARCH_ALL_PUBLICATIONS) assert article_title not in get_search_result_names(results)
def edit_publisher( sr, vals, toast_type="info", expected_error=None ): """Edit a publisher's details.""" # initialize if sr: select_sr_menu_option( sr, "edit" ) else: pass # nb: we assume that the dialog is already on-screen dlg = wait_for_elem( 2, "#publisher-form" ) # update the specified publisher's details _update_values( dlg, vals ) set_toast_marker( toast_type ) find_child( "button.ok", dlg ).click() # check what happened if expected_error: # we were expecting an error, confirm the error message check_error_msg( expected_error ) else: # we were expecting the update to work, confirm this expected = "updated OK" if sr else "created OK" wait_for( 2, lambda: check_toast( toast_type, expected, contains=True ) ) wait_for_not_elem( 2, "#publisher-form" )
def create_publisher( vals, toast_type="info", expected_error=None, dlg=None ): """Create a new publisher.""" # initialize set_toast_marker( toast_type ) # create the new publisher if not dlg: select_main_menu_option( "new-publisher" ) dlg = wait_for_elem( 2, "#publisher-form" ) _update_values( dlg, vals ) find_child( "button.ok", dlg ).click() # check what happened if expected_error: # we were expecting an error, confirm the error message check_error_msg( expected_error ) return dlg # nb: the dialog is left on-screen else: # we were expecting the create to work, confirm this wait_for( 2, lambda: check_toast( toast_type, "created OK", contains=True ) ) wait_for_not_elem( 2, "#publisher-form" ) return None
def test_clean_html(webdriver, flask_app, dbconn): """Test cleaning HTML content.""" # initialize init_tests(webdriver, flask_app, dbconn) replace = [ "[\u00ab\u00bb\u201c\u201d\u201e\u201f foo\u2014bar \u2018\u2019\u201a\u201b\u2039\u203a]", "[\"\"\"\"\"\" foo - bar '''''']" ] # create a article with HTML content create_article( { "title": "title: <span onclick='boo!'> <b>bold</b> <xxx>xxx</xxx> <i>italic</i> {}" .format(replace[0]), "subtitle": "<i>italicized subtitle</i> {}".format(replace[0]), "snippet": "bad stuff here: <script>HCF</script> {}".format(replace[0]) }, toast_type="warning") # check that the HTML was cleaned sr = check_search_result(None, _check_sr, [ "title: bold xxx italic {}".format( replace[1]), "italicized subtitle {}".format(replace[1]), "bad stuff here: {}".format(replace[1]), "", [], [], None ]) assert find_child( ".title", sr ).get_attribute( "innerHTML" ) \ == "title: <span> <b>bold</b> xxx <i>italic</i> {}</span>".format( replace[1] ) assert find_child( ".subtitle", sr ).get_attribute( "innerHTML" ) \ == "<i>italicized subtitle</i> {}".format( replace[1] ) assert check_toast("warning", "Some values had HTML cleaned up.", contains=True) # update the article with new HTML content edit_article(sr, {"title": "<div onclick='...'>updated</div>"}, toast_type="warning") wait_for(2, lambda: get_search_result_names() == ["updated"]) assert check_toast("warning", "Some values had HTML cleaned up.", contains=True)
def do_test( msg_type ): # check that the startup message was shown in the UI correctly set_toast_marker( msg_type ) assert startup_msgs[ msg_type ] == [] asl_articles.startup.log_startup_msg( msg_type, "TEST: {}", msg_type ) webdriver.refresh() expected = startup_msgs[ msg_type ][0] wait_for( 2, lambda: check_toast( msg_type, expected ) ) startup_msgs[ msg_type ] = [] # check if the webapp started up or not if msg_type == "error": assert not find_child( "#search-form" ) else: assert find_child( "#search-form" )