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 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 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 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" )