def test_default_image(webdriver, flask_app, dbconn): """Test displaying a publication's default image.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="default-publication-image.json") # initialize from asl_articles.tests.test_publishers import edit_publisher #pylint: disable=import-outside-toplevel images = ["1.gif", "2.gif", "3.gif"] image_fnames = { f: os.path.join(os.path.split(__file__)[0], "fixtures/images/" + f) for f in images } image_data = {f: open(image_fnames[f], "rb").read() for f in images} # show the test publisher/publication results = do_search(SEARCH_ALL) publ_sr = find_search_result("Joe Publisher", results) pub_sr = find_search_result("My Publication", results) def check_images(publ_expected, pub_expected): do_check_image(publ_sr, publ_expected) do_check_image(pub_sr, pub_expected) def do_check_image(sr, expected): img = find_child("img.image", sr) if img: assert expected image_url = img.get_attribute("src") resp = urllib.request.urlopen(image_url).read() assert resp == image_data[expected] else: assert not expected # add an image to the publisher edit_publisher(publ_sr, {"image": image_fnames["1.gif"]}) check_images("1.gif", "1.gif") # add an image to the publication edit_publication(pub_sr, {"image": image_fnames["2.gif"]}) check_images("1.gif", "2.gif") # remove the publisher's image edit_publisher(publ_sr, {"image": None}) check_images(None, "2.gif") # add a different image to the publisher edit_publisher(publ_sr, {"image": image_fnames["3.gif"]}) check_images("3.gif", "2.gif") # remove the publication's image edit_publication(pub_sr, {"image": None}) check_images("3.gif", "3.gif") # detach the publication from the publisher edit_publication(pub_sr, {"publisher": "(none)"}) check_images("3.gif", None)
def test_search_publishers( webdriver, flask_app, dbconn ): """Test searching publishers.""" # initialize init_tests( webdriver, flask_app, dbconn ) # test searching publisher names/descriptions _do_test_searches( ["hill","original"], [] ) create_publisher( { "name": "Avalon Hill", "description": "The original ASL vendor." } ) _do_test_searches( ["hill","original"], ["Avalon Hill"] ) # edit the publisher sr = find_search_result( "Avalon Hill" ) edit_publisher( sr, { "name": "Avalon Mountain", "description": "The first ASL vendor." } ) _do_test_searches( ["hill","original"], [] ) _do_test_searches( ["mountain","first"], ["Avalon Mountain"] ) # delete the publisher sr = find_search_result( "Avalon Mountain" ) select_sr_menu_option( sr, "delete" ) check_ask_dialog( "Delete this publisher?", "ok" ) _do_test_searches( ["hill","original","mountain","first"], [] )
def test_article_authors(webdriver, flask_app, dbconn): """Test article author operations.""" # initialize init_tests(webdriver, flask_app, dbconn) # create some test articles create_article({"title": "article 1"}) create_article({"title": "article 2"}) all_authors = set() _check_authors(flask_app, all_authors, [[], []]) # add an author to article #1 edit_article(find_search_result("article 1"), {"authors": ["+andrew"]}) _check_authors(flask_app, all_authors, [["andrew"], []]) # add authors to article #2 edit_article(find_search_result("article 2"), {"authors": ["+bob", "+charlie"]}) _check_authors(flask_app, all_authors, [["andrew"], ["bob", "charlie"]]) # add/remove authors to article #2 edit_article(find_search_result("article 2"), {"authors": ["+dan", "-charlie", "+andrew"]}) _check_authors(flask_app, all_authors, [["andrew"], ["bob", "dan", "andrew"]]) # add new/existing authors to article #1 # NOTE: The main thing we're checking here is that despite new and existing authors # being added to the article, their order is preserved. edit_article(find_search_result("article 1"), {"authors": ["+bob", "+new1", "+charlie", "+new2"]}) _check_authors(flask_app, all_authors, [["andrew", "bob", "new1", "charlie", "new2"], ["bob", "dan", "andrew"]])
def test_search_publications( webdriver, flask_app, dbconn ): """Test searching publications.""" # initialize init_tests( webdriver, flask_app, dbconn ) # test searching publication names/descriptions _do_test_searches( ["journal","good"], [] ) create_publication( { "name": "ASL Journal", "description": "A pretty good magazine." } ) _do_test_searches( ["journal","good"], ["ASL Journal"] ) # edit the publication sr = find_search_result( "ASL Journal" ) edit_publication( sr, { "name": "ASL Magazine", "description": "Not a bad magazine." } ) _do_test_searches( ["journal","good"], [] ) _do_test_searches( ["magazine","bad"], ["ASL Magazine"] ) # delete the publication sr = find_search_result( "ASL Magazine" ) select_sr_menu_option( sr, "delete" ) check_ask_dialog( "Delete this publication?", "ok" ) _do_test_searches( ["journal","good","magazine","bad"], [] )
def test_search_articles( webdriver, flask_app, dbconn ): """Test searching articles.""" # initialize init_tests( webdriver, flask_app, dbconn ) # test searching article titles/subtitles/snippets _do_test_searches( ["low","some","game"], [] ) create_article( { "title": "Hit 'Em High, Or Hit 'Em Low", "subtitle": "Some things about light mortars you might like to know", "snippet": "Light mortars in ASL can be game winners." } ) _do_test_searches( ["low","some","game"], ["Hit 'Em High, Or Hit 'Em Low"] ) # edit the article sr = find_search_result( "Hit 'Em High, Or Hit 'Em Low" ) edit_article( sr, { "title": "Hit 'Em Hard", "subtitle": "Where it hurts!", "snippet": "Always the best way to do things." } ) _do_test_searches( ["low","some","game"], [] ) _do_test_searches( ["hard","hurt","best"], ["Hit 'Em Hard"] ) # delete the article sr = find_search_result( "Hit 'Em Hard" ) select_sr_menu_option( sr, "delete" ) check_ask_dialog( "Delete this article?", "ok" ) _do_test_searches( ["hard","hurt","best"], [] )
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 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_tags( webdriver, flask_app, dbconn ): """Test tag operations.""" # initialize init_tests( webdriver, flask_app, dbconn ) # create a test publication and article create_publication( { "name": "publication 1" } ) create_article( { "title": "article 1" } ) _check_tags( flask_app, { "publication 1": [], "article 1": [] } ) # add some tags to the publication edit_publication( find_search_result( "publication 1" ), { "tags": [ "+aaa", "+bbb" ] } ) _check_tags( flask_app, { "publication 1": [ "aaa", "bbb" ], "article 1": [] } ) # add some tags to the article edit_article( find_search_result( "article 1" ), { "tags": [ "+bbb", "+ccc" ] } ) _check_tags( flask_app, { "publication 1": [ "aaa", "bbb" ], "article 1": [ "bbb", "ccc" ] } ) # remove some tags from the publication edit_publication( find_search_result( "publication 1" ), { "tags": [ "-bbb" ] } ) _check_tags( flask_app, { "publication 1": [ "aaa" ], "article 1": [ "bbb", "ccc" ] } ) # remove some tags from the article edit_article( find_search_result( "article 1" ), { "tags": [ "-ccc", "-bbb" ] } ) _check_tags( flask_app, { "publication 1": [ "aaa" ], "article 1": [] } ) # add duplicate tags to the publication edit_publication( find_search_result( "publication 1" ), { "tags": [ "+bbb", "+aaa", "+eee" ] } ) _check_tags( flask_app, { "publication 1": [ "aaa","bbb","eee" ], "article 1": [] } )
def do_test( publ_name, expected_warning, expected_deletions ): # initialize load_fixtures( session, "cascading-deletes-1.json" ) results = do_search( SEARCH_ALL ) # delete the specified publisher sr = find_search_result( publ_name, results ) select_sr_menu_option( sr, "delete" ) check_ask_dialog( ( "Delete this publisher?", publ_name, expected_warning ), "ok" ) # check that deleted associated publications/articles were removed from the UI def check_publications(): check_results( "publication", [ "2", "3", "4", "5a", "5b", "6a", "6b", "7a", "7b", "8a", "8b" ], expected_deletions ) def check_articles(): check_results( "article", [ "3", "4a", "4b", "6a", "7a", "7b", "8a.1", "8a.2", "8b.1", "8b.2" ], expected_deletions ) check_publications() check_articles() # check that associated publications/articles were removed from the database results = do_search( SEARCH_ALL ) check_publications() check_articles()
def test_edit_publisher( webdriver, flask_app, dbconn ): """Test editing publishers.""" # initialize init_tests( webdriver, flask_app, dbconn, fixtures="publishers.json" ) # edit "Avalon Hill" results = do_search( SEARCH_ALL_PUBLISHERS ) sr = find_search_result( "Avalon Hill", results ) edit_publisher( sr, { "name": " Avalon Hill (updated) ", "description": " Updated AH description. ", "url": " http://ah-updated.com " } ) # check that the search result was updated in the UI sr = check_search_result( "Avalon Hill (updated)", _check_sr, [ "Avalon Hill (updated)", "Updated AH description.", "http://ah-updated.com/" ] ) # remove all fields from the publisher edit_publisher( sr, { "name": "AH", "description": "", "url": "" } ) # check that the search result was updated in the UI expected = [ "AH", "", None ] check_search_result( expected[0], _check_sr, expected ) # check that the publisher was updated in the database results = do_search( SEARCH_ALL_PUBLISHERS ) check_search_result( expected[0], _check_sr, expected )
def do_test(pub_name, expected_warning, expected_articles): # initialize load_fixtures(session, "cascading-deletes-2.json") results = do_search(SEARCH_ALL) # delete the specified publication sr = find_search_result(pub_name, results) select_sr_menu_option(sr, "delete") check_ask_dialog( ("Delete this publication?", pub_name, expected_warning), "ok") def check_results(): results = wait_for(2, lambda: get_results(len(expected_articles))) assert set(results) == set(expected_articles) def get_results(expected_len): # NOTE: The UI will remove anything that has been deleted, so we need to # give it a bit of time to finish doing this. try: results = get_search_result_names() except StaleElementReferenceException: return None results = [r for r in results if r.startswith("article")] if len(results) == expected_len: return results return None # check that deleted associated articles were removed from the UI check_results() # check that associated articles were removed from the database results = do_search(SEARCH_ALL_ARTICLES) check_results()
def check_article_order(expected): # check the article order in the database articles = defaultdict(list) query = dbconn.execute("SELECT pub_name, article_title, article_seqno" " FROM article LEFT JOIN publication" " ON article.pub_id = publication.pub_id" " ORDER BY article.pub_id, article_seqno") for row in query: articles[row[0]].append((row[1], row[2])) assert articles == expected # check the article order in the UI results = do_search(SEARCH_ALL) for pub_name in expected: if not pub_name: continue sr = find_search_result(pub_name, results) select_sr_menu_option(sr, "edit") dlg = wait_for_elem(2, "#publication-form") articles = [ a.text for a in find_children(".articles li.draggable", dlg) ] find_child(".cancel", dlg).click() assert articles == [a[0] for a in expected[pub_name]]
def test_tag_search( webdriver, flask_app, dbconn ): """Test searching for tags.""" # initialize init_tests( webdriver, flask_app, dbconn, fixtures="search.json" ) def click_on_tag( tag, expected ): tag.click() wait_for( 2, lambda: get_search_result_names() == expected ) return get_search_results() def get_tags( sr ): return find_children( ".tags .tag", sr ) # find an article and click on the "#aslj" tag results = do_search( "high low" ) assert len(results) == 1 tags = get_tags( results[0] ) assert [ t.text for t in tags ] == [ "#aslj", "#mortars" ] expected = [ "ASL Journal (4)", "ASL Journal (5)", "'Bolts From Above", "The Jungle Isn't Neutral", "Hunting DUKWs and Buffalos", "Hit 'Em High, Or Hit 'Em Low" ] results = click_on_tag( tags[0], expected ) # click on another "#aslj" tag tags = get_tags( results[0] ) assert [ t.text for t in tags ] == [ "#aslj" ] results = click_on_tag( tags[0], expected ) # click on a "#PTO" tag sr = find_search_result( "The Jungle Isn't Neutral", results ) tags = get_tags( sr ) assert [ t.text for t in tags ] == [ "#aslj", "#PTO" ] click_on_tag( tags[1], [ "The Jungle Isn't Neutral" ] )
def check_articles(results, expected): for pub_name, article_title in expected.items(): pub_sr = find_search_result(pub_name, results) articles = find_child(".collapsible", pub_sr) if article_title: # check that the article appears in the publication's search result assert find_child(".caption", articles).text == "Articles:" articles = find_children("li", articles) assert len(articles) == 1 assert articles[0].text == article_title # check that the "edit publication" dialog is correct select_sr_menu_option(pub_sr, "edit") dlg = find_child(".MuiDialog-root") articles = find_children(".articles li", dlg) assert len(articles) == 1 assert articles[0].text == article_title find_child("button.cancel", dlg).click() else: # check that the publication has no associated articles assert articles is None # check that the "edit publication" dialog is correct select_sr_menu_option(pub_sr, "edit") dlg = find_child(".MuiDialog-root") articles = find_children(".articles", dlg) assert len(articles) == 0 find_child("button.cancel", dlg).click()
def test_create_publication(webdriver, flask_app, dbconn): """Test creating new publications.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="publications.json") do_search(SEARCH_ALL_PUBLICATIONS) # create a new publication create_publication({ "name": "New publication", "edition": "#1", "pub_date": "1st January, 1900", "description": "New publication description.", "tags": ["+111", "+222", "+333"], "url": "http://new-publication.com" }) # check that the new publication appears in the UI expected = [ "New publication", "#1", "1st January, 1900", "New publication description.", ["111", "222", "333"], "http://new-publication.com/" ] check_search_result("New publication (#1)", _check_sr, expected) # check that the new publication has been saved in the database results = do_search(SEARCH_ALL_PUBLICATIONS) sr = find_search_result("New publication (#1)", results) check_search_result(sr, _check_sr, expected)
def test_edit_publication(webdriver, flask_app, dbconn): """Test editing publications.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="publications.json") # edit "ASL Journal #2" results = do_search(SEARCH_ALL_PUBLICATIONS) sr = find_search_result("ASL Journal (2)", results) edit_publication( sr, { "name": " ASL Journal (updated) ", "edition": " 2a ", "pub_date": "Jan 2020", "description": " Updated ASLJ description. ", "tags": ["+abc", "+xyz"], "url": " http://aslj-updated.com ", }) # check that the search result was updated in the UI sr = find_search_result("ASL Journal (updated) (2a)") check_search_result(sr, _check_sr, [ "ASL Journal (updated)", "2a", "Jan 2020", "Updated ASLJ description.", ["abc", "xyz"], "http://aslj-updated.com/" ]) # remove all fields from the publication edit_publication( sr, { "name": "ASLJ", "edition": "", "pub_date": "", "description": "", "tags": ["-abc", "-xyz"], "url": "", }) # check that the search result was updated in the UI expected = ["ASLJ", "", "", "", [], ""] check_search_result(sr, _check_sr, expected) # check that the publication was updated in the database results = do_search(SEARCH_ALL_PUBLICATIONS) sr = find_search_result("ASLJ", results) check_search_result(sr, _check_sr, expected)
def test_article_scenarios(webdriver, flask_app, dbconn): """Test article scenario operations.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="article-scenarios.json") all_scenarios = set([ "Test Scenario 1 [TEST 1]", "Test Scenario 2 [TEST 2]", "Test Scenario 3 [TEST 3]", "No scenario ID" ]) # create some test articles create_article({"title": "article 1"}) create_article({"title": "article 2"}) _check_scenarios(flask_app, all_scenarios, [[], []]) # add a scenario to article #1 edit_article(find_search_result("article 1"), {"scenarios": ["+Test Scenario 1 [TEST 1]"]}) _check_scenarios(flask_app, all_scenarios, [["Test Scenario 1 [TEST 1]"], []]) # add scenarios to article #2 edit_article( find_search_result("article 2"), {"scenarios": ["+Test Scenario 3 [TEST 3]", "+No scenario ID"]}) _check_scenarios(flask_app, all_scenarios, [["Test Scenario 1 [TEST 1]"], ["Test Scenario 3 [TEST 3]", "No scenario ID"]]) # add/remove scenarios to article #2 edit_article(find_search_result("article 2"), { "scenarios": ["+Test Scenario 1 [TEST 1]", "-Test Scenario 3 [TEST 3]"] }) _check_scenarios(flask_app, all_scenarios, [["Test Scenario 1 [TEST 1]"], ["No scenario ID", "Test Scenario 1 [TEST 1]"]]) # add an unknown scenario to article #1 edit_article(find_search_result("article 1"), {"scenarios": ["+new scenario [NEW]"]}) _check_scenarios(flask_app, all_scenarios, [["Test Scenario 1 [TEST 1]", "new scenario [NEW]"], ["No scenario ID", "Test Scenario 1 [TEST 1]"]])
def check_publications( results, expected ): for publ_name,pub_name in expected.items(): publ_sr = find_search_result( publ_name, results ) pubs = find_child( ".collapsible", publ_sr ) if pub_name: # check that the publication appears in the publisher's search result assert find_child( ".caption", pubs ).text == "Publications:" pubs = find_children( "li", pubs ) assert len(pubs) == 1 assert pubs[0].text == pub_name else: # check that the publisher has no associated publications assert pubs is None
def test_publisher_article_dates(webdriver, flask_app, dbconn): """Test "published" dates for publisher articles.""" # initialize init_tests(webdriver, flask_app, dbconn, disable_constraints=False, fixtures="publisher-article-dates.json") # initialize article_title, article_date = "test article", "1st January, 2000" article_sr = None def check_article_date(has_date): # check the article's publication date def do_check(): elem = find_child(".article_date", article_sr) article_id = article_sr.get_attribute("testing--article_id") row = get_article_row(dbconn, article_id, ["article_date"]) if has_date: return elem.text == article_date and row[0] == article_date else: return not elem and not row[0] wait_for(2, do_check) # create an article associated with a publication create_article({ "title": article_title, "publication": "ASL Journal", "snippet": "This is a test article.", "pageno": 42, "authors": ["+Joe Blow"] }) article_sr = wait_for(2, lambda: find_search_result(article_title)) check_article_date(False) # change the article to be associated with a publisher edit_article(article_sr, {"publisher": "Avalon Hill"}, expected_constraints=["The article date was not specified."], accept_constraints=True) check_article_date(False) # give the article a published date edit_article(article_sr, {"article_date": article_date}) check_article_date(True) # change the article back to the publication edit_article(article_sr, {"publication": "ASL Journal"}) check_article_date(False)
def test_publication_lists( webdriver, flask_app, dbconn ): """Test showing publications that belong a publisher.""" # initialize init_tests( webdriver, flask_app, dbconn, fixtures="publishers.json" ) def check_publications( results, expected ): for publ_name,pub_name in expected.items(): publ_sr = find_search_result( publ_name, results ) pubs = find_child( ".collapsible", publ_sr ) if pub_name: # check that the publication appears in the publisher's search result assert find_child( ".caption", pubs ).text == "Publications:" pubs = find_children( "li", pubs ) assert len(pubs) == 1 assert pubs[0].text == pub_name else: # check that the publisher has no associated publications assert pubs is None # check that the publishers have no publications associated with them results = do_search( SEARCH_ALL_PUBLISHERS ) publ_name1, publ_name2 = "Avalon Hill", "Multiman Publishing" check_publications( results, { publ_name1: None, publ_name2: None } ) # create a publication that has no parent publisher create_publication( { "name": "no parent" } ) check_publications( results, { publ_name1: None, publ_name2: None } ) # create a publication that has a parent publisher pub_name = "test publication" create_publication( { "name": pub_name, "publisher": publ_name1 } ) check_publications( results, { publ_name1: pub_name, publ_name2: None } ) # move the publication to another publisher pub_sr = find_search_result( pub_name ) edit_publication( pub_sr, { "publisher": publ_name2 } ) check_publications( results, { publ_name1: None, publ_name2: pub_name } ) # change the publication to have no parent publisher edit_publication( pub_sr, { "publisher": "(none)" } ) check_publications( results, { publ_name1: None, publ_name2: None } ) # move the publication back to a publisher edit_publication( pub_sr, { "publisher": publ_name1 } ) check_publications( results, { publ_name1: pub_name, publ_name2: None } ) # delete the publication select_sr_menu_option( pub_sr, "delete" ) check_ask_dialog( ( "Delete this publication?", pub_name ), "ok" ) check_publications( results, { publ_name1: None, publ_name2: None } )
def test_edit_article(webdriver, flask_app, dbconn): """Test editing articles.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="articles.json") # edit an article results = do_search(SEARCH_ALL_ARTICLES) sr = find_search_result("What To Do If You Have A Tin Can", results) edit_article( sr, { "title": " Updated title ", "subtitle": " Updated subtitle ", "snippet": " Updated snippet. ", "pageno": " 123 ", "authors": ["+Fred Nerk", "+Joe Blow"], "tags": ["+abc", "+xyz"], "url": " http://updated-article.com ", }) # check that the search result was updated in the UI sr = check_search_result("Updated title", _check_sr, [ "Updated title", "Updated subtitle", "Updated snippet.", "123", ["Fred Nerk", "Joe Blow"], ["abc", "xyz"], "http://updated-article.com/" ]) # remove all fields from the article edit_article( sr, { "title": "Tin Cans Rock!", "subtitle": "", "snippet": "", "pageno": "", "authors": ["-Fred Nerk", "-Joe Blow"], "tags": ["-abc", "-xyz"], "url": "", }) # check that the search result was updated in the UI expected = ["Tin Cans Rock!", None, "", "", [], [], None] check_search_result(expected[0], _check_sr, expected) # check that the article was updated in the database do_search(SEARCH_ALL_ARTICLES) check_search_result(expected[0], _check_sr, expected)
def test_author_search(webdriver, flask_app, dbconn): """Test searching for authors.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="search.json") def click_on_author(sr, expected_author, expected_sr): authors = find_children(".authors .author", sr) assert len(authors) == 1 assert authors[0].text == expected_author authors[0].click() wait_for(2, lambda: get_search_result_names() == expected_sr) return get_search_results() # find an article and click on the author results = do_search(SEARCH_ALL) sr = find_search_result("Jagdpanzer 38(t) Hetzer", results) click_on_author(sr, "Michael Davies", ["Jagdpanzer 38(t) Hetzer"])
def test_article_search( webdriver, flask_app, dbconn ): """Test searching for articles.""" # initialize init_tests( webdriver, flask_app, dbconn, fixtures="search.json" ) def click_on_article( sr, expected_pub, expected_sr ): elems = find_children( ".content .collapsible li", sr ) elem = elems[0] # nb: we just use the first one assert elem.text == expected_pub elem.click() wait_for( 2, lambda: get_search_result_names() == expected_sr ) assert find_child( "#search-form input.query" ).get_attribute( "value" ) == "" # find a publication and click on one of its articles results = do_search( "vftt" ) sr = find_search_result( "View From The Trenches (100)", results ) click_on_article( sr, "Jagdpanzer 38(t) Hetzer", [ "Jagdpanzer 38(t) Hetzer", "View From The Trenches (100)" ] )
def test_publication_search(webdriver, flask_app, dbconn): """Test searching for publications.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="search.json") def click_on_publication(sr, expected_pub, expected_sr): classes = sr.get_attribute("class").split() if "article" in classes: elem = find_child(".header .publication", sr) elif "publisher" in classes: elems = find_children(".content .collapsible li", sr) elem = elems[0] # nb: we just use the first one else: assert "publication" in classes elem = find_child(".header .name", sr) assert elem.text == expected_pub elem.click() wait_for(2, lambda: get_search_result_names() == expected_sr) # find a publication and click on it results = do_search("vftt") sr = find_search_result("View From The Trenches (100)", results) click_on_publication( sr, "View From The Trenches (100)", ["View From The Trenches (100)", "Jagdpanzer 38(t) Hetzer"]) # find an article and click on its parent publication results = do_search("neutral") assert len(results) == 1 click_on_publication(results[0], "ASL Journal (5)", [ "ASL Journal (5)", "The Jungle Isn't Neutral", "Hunting DUKWs and Buffalos" ]) # find a publisher and click on one of its publications results = do_search("mmp") assert len(results) == 1 click_on_publication(results[0], "ASL Journal (4)", [ "ASL Journal (4)", "Hit 'Em High, Or Hit 'Em Low", "'Bolts From Above" ])
def test_db_report(webdriver, flask_app, dbconn): """Test the database report.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="db-report.json") # check the initial report row_counts, links, dupe_images, image_sizes = _get_db_report() assert row_counts == { "publishers": 2, "publications": 3, "articles": 5, "authors": 3, "scenarios": 2 } assert links == { "publishers": [2, []], "publications": [2, []], "articles": [2, []], } assert dupe_images == [] assert image_sizes == {} # add some images do_search(SEARCH_ALL) publ_sr = find_search_result("Avalon Hill", wait=2) fname = os.path.join(os.path.split(__file__)[0], "fixtures/images/1.gif") edit_publisher(publ_sr, {"image": fname}) results = get_search_results() pub_sr = find_search_result("ASL Journal (1)", results) fname = os.path.join(os.path.split(__file__)[0], "fixtures/images/2.gif") edit_publication(pub_sr, {"image": fname}) article_sr = find_search_result("ASLJ article 1", results) fname = os.path.join(os.path.split(__file__)[0], "fixtures/images/3.gif") edit_article(article_sr, {"image": fname}) article_sr = find_search_result("ASLJ article 2", results) fname = os.path.join(os.path.split(__file__)[0], "fixtures/images/3.gif") edit_article(article_sr, {"image": fname}) # check the updated report row_counts, _, dupe_images, image_sizes = _get_db_report() assert row_counts == { "publishers": 2, "publisher_images": 1, "publications": 3, "publication_images": 1, "articles": 5, "article_images": 2, "authors": 3, "scenarios": 2 } assert dupe_images == [[ "f0457ea742376e76ff276ce62c7a8540", "/images/article/100", ("ASLJ article 1", "/article/100"), ("ASLJ article 2", "/article/101"), ]] assert image_sizes == { "publishers": [ ("Avalon Hill", "/publisher/1", "/images/publisher/1"), ], "publications": [ ("ASL Journal (1)", "/publication/10", "/images/publication/10"), ], "articles": [ ("ASLJ article 1", "/article/100", "/images/article/100"), ("ASLJ article 2", "/article/101", "/images/article/101"), ] } # delete all the publishers (and associated objects), then check the updated report do_search(SEARCH_ALL) publ_sr = find_search_result("Avalon Hill", wait=2) select_sr_menu_option(publ_sr, "delete") check_ask_dialog("Delete this publisher?", "ok") results = get_search_results() publ_sr = find_search_result("Multiman Publishing", results) select_sr_menu_option(publ_sr, "delete") check_ask_dialog("Delete this publisher?", "ok") row_counts, links, dupe_images, image_sizes = _get_db_report() assert row_counts == { "publishers": 0, "publications": 0, "articles": 0, "authors": 3, "scenarios": 2 } assert links == { "publishers": [0, []], "publications": [0, []], "articles": [0, []], } assert dupe_images == [] assert image_sizes == {}
def check_scenarios(sr_name, expected): sr = find_search_result(sr_name) sr_scenarios = [s.text for s in find_children(".scenario", sr)] if sr_scenarios == expected: return sr return None
def check_authors(sr_name, expected): sr = find_search_result(sr_name) sr_authors = [a.text for a in find_children(".author", sr)] if sr_authors == expected: return sr return None
def test_article_lists(webdriver, flask_app, dbconn): """Test showing articles that belong to a publication.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="publications.json") def check_articles(results, expected): for pub_name, article_title in expected.items(): pub_sr = find_search_result(pub_name, results) articles = find_child(".collapsible", pub_sr) if article_title: # check that the article appears in the publication's search result assert find_child(".caption", articles).text == "Articles:" articles = find_children("li", articles) assert len(articles) == 1 assert articles[0].text == article_title # check that the "edit publication" dialog is correct select_sr_menu_option(pub_sr, "edit") dlg = find_child(".MuiDialog-root") articles = find_children(".articles li", dlg) assert len(articles) == 1 assert articles[0].text == article_title find_child("button.cancel", dlg).click() else: # check that the publication has no associated articles assert articles is None # check that the "edit publication" dialog is correct select_sr_menu_option(pub_sr, "edit") dlg = find_child(".MuiDialog-root") articles = find_children(".articles", dlg) assert len(articles) == 0 find_child("button.cancel", dlg).click() # check that the publications have no articles associated with them results = do_search(SEARCH_ALL_PUBLICATIONS) pub_name1, pub_name2 = "ASL Journal (1)", "MMP News" check_articles(results, {pub_name1: None, pub_name2: None}) # create an article that has no parent publication create_article({"title": "no parent"}) check_articles(results, {pub_name1: None, pub_name2: None}) # create an article that has a parent publication article_title = "test article" create_article({"title": article_title, "publication": pub_name1}) check_articles(results, {pub_name1: article_title, pub_name2: None}) # move the article to another publication article_sr = find_search_result(article_title) edit_article(article_sr, {"publication": pub_name2}) check_articles(None, {pub_name1: None, pub_name2: article_title}) # change the article to have no parent publication edit_article(article_sr, {"publication": "(none)"}) check_articles(None, {pub_name1: None, pub_name2: None}) # move the article back into a publication edit_article(article_sr, {"publication": pub_name1}) check_articles(None, {pub_name1: article_title, pub_name2: None}) # delete the article select_sr_menu_option(article_sr, "delete") check_ask_dialog(("Delete this article?", article_title), "ok") check_articles(None, {pub_name1: None, pub_name2: None})
def test_article_order(webdriver, flask_app, dbconn): """Test ordering of articles.""" # initialize init_tests(webdriver, flask_app, dbconn, fixtures="article-order.json") def check_article_order(expected): # check the article order in the database articles = defaultdict(list) query = dbconn.execute("SELECT pub_name, article_title, article_seqno" " FROM article LEFT JOIN publication" " ON article.pub_id = publication.pub_id" " ORDER BY article.pub_id, article_seqno") for row in query: articles[row[0]].append((row[1], row[2])) assert articles == expected # check the article order in the UI results = do_search(SEARCH_ALL) for pub_name in expected: if not pub_name: continue sr = find_search_result(pub_name, results) select_sr_menu_option(sr, "edit") dlg = wait_for_elem(2, "#publication-form") articles = [ a.text for a in find_children(".articles li.draggable", dlg) ] find_child(".cancel", dlg).click() assert articles == [a[0] for a in expected[pub_name]] # create some articles (to check the seq# is being assigned correctly) create_article({"title": "Article 1", "publication": "Publication A"}) check_article_order({"Publication A": [("Article 1", 1)]}) create_article({"title": "Article 2", "publication": "Publication A"}) check_article_order( {"Publication A": [("Article 1", 1), ("Article 2", 2)]}) create_article({"title": "Article 3", "publication": "Publication A"}) check_article_order({ "Publication A": [("Article 1", 1), ("Article 2", 2), ("Article 3", 3)] }) # create some articles (to check the seq# is being assigned correctly) create_article({"title": "Article 5", "publication": "Publication B"}) check_article_order({ "Publication A": [("Article 1", 1), ("Article 2", 2), ("Article 3", 3)], "Publication B": [("Article 5", 1)] }) create_article({"title": "Article 6", "publication": "Publication B"}) check_article_order({ "Publication A": [("Article 1", 1), ("Article 2", 2), ("Article 3", 3)], "Publication B": [("Article 5", 1), ("Article 6", 2)] }) # NOTE: It would be nice to test re-ordering articles via drag-and-drop, # but Selenium just ain't co-operating... :-/ # move an article to another publication sr = find_search_result("Article 1") edit_article(sr, {"publication": "Publication B"}) check_article_order({ "Publication A": [("Article 2", 2), ("Article 3", 3)], "Publication B": [("Article 5", 1), ("Article 6", 2), ("Article 1", 3)] }) # remove the article from the publication sr = find_search_result("Article 1") edit_article(sr, {"publication": "(none)"}) check_article_order({ "Publication A": [("Article 2", 2), ("Article 3", 3)], "Publication B": [("Article 5", 1), ("Article 6", 2)], None: [("Article 1", None)] }) # add the article to another publication sr = find_search_result("Article 1") edit_article(sr, {"publication": "Publication A"}) check_article_order({ "Publication A": [("Article 2", 2), ("Article 3", 3), ("Article 1", 4)], "Publication B": [("Article 5", 1), ("Article 6", 2)], })