Exemple #1
0
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"], [] )
Exemple #2
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": []
    } )
Exemple #3
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 )
    )
def test_publication_lists( webdriver, flask_app, dbconn ):
    """Test showing publications that belong a publisher."""

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

    def check_publications( results, expected ):
        for publ_name,pub_name in expected.items():
            publ_sr = find_search_result( publ_name, results )
            pubs = find_child( ".collapsible", publ_sr )
            if pub_name:
                # check that the publication appears in the publisher's search result
                assert find_child( ".caption", pubs ).text == "Publications:"
                pubs = find_children( "li", pubs )
                assert len(pubs) == 1
                assert pubs[0].text == pub_name
            else:
                # check that the publisher has no associated publications
                assert pubs is None

    # check that the publishers have no publications associated with them
    results = do_search( SEARCH_ALL_PUBLISHERS )
    publ_name1, publ_name2 = "Avalon Hill", "Multiman Publishing"
    check_publications( results, { publ_name1: None, publ_name2: None } )

    # create a publication that has no parent publisher
    create_publication( { "name": "no parent" } )
    check_publications( results, { publ_name1: None, publ_name2: None } )

    # create a publication that has a parent publisher
    pub_name = "test publication"
    create_publication( { "name": pub_name, "publisher": publ_name1 } )
    check_publications( results, { publ_name1: pub_name, publ_name2: None } )

    # move the publication to another publisher
    pub_sr = find_search_result( pub_name )
    edit_publication( pub_sr, { "publisher": publ_name2 } )
    check_publications( results, { publ_name1: None, publ_name2: pub_name } )

    # change the publication to have no parent publisher
    edit_publication( pub_sr, { "publisher": "(none)" } )
    check_publications( results, { publ_name1: None, publ_name2: None } )

    # move the publication back to a publisher
    edit_publication( pub_sr, { "publisher": publ_name1 } )
    check_publications( results, { publ_name1: pub_name, publ_name2: None } )

    # delete the publication
    select_sr_menu_option( pub_sr, "delete" )
    check_ask_dialog( ( "Delete this publication?", pub_name ), "ok" )
    check_publications( results, { publ_name1: None, publ_name2: None } )
def test_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 == {}