Exemple #1
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 #2
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)
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_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 #5
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)
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 )
Exemple #7
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.")
Exemple #8
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)
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 #10
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/"
    ])
Exemple #11
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 article with HTML content
    create_article(
        {
            "title":
            "title: <span onclick='boo!'> <b>bold</b> <xxx>xxx</xxx> <i>italic</i> {}"
            .format(replace[0]),
            "subtitle":
            "<i>italicized subtitle</i> {}".format(replace[0]),
            "snippet":
            "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, [
        "title: bold xxx italic {}".format(
            replace[1]), "italicized subtitle {}".format(replace[1]),
        "bad stuff here: {}".format(replace[1]), "", [], [], None
    ])
    assert find_child( ".title", sr ).get_attribute( "innerHTML" ) \
        == "title: <span> <b>bold</b> xxx <i>italic</i> {}</span>".format( replace[1] )
    assert find_child( ".subtitle", sr ).get_attribute( "innerHTML" ) \
        == "<i>italicized subtitle</i> {}".format( replace[1] )
    assert check_toast("warning",
                       "Some values had HTML cleaned up.",
                       contains=True)

    # update the article with new HTML content
    edit_article(sr, {"title": "<div onclick='...'>updated</div>"},
                 toast_type="warning")
    wait_for(2, lambda: get_search_result_names() == ["updated"])
    assert check_toast("warning",
                       "Some values had HTML cleaned up.",
                       contains=True)
Exemple #12
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)
Exemple #13
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 an article with no title
    dlg = create_article({}, expected_error="Please give it a title.")

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

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

    # set the article's title
    do_create_test({"title": "New article"}, [
        "No publication was specified.", "No snippet was provided.",
        "No authors were specified."
    ])

    # set the article's page number
    do_create_test({"pageno": 99}, [
        "No publication was specified.",
        "A page number was specified but no publication.",
        "No snippet was provided.", "No authors were specified."
    ])

    # assign the article to a publisher
    do_create_test({
        "publication": "MMP News",
        "pageno": ""
    }, [
        "No page number was specified.", "No snippet was provided.",
        "No authors were specified."
    ])

    # set a non-numeric page number
    do_create_test({"pageno": "foo!"}, [
        "The page number is not numeric.", "No snippet was provided.",
        "No authors were specified."
    ])

    # set the article's page number and provide a snippet
    do_create_test({
        "pageno": 123,
        "snippet": "Article snippet."
    }, ["No authors were specified."])

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

    # check that the search result was updated in the UI
    check_search_result(
        article_sr, _check_sr,
        ["New article", "", "Article snippet.", "123", [], [], None])

    # try editing the article
    dlg = do_edit_test(article_sr, {}, ["No authors were specified."])
    find_child("button.cancel", dlg).click()

    # set the article's author
    do_edit_test(article_sr, {"authors": ["+Joe Blow"]}, None)

    # check that the search result was updated in the UI
    check_search_result(
        article_sr, _check_sr,
        ["New article", "", "Article snippet.", "123", ["Joe Blow"], [], None])