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()
Exemple #2
0
    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 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 )
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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)
Exemple #9
0
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" ] )
Exemple #10
0
    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]]
Exemple #11
0
    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
Exemple #12
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/"
    ])
Exemple #13
0
def test_image_preview( webdriver, flask_app, dbconn ):
    """Test previewing images."""

    # initialize
    init_tests( webdriver, flask_app, dbconn )

    def do_test( create, edit, refresh ):

        # create a new object
        webdriver.refresh()
        create()
        results = get_search_results()
        assert len(results) == 1
        sr = results[0]

        # add images to the object
        # NOTE: We're testing that images in an object already on-screen is updated correctly.
        fname = os.path.join( os.path.split(__file__)[0], "fixtures/images/1.gif" )
        description = 'foo <img src="/images/app.png" style="height:2em;" class="preview"> bar'
        edit( sr, fname, description )
        _check_previewable_images( sr )

        # refresh the object
        # NOTE: We're testing that images in an object loaded afresh is set up correctly.
        webdriver.refresh()
        wait_for( 2, lambda: find_child( "#search-form" ) )
        results = refresh()
        assert len(results) == 1
        _check_previewable_images( results[0] )

    # do the tests
    do_test(
        lambda: create_publisher( { "name": "Test publisher" } ),
        lambda sr, fname, description: edit_publisher( sr, { "image": fname, "description": description } ),
        lambda: do_search( SEARCH_ALL_PUBLISHERS )
    )
    do_test(
        lambda: create_publication( { "name": "Test publication" } ),
        lambda sr, fname, description: edit_publication( sr, { "image": fname, "description": description } ),
        lambda: do_search( SEARCH_ALL_PUBLICATIONS )
    )
    do_test(
        lambda: create_article( { "title": "Test article" } ),
        lambda sr, fname, description: edit_article( sr, { "image": fname, "snippet": description } ),
        lambda: do_search( SEARCH_ALL_ARTICLES )
    )
Exemple #14
0
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)
Exemple #15
0
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_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_create_publisher( webdriver, flask_app, dbconn ):
    """Test creating new publishers."""

    # initialize
    init_tests( webdriver, flask_app, dbconn, fixtures="publishers.json" )
    do_search( SEARCH_ALL_PUBLISHERS )

    # create a new publisher
    create_publisher( {
        "name": "New publisher",
        "url": "http://new-publisher.com",
        "description": "New publisher description."
    } )

    # check that the new publisher appears in the UI
    expected = [ "New publisher", "New publisher description.", "http://new-publisher.com/" ]
    check_search_result( expected[0], _check_sr, expected )

    # check that the new publisher has been saved in the database
    do_search( SEARCH_ALL_PUBLISHERS )
    check_search_result( expected[0], _check_sr, expected )
Exemple #18
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])
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 } )
Exemple #20
0
    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 )
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"])
Exemple #22
0
def test_publisher_search( webdriver, flask_app, dbconn ):
    """Test searching for publishers."""

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

    def click_on_publisher( sr, expected_publ, expected_sr ):
        elem = find_child( ".header .publisher", sr )
        assert elem.text == expected_publ
        elem.click()
        wait_for( 2, lambda: get_search_result_names() == expected_sr )

    # find a publication and click on its parent publisher
    results = do_search( "fantastic" )
    assert len(results) == 1
    click_on_publisher( results[0], "View From The Trenches", [
        "View From The Trenches", "View From The Trenches (100)"
    ] )
Exemple #23
0
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)"
    ] )
Exemple #24
0
def test_unicode(webdriver, flask_app, dbconn):
    """Test Unicode content."""

    # initialize
    init_tests(webdriver, flask_app, dbconn)

    # create a article with Unicode content
    create_article({
        "title": "japan = \u65e5\u672c",
        "subtitle": "s.korea = \ud55c\uad6d",
        "snippet": "greece = \u0395\u03bb\u03bb\u03ac\u03b4\u03b1",
        "tags": ["+\u0e51", "+\u0e52", "+\u0e53"],
        "url": "http://\ud55c\uad6d.com"
    })

    # check that the new article is showing the Unicode content correctly
    results = do_search(SEARCH_ALL_ARTICLES)
    assert len(results) == 1
    check_search_result(results[0], _check_sr, [
        "japan = \u65e5\u672c", "s.korea = \ud55c\uad6d",
        "greece = \u0395\u03bb\u03bb\u03ac\u03b4\u03b1", "", [],
        ["\u0e51", "\u0e52", "\u0e53"], "http://xn--3e0b707e.com/"
    ])
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 == {}
Exemple #26
0
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})
Exemple #27
0
def test_publisher_articles(webdriver, flask_app, dbconn):  #pylint: disable=too-many-statements
    """Test articles that are associated with a publisher (not publication)."""

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

    def check_parent_in_sr(sr, pub, publ):
        """Check the article's parent publication/publisher in a search result."""
        if pub:
            elem = wait_for(2, lambda: find_child(".header a.publication", sr))
            assert elem.is_displayed()
            assert elem.text == pub
            assert re.search(r"^http://.+?/publication/\d+",
                             elem.get_attribute("href"))
        elif publ:
            elem = wait_for(2, lambda: find_child(".header a.publisher", sr))
            assert elem.is_displayed()
            assert elem.text == publ
            assert re.search(r"^http://.+?/publisher/\d+",
                             elem.get_attribute("href"))
        else:
            assert False, "At least one publication/publisher must be specified."

    def check_parent_in_dlg(dlg, pub, publ):
        """Check the article's parent publication/publication in the edit dialog."""
        if pub:
            select = find_child(".row.publication .react-select", dlg)
            assert select.is_displayed()
            assert select.text == pub
        elif publ:
            select = find_child(".row.publisher .react-select", dlg)
            assert select.is_displayed()
            assert select.text == publ
        else:
            assert False, "At least one publication/publisher must be specified."

    # create an article associated with LFT
    create_article({"title": "test article", "publisher": "Le Franc Tireur"})
    results = wait_for(2, get_search_results)
    assert len(results) == 1
    sr = results[0]
    check_parent_in_sr(sr, None, "Le Franc Tireur")

    # open the article's dialog
    select_sr_menu_option(sr, "edit")
    dlg = wait_for_elem(2, "#article-form")
    check_parent_in_dlg(dlg, None, "Le Franc Tireur")

    # change the article to be associated with an MMP publication
    find_child(".row.publisher label.parent-mode").click()
    select = wait_for_elem(2, ".row.publication .react-select")
    ReactSelect(select).select_by_name("MMP News")
    find_child("button.ok", dlg).click()
    results = wait_for(2, get_search_results)
    assert len(results) == 1
    sr = results[0]
    check_parent_in_sr(sr, "MMP News", None)

    # open the article's dialog
    select_sr_menu_option(sr, "edit")
    dlg = wait_for_elem(2, "#article-form")
    check_parent_in_dlg(dlg, "MMP News", None)

    # change the article to be associated with MMP (publisher)
    find_child(".row.publication label.parent-mode").click()
    select = wait_for_elem(2, ".row.publisher .react-select")
    ReactSelect(select).select_by_name("Multiman Publishing")
    find_child("button.ok", dlg).click()
    results = wait_for(2, get_search_results)
    assert len(results) == 1
    sr = results[0]
    check_parent_in_sr(sr, None, "Multiman Publishing")

    # show the MMP publisher
    results = do_search("multiman")
    assert len(results) == 1
    sr = results[0]
    collapsibles = find_children(".collapsible", sr)
    assert len(collapsibles) == 2
    items = find_children("li a", collapsibles[1])
    assert len(items) == 1
    item = items[0]
    assert item.text == "test article"
    assert re.search(r"^http://.+?/article/\d+", item.get_attribute("href"))

    # delete the MMP publisher
    # NOTE: There are 2 MMP articles, the one that is in the "MMP News" publication,
    # and the test article we created above that is associated with the publisher.
    select_sr_menu_option(sr, "delete")
    check_ask_dialog(
        ("Delete this publisher?", "2 articles will also be deleted"), "ok")
    query = dbconn.execute("SELECT count(*) FROM article")
    assert query.scalar() == 0
Exemple #28
0
def _do_test_search( query, expected ):
    """Run a search and check the results."""
    results = do_search( query )
    assert set( get_search_result_names( results ) ) == set( expected )
    return results