コード例 #1
0
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 )
コード例 #2
0
def test_constraints(webdriver, flask_app, dbconn):
    """Test constraint validation."""

    # initialize
    init_tests(webdriver,
               flask_app,
               dbconn,
               disable_constraints=False,
               fixtures="publishers.json")

    # try to create a publisher with no title
    dlg = create_publisher({}, expected_error="Please give them a name.")

    # try to create a duplicate publisher
    create_publisher(
        {"name": "Avalon Hill"},
        dlg=dlg,
        expected_error="There is already a publisher with this name.")

    # set the publisher's name
    create_publisher({"name": "Joe Publisher"}, dlg=dlg)

    # check that the search result was updated in the UI
    expected = ["Joe Publisher", "", ""]
    sr = check_search_result(expected[0], _check_sr, expected)

    # try to remove the publisher's name
    edit_publisher(sr, {"name": "   "},
                   expected_error="Please give them a name.")
コード例 #3
0
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 )
コード例 #4
0
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"]])
コード例 #5
0
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)
コード例 #6
0
def test_create_article(webdriver, flask_app, dbconn):
    """Test creating new articles."""

    # initialize
    init_tests(webdriver, flask_app, dbconn, fixtures="articles.json")
    do_search(SEARCH_ALL_ARTICLES)

    # create a new article
    create_article({
        "title": "New article",
        "subtitle": "New subtitle",
        "snippet": "New snippet.",
        "pageno": "99",
        "authors": ["+Me"],
        "tags": ["+111", "+222", "+333"],
        "url": "http://new-snippet.com"
    })

    # check that the new article appears in the UI
    expected = [
        "New article", "New subtitle", "New snippet.", "99", ["Me"],
        ["111", "222", "333"], "http://new-snippet.com/"
    ]
    check_search_result(expected[0], _check_sr, expected)

    # check that the new article has been saved in the database
    do_search(SEARCH_ALL_ARTICLES)
    check_search_result(expected[0], _check_sr, expected)
コード例 #7
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
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"], [] )
コード例 #8
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
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"], [] )
コード例 #9
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
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"], [] )
コード例 #10
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
def test_author_aliases( webdriver, flask_app, dbconn ):
    """Test author aliases."""

    # initialize
    # NOTE: We can't monkeypatch the author aliases table, since we might be talking to
    # a remote Flask server not under our control (e.g. in a Docker container). Instead,
    # we define the aliases we need in a test config file, which is always loaded.
    init_tests( webdriver, flask_app, dbconn, fixtures="author-aliases.json" )

    def do_test( author_names ):

        # test each author in the alias group
        expected = set( "By {}".format(a) for a in author_names )
        for author_name in author_names:

            # find the author's article
            results = do_search( '"{}"'.format( author_name ) )
            assert len(results) == 1

            # click on the author's name
            authors = find_children( ".author", results[0] )
            assert len(authors) == 1
            authors[0].click()

            # check that we found all the articles by the aliased names
            wait_for( 2, lambda: set( get_search_result_names() ) == expected )

    # test author aliases
    do_test( [ "Charles M. Jones", "Chuck Jones", "Charles Martin Jones" ] )
    do_test( [ "Joseph Blow", "Joe Blow" ] )
    do_test( [ "John Doe" ] )
コード例 #11
0
ファイル: test_startup.py プロジェクト: brookscl/asl-articles
def test_startup_messages( webdriver, flask_app, dbconn ):
    """Test startup messages."""

    # initialize
    init_tests( webdriver, flask_app, dbconn )
    startup_msgs = asl_articles.startup._startup_msgs #pylint: disable=protected-access

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

    # test each type of startup message
    do_test( "info" )
    do_test( "warning" )
    do_test( "error" )
コード例 #12
0
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)
コード例 #13
0
def test_timestamps(webdriver, flask_app, dbconn):
    """Test setting of timestamps."""

    # initialize
    init_tests(webdriver, flask_app, dbconn)

    # create a publication
    create_publication({"name": "My Publication"})
    results = get_search_results()
    assert len(results) == 1
    pub_sr = results[0]
    pub_id = pub_sr.get_attribute("testing--pub_id")

    # check its timestamps
    row = get_publication_row(dbconn, pub_id, ["time_created", "time_updated"])
    assert row[0]
    assert row[1] is None

    # update the publication
    edit_publication(pub_sr, {"name": "My Publication (updated)"})

    # check its timestamps
    row2 = get_publication_row(dbconn, pub_id,
                               ["time_created", "time_updated"])
    assert row2[0] == row[0]
    assert row2[1] > row2[0]
コード例 #14
0
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)
コード例 #15
0
def test_timestamps(webdriver, flask_app, dbconn):
    """Test setting of timestamps."""

    # initialize
    init_tests(webdriver, flask_app, dbconn)

    # create an article
    create_article({"title": "My Article"})
    results = get_search_results()
    assert len(results) == 1
    article_sr = results[0]
    article_id = article_sr.get_attribute("testing--article_id")

    # check its timestamps
    row = get_article_row(dbconn, article_id, ["time_created", "time_updated"])
    assert row[0]
    assert row[1] is None

    # update the article
    edit_article(article_sr, {"title": "My Article (updated)"})

    # check its timestamps
    row2 = get_article_row(dbconn, article_id,
                           ["time_created", "time_updated"])
    assert row2[0] == row[0]
    assert row2[1] > row2[0]
コード例 #16
0
def test_unicode(webdriver, flask_app, dbconn):
    """Test Unicode content."""

    # initialize
    init_tests(webdriver, flask_app, dbconn)

    # create a publication with Unicode content
    create_publication({
        "name":
        "japan = \u65e5\u672c",
        "edition":
        "\u263a",
        "tags": ["+\u0e51", "+\u0e52", "+\u0e53"],
        "url":
        "http://\ud55c\uad6d.com",
        "description":
        "greece = \u0395\u03bb\u03bb\u03ac\u03b4\u03b1"
    })

    # check that the new publication is showing the Unicode content correctly
    results = do_search(SEARCH_ALL_PUBLICATIONS)
    assert len(results) == 1
    check_search_result(results[0], _check_sr, [
        "japan = \u65e5\u672c", "\u263a", None,
        "greece = \u0395\u03bb\u03bb\u03ac\u03b4\u03b1",
        ["\u0e51", "\u0e52", "\u0e53"], "http://xn--3e0b707e.com/"
    ])
コード例 #17
0
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)
コード例 #18
0
def test_confirm_discard_changes(webdriver, flask_app, dbconn):
    """Test confirmation of discarding changes made to a dialog."""

    # initialize
    init_tests(webdriver,
               flask_app,
               dbconn,
               disable_confirm_discard_changes=False,
               fixtures="publications.json")

    # do the test
    def update_react_select(elem, val):
        select = ReactSelect(find_parent_by_class(elem, "react-select"))
        select.select_by_name(val)

    def update_multiselect(elem, vals):
        select = ReactSelect(find_parent_by_class(elem, "react-select"))
        select.update_multiselect_values(*vals)

    do_test_confirm_discard_changes(
        "new-publication", {
            "publisher":
            (lambda elem: update_react_select(elem, "Avalon Hill"),
             lambda elem: update_react_select(elem, "(none)")),
            "tags": (
                lambda elem: update_multiselect(elem, ["+foo"]),
                lambda elem: update_multiselect(elem, ["-foo"]),
            )
        })
コード例 #19
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
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" ] )
コード例 #20
0
def test_constraints(webdriver, flask_app, dbconn):
    """Test constraint validation."""

    # initialize
    init_tests(webdriver,
               flask_app,
               dbconn,
               disable_constraints=False,
               fixtures="publications.json")

    # try to create a publication with no name
    dlg = create_publication({}, expected_error="Please give it a name.")

    def do_create_test(vals, expected):
        return create_publication(vals, dlg=dlg, expected_constraints=expected)

    def do_edit_test(sr, vals, expected):
        return edit_publication(sr, vals, expected_constraints=expected)

    # set the publication's name
    do_create_test({"name": "ASL Journal"}, [
        "The publication's edition was not specified.",
        "The publication date was not specified.",
        "A publisher was not specified.",
    ])

    # try to create a duplicate publication
    create_publication(
        {"edition": 1},
        dlg=dlg,
        expected_error="There is already a publication with this name/edition."
    )

    # set the publication's edition and date
    do_create_test({
        "edition": 3,
        "pub_date": "yesterday"
    }, [
        "A publisher was not specified.",
    ])

    # accept the constraint warnings
    find_child("button.ok", dlg).click()
    find_child("#ask button.ok").click()
    results = wait_for(2, get_search_results)
    pub_sr = results[0]

    # check that the search result was updated in the UI
    check_search_result(pub_sr, _check_sr,
                        ["ASL Journal", "3", "yesterday", "", [], ""])

    # try editing the publication
    dlg = do_edit_test(pub_sr, {}, [
        "A publisher was not specified.",
    ])
    find_child("button.cancel", dlg).click()

    # set the publisher
    do_edit_test(pub_sr, {"publisher": "Avalon Hill"}, None)
コード例 #21
0
def test_confirm_discard_changes( webdriver, flask_app, dbconn ):
    """Test confirmation of discarding changes made to a dialog."""

    # initialize
    init_tests( webdriver, flask_app, dbconn, disable_confirm_discard_changes=False )

    # do the test
    do_test_confirm_discard_changes( "new-publisher" )
コード例 #22
0
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": []
    } )
コード例 #23
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
def test_search_scenarios( webdriver, flask_app, dbconn ):
    """Test searching for scenarios."""

    # initialize
    init_tests( webdriver, flask_app, dbconn, fixtures="search.json" )

    # search for some scenarios
    _do_test_search( "foul", ["Hunting DUKWs and Buffalos"] )
    _do_test_search( "hs17", ["Hunting DUKWs and Buffalos"] )
コード例 #24
0
def test_parent_publisher(webdriver, flask_app, dbconn):
    """Test setting a publication's parent publisher."""

    # initialize
    init_tests(webdriver, flask_app, dbconn, fixtures="parents.json")

    def check_result(sr, expected_parent):  #pylint: disable=too-many-return-statements

        # check that the parent publisher was updated in the UI
        elem = find_child(".header .publisher", sr)
        if expected_parent:
            if elem.text != "{}".format(expected_parent[1]):
                return None
        else:
            if elem is not None:
                return None

        # check that the parent publisher was updated in the database
        pub_id = sr.get_attribute("testing--pub_id")
        url = flask_app.url_for("get_publication", pub_id=pub_id)
        pub = json.load(urllib.request.urlopen(url))
        if expected_parent:
            if pub["publ_id"] != expected_parent[0]:
                return None
        else:
            if pub["publ_id"] is not None:
                return None

        # check that the parent publisher was updated in the UI
        results = do_search('"MMP News"')
        assert len(results) == 1
        sr = results[0]
        elem = find_child(".header .publisher", sr)
        if expected_parent:
            if elem.text != "{}".format(expected_parent[1]):
                return None
        else:
            if elem is not None:
                return None

        return sr

    # create a publication with no parent publisher
    create_publication({"name": "MMP News"})
    results = get_search_results()
    assert len(results) == 1
    sr = wait_for(2, lambda: check_result(results[0], None))

    # change the publication to have a publisher
    edit_publication(sr, {"publisher": "Multiman Publishing"})
    sr = wait_for(2, lambda: check_result(sr, (1, "Multiman Publishing")))

    # change the publication back to having no publisher
    edit_publication(sr, {"publisher": "(none)"})
    sr = wait_for(2, lambda: check_result(sr, None))
コード例 #25
0
def test_parent_publisher(webdriver, flask_app, dbconn):
    """Test setting an article's parent publication."""

    # initialize
    init_tests(webdriver, flask_app, dbconn, fixtures="parents.json")

    def check_result(sr, expected_parent):  #pylint: disable=too-many-return-statements

        # check that the parent publication was updated in the UI
        elem = find_child(".header .publication", sr)
        if expected_parent:
            if elem.text != "{}".format(expected_parent[1]):
                return None
        else:
            if elem is not None:
                return None

        # check that the parent publication was updated in the database
        article_id = sr.get_attribute("testing--article_id")
        url = flask_app.url_for("get_article", article_id=article_id)
        article = json.load(urllib.request.urlopen(url))
        if expected_parent:
            if article["pub_id"] != expected_parent[0]:
                return None
        else:
            if article["pub_id"] is not None:
                return None

        # check that the parent publication was updated in the UI
        results = do_search('"My Article"')
        assert len(results) == 1
        sr = results[0]
        elem = find_child(".header .publication", sr)
        if expected_parent:
            if elem.text != "{}".format(expected_parent[1]):
                return None
        else:
            if elem is not None:
                return None

        return sr

    # create an article with no parent publication
    create_article({"title": "My Article"})
    results = get_search_results()
    assert len(results) == 1
    sr = wait_for(2, lambda: check_result(results[0], None))

    # change the article to have a publication
    edit_article(sr, {"publication": "ASL Journal"})
    sr = wait_for(2, lambda: check_result(sr, (1, "ASL Journal")))

    # change the article back to having no publication
    edit_article(sr, {"publication": "(none)"})
    sr = wait_for(2, lambda: check_result(sr, None))
コード例 #26
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
def test_search_authors( webdriver, flask_app, dbconn ):
    """Test searching for authors."""

    # initialize
    init_tests( webdriver, flask_app, dbconn, fixtures="search.json" )

    # search for some authors
    _do_test_search( "pitcavage", ["The Jungle Isn't Neutral"] )
    _do_test_search( "davie", ["Jagdpanzer 38(t) Hetzer"] )
    _do_test_search( "pit* dav*", [] ) # nb: implied AND
    _do_test_search( "pit* OR dav*", ["The Jungle Isn't Neutral","Jagdpanzer 38(t) Hetzer"] )
コード例 #27
0
ファイル: test_search.py プロジェクト: brookscl/asl-articles
def test_empty_search( webdriver, flask_app, dbconn ):
    """Test handling of an empty search string."""

    # initialize
    init_tests( webdriver, flask_app, dbconn )

    # search for an empty string
    form = find_child( "#search-form" )
    find_child( ".query", form ).send_keys( "   " )
    find_child( "button[type='submit']", form ).click()
    dlg = wait_for_elem( 2, "#ask" )
    assert find_child( ".MuiDialogContent-root", dlg ).text == "Please enter something to search for."
コード例 #28
0
def test_article_ratings(webdriver, flask_app, dbconn):
    """Test article ratings."""

    # initialize
    init_tests(webdriver, flask_app, dbconn, fixtures="articles.json")

    def do_test(article_sr, star_no, expected):

        # click the specified article star
        stars = find_children(".rating-stars img", article_sr)
        stars[star_no].click()
        for sr_no, sr in enumerate(results):
            assert get_rating(sr) == expected[sr_no]

        # compare the ratings on-screen with what's in the database
        for sr in results:
            article_id = sr.get_attribute("testing--article_id")
            ui_rating = get_rating(sr)
            db_rating = dbconn.execute(
                "SELECT article_rating FROM article WHERE article_id={}".
                format(article_id)).scalar()
            if db_rating is None:
                assert ui_rating == 0
            else:
                assert ui_rating == db_rating

    def get_rating(article_sr):
        stars = [
            "disabled" not in star.get_attribute("src")
            for star in find_children(".rating-stars img", article_sr)
        ]
        rating = 0
        for star in stars:
            if not star:
                assert all(not s for s in stars[rating + 1:])
                break
            rating += 1
        return rating

    # get the test articles
    results = do_search(SEARCH_ALL_ARTICLES)

    # do the tests
    do_test(results[0], 2, [3, 0])
    do_test(results[1], 1, [3, 2])

    # do the tests
    do_test(results[0], 2, [2, 2])
    do_test(results[0], 2, [3, 2])
    do_test(results[0], 0, [1, 2])
    do_test(results[0], 0, [0, 2])
    do_test(results[0], 0, [1, 2])
コード例 #29
0
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)
コード例 #30
0
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 } )