Exemple #1
0
def test_webpage_from_single_article():
    """ Test creating an article item page using item_from_md_filename()
    """

    webpage = Webpage(TEST_WEBSITE)
    webpage.item_from_md_filename('001-basic-article.md')

    # Page title should be "Article title - Website name"
    title = 'This is the heading - Test website name'
    assert webpage.title == title
    assert webpage.html.count('<title>' + title + '</title>') == 1

    # Page should use static page template
    assert '<p>Article page template</p>' in webpage.html

    # List page header should be present
    assert webpage.html.count('<div>list page header</div>') == 1

    # Webpage should contain the text from the article
    assert webpage.html.count('<p>And here is some text...</p>') == 1

    # Article item footer should be present
    assert webpage.html.count('<footer class="article-footer">') == 1

    # Filename for webpage should be based on the article
    article = Item(TEST_WEBSITE)
    article.from_md_filename('001-basic-article.md')
    assert webpage.filename == article.filename

    # Body should have class='magnetizer-article-page'
    assert webpage.html.count("<body class='magnetizer-article-page'>") == 1

    # Twitter card should be present
    assert '<meta name="twitter:card" content="summary_large_image" />' in webpage.html

    # Link to Atom feed should be present
    assert ('<link rel="alternate" type="application/rss+xml" ' +
            'href="https://example.com/atom.xml" />') in webpage.html

    # Link to CSS should be present
    assert '<link rel="stylesheet" type="text/css" href="test-stylesheet.css' in webpage.html

    # Includes should be included, as per the .md file
    assert webpage.html.count("<div class='include'>Include 1</div>") == 2
    assert webpage.html.count("<div class='include'>Include 2</div>") == 1
    assert webpage.html.count("<div class='include'>Include 3</div>") == 1
    assert "[ ERROR: Include 'inexistent_file.html' does not exist! ]" in webpage.html

    # No html comments should be left in page
    assert '<!--' not in webpage.html

    # Meta description should be pulled in from article
    assert '<meta name="description" content="Meta description from article">' in webpage.html

    # Footnote link should have been added
    assert "<a href='#1'>[1]</a>" in webpage.html

    # Footnote anchor should have been added
    assert "<a id='1'></a>[1]:" in webpage.html
Exemple #2
0
def test_page_indexability():
    """ Test to make sure indexability carries through from item to webpage
    """

    webpage_index = Webpage(TEST_WEBSITE)
    webpage_index.item_from_md_filename('001-basic-article.md')

    webpage_dont_index = Webpage(TEST_WEBSITE)
    webpage_dont_index.item_from_md_filename('009-unindexed-article.md')

    # Don't include noindex tag for article page that SHOULD be indexed
    assert '<meta name="robots" content="noindex">' not in webpage_index.html

    # Include noindex tag for article page that should NOT be indexed
    assert '<meta name="robots" content="noindex">' in webpage_dont_index.html
Exemple #3
0
def test_static_item_page():
    """ Test creating a static item page using item_from_md_filename()
    """

    webpage = Webpage(TEST_WEBSITE)
    webpage.item_from_md_filename('dont-show-on-list-page.md')

    # Page title should be "Article title - Website name"
    title = 'This post should not be in the index - Test website name'
    assert webpage.title == title
    assert webpage.html.count('<title>' + title + '</title>') == 1

    # Page should use static page template
    assert '<p>Static page template</p>' in webpage.html

    # List page header should NOT present
    assert webpage.html.count('<div>list page header</div>') == 0

    # Webpage should contain the text from the article
    assert webpage.html.count("<p>That's why it doesn't start with") == 1

    # Article footer should NOT be present
    assert webpage.html.count('<footer>footer</footer>') == 0

    # Filename for webpage should be based on the article
    article = Item(TEST_WEBSITE)
    article.from_md_filename('dont-show-on-list-page.md')
    assert webpage.filename == article.filename

    # Body should have class='magnetizer-static-page'
    assert webpage.html.count("<body class='magnetizer-static-page'>") == 1

    # Twitter card should be present
    assert '<meta name="twitter:card" content="summary_large_image" />' in webpage.html

    # Link to Atom feed should be present
    assert ('<link rel="alternate" type="application/rss+xml" ' +
            'href="https://example.com/atom.xml" />') in webpage.html

    # Link to CSS should be present
    assert '<link rel="stylesheet" type="text/css" href="test-stylesheet.css' in webpage.html

    # No html comments should be left in page
    assert '<!--' not in webpage.html