Example #1
0
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"], [] )
Example #2
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"]])
Example #3
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": []
    } )
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]"]])
Example #5
0
def test_clean_html( webdriver, flask_app, dbconn ):
    """Test cleaning HTML from tags."""

    # initialize
    init_tests( webdriver, flask_app, dbconn )

    # try to create a publication with HTML tags
    create_publication( {
        "name": "test publication",
        "tags": [ "+<b>bold</b>" ]
    }, toast_type="warning" )
    _check_tags( flask_app, {
        "test publication": [ "bold" ]
    } )

    # try to create an article with HTML tags
    create_article( {
        "title": "test article",
        "tags": [ "+<i>italic</i>" ]
    }, toast_type="warning" )
    _check_tags( flask_app, {
        "test publication": [ "bold" ],
        "test article": [ "italic" ]
    } )
Example #6
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 )
    )
Example #7
0
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)],
    })
Example #8
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})