Ejemplo n.º 1
0
def _check_sr(sr, expected):  #pylint: disable=too-many-return-statements
    """Check a search result."""

    # check the title and subtitle
    names = get_search_result_names([sr])
    if names[0] != expected[0]:
        return False
    elem = find_child(".subtitle", sr)
    if expected[1]:
        if not elem or elem.text != expected[1]:
            return False
    else:
        if elem is not None:
            return False

    # check the snippet
    if find_child(".snippet", sr).text != expected[2]:
        return False

    # check the authors
    authors = [t.text for t in find_children(".author", sr)]
    if authors != expected[4]:
        return False

    # check the tags
    tags = [t.text for t in find_children(".tag", sr)]
    if tags != expected[5]:
        return False

    # check the article's link
    elem = find_child("a.open-link", sr)
    if expected[6]:
        assert elem
        if elem.get_attribute("href") != expected[6]:
            return False
    else:
        assert elem is None

    return True
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
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 )
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
def _check_sr(sr, expected):
    """Check a search result."""

    # check the name and edition
    expected_name = expected[0]
    if expected[1]:
        expected_name += " ({})".format(expected[1])
    if find_child(".name", sr).text != expected_name:
        return False

    # check the publication date
    elem = find_child(".pub_date", sr)
    if expected[2]:
        assert elem
        if elem.text != expected[2]:
            return False
    else:
        assert elem is None

    # check the description
    if find_child(".description", sr).text != expected[3]:
        return False

    # check the tags
    tags = [t.text for t in find_children(".tag", sr)]
    if tags != expected[4]:
        return False

    # check the publication's link
    elem = find_child("a.open-link", sr)
    if expected[5]:
        assert elem
        if elem.get_attribute("href") != expected[5]:
            return False
    else:
        assert elem is None

    return True
Ejemplo n.º 7
0
def test_special_searches( webdriver, flask_app, dbconn ):
    """Test special searches."""

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

    # initialize
    def get_url():
        url = webdriver.current_url
        pos = url.find( "?" )
        if pos >= 0:
            url = url[:pos]
        while url.endswith( "/" ):
            url = url[:-1]
        return url
    url_stem = get_url()

    title_stem = "ASL Articles"
    def check_title( expected ):
        if expected:
            return webdriver.title == "{} - {}".format( title_stem, expected )
        else:
            return webdriver.title == title_stem

    def check_results( expected_url, expected_title, expected_sr ):
        wait_for( 2, lambda: check_title( expected_title ) )
        assert get_url() == "{}/{}".format( url_stem, expected_url ) if expected_url else url_stem
        results = get_search_results()
        assert get_search_result_names( results ) == expected_sr
        return results

    # test showing "technique" articles
    select_main_menu_option( "search-technique" )
    check_results( "", "Technique", [ "A technique article" ] )

    # test showing "tip" articles
    select_main_menu_option( "search-tips" )
    check_results( "", "Tips", [ "A tip article" ] )

    # test showing all publishers
    select_main_menu_option( "show-publishers" )
    results = check_results( "", "All publishers", [
        "Multi-Man Publishing", "View From The Trenches"
    ] )

    # test showing a single publication
    pubs = find_children( ".collapsible li", results[1] )
    assert [ p.text for p in pubs ] == [ "View From The Trenches (100)" ]
    pubs[0].click()
    results = check_results( "publication/12", "View From The Trenches (100)", [
        "View From The Trenches (100)", "Jagdpanzer 38(t) Hetzer"
    ] )

    # test showing a single publisher
    publ = find_child( "a.publisher", results[0] )
    assert publ.text == "View From The Trenches"
    publ.click()
    results = check_results( "publisher/2", "View From The Trenches", [
        "View From The Trenches", "View From The Trenches (100)"
    ] )

    # test showing a single article
    articles = find_children( ".collapsible li", results[1] )
    assert [ a.text for a in articles ] == [ "Jagdpanzer 38(t) Hetzer" ]
    articles[0].click()
    results = check_results( "article/520", "Jagdpanzer 38(t) Hetzer" , [
        "Jagdpanzer 38(t) Hetzer", "View From The Trenches (100)"
    ] )

    # test showing an author's articles
    authors = find_children( "a.author", results[0] )
    assert [ a.text for a in authors ] == [ "Michael Davies" ]
    authors[0].click()
    results = check_results( "author/1003", "Michael Davies" , [
        "Jagdpanzer 38(t) Hetzer"
    ] )

    # test searching for a tag
    tags = find_children( "a.tag", results[0] )
    assert [ t.text for t in tags ] == [ "jagdpanzer" ]
    tags[0].click()
    check_results( "tag/jagdpanzer", "jagdpanzer" , [
        "Jagdpanzer 38(t) Hetzer"
    ] )
Ejemplo n.º 8
0
 def get_tags( sr ):
     return find_children( ".tags .tag", sr )
Ejemplo n.º 9
0
 def find_highlighted( elems ):
     results = []
     for e in elems if isinstance(elems,list) else [elems]:
         results.extend( c.text for c in find_children( ".hilite", e ) )
     return results
Ejemplo n.º 10
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
Ejemplo n.º 11
0
 def check_authors(sr_name, expected):
     sr = find_search_result(sr_name)
     sr_authors = [a.text for a in find_children(".author", sr)]
     if sr_authors == expected:
         return sr
     return None
Ejemplo n.º 12
0
 def check_tags( sr ):
     name = get_search_result_names( [sr] )[ 0 ]
     tags = [ t.text for t in find_children( ".tag", sr ) ]
     if tags == expected[name]:
         return name
     return None
Ejemplo n.º 13
0
 def get_multiselect_values(self):
     """Get the current multi-select values."""
     return [
         e.text
         for e in find_children(".react-select__multi-value", self.select)
     ]
Ejemplo n.º 14
0
def _get_db_report():  #pylint: disable=too-many-locals
    """Generate the database report."""

    # generate the report
    select_main_menu_option("db-report")
    wait_for_elem(2, "#db-report .db-images")

    # unload the row counts
    row_counts = {}
    table = find_child("#db-report .db-row-counts")
    for row in find_children("tr", table):
        cells = find_children("td", row)
        mo = re.search(r"^(\d+)( \((\d+) images?\))?$", cells[1].text)
        key = cells[0].text.lower()[:-1]
        row_counts[key] = int(mo.group(1))
        if mo.group(3):
            row_counts[key[:-1] + "_images"] = int(mo.group(3))

    # unload the links
    links = {}
    table = find_child("#db-report .db-links")
    last_key = None
    for row in find_children("tr", table):
        cells = find_children("td", row)
        if len(cells) == 2:
            last_key = cells[0].text.lower()[:-1]
            links[last_key] = [int(cells[1].text), []]
        else:
            mo = re.search(r"^(.+) \((.+)\)$", cells[0].text)
            tags = find_children("a", cells[0])
            url = _fixup_url(tags[0].get_attribute("href"))
            links[last_key][1].append((mo.group(1), url, mo.group(2)))

    # unload duplicate images
    dupe_images = []
    for row in find_children("#db-report .dupe-analysis .dupe-image"):
        elem = find_child(".caption .hash", row)
        mo = re.search(r"^\(md5:(.+)\)$", elem.text)
        image_hash = mo.group(1)
        image_url = _fixup_url(find_child("img", row).get_attribute("src"))
        parents = []
        for entry in find_children(".collapsible li", row):
            url = _fixup_url(find_child("a", entry).get_attribute("href"))
            parents.append((entry.text, url))
        dupe_images.append(
            list(itertools.chain([image_hash, image_url], parents)))

    # unload the image sizes
    tab_ctrl = find_child("#db-report .db-images .react-tabs")
    image_sizes = {}
    for tab in find_children(".react-tabs__tab", tab_ctrl):
        key = tab.text.lower()
        tab_id = tab.get_attribute("id")
        tab.click()
        sel = ".react-tabs__tab-panel[aria-labelledby='{}'].react-tabs__tab-panel--selected".format(
            tab_id)
        tab_page = wait_for(
            2,
            lambda: find_child(sel, tab_ctrl)  #pylint: disable=cell-var-from-loop
        )
        parents = []
        for row_no, row in enumerate(
                find_children("table.image-sizes tr", tab_page)):
            if row_no == 0:
                continue
            cells = find_children("td", row)
            image_url = _fixup_url(
                find_child("img", cells[0]).get_attribute("src"))
            url = _fixup_url(find_child("a", cells[2]).get_attribute("href"))
            parents.append((cells[2].text, url, image_url))
        if parents:
            image_sizes[key] = parents
        else:
            assert tab_page.text == "No images found."

    return row_counts, links, dupe_images, image_sizes
Ejemplo n.º 15
0
 def check_scenarios(sr_name, expected):
     sr = find_search_result(sr_name)
     sr_scenarios = [s.text for s in find_children(".scenario", sr)]
     if sr_scenarios == expected:
         return sr
     return None