コード例 #1
0
def test_includes():
    """ Test of webpage.includes()
    """

    webpage = Webpage(TEST_WEBSITE)
    webpage.html = '<h1>Some html</h1>'
    webpage.html += "<!-- MAGNETIZER_INCLUDE _include1.html -->"
    webpage.html += "<!-- MAGNETIZER_INCLUDE _include2.html -->"
    webpage.html += '<div>More html...</div>'
    webpage.html += "<!-- MAGNETIZER_INCLUDE _include3.html -->"
    webpage.html += "<!-- MAGNETIZER_INCLUDE _include1.html -->"

    correct_includes = ['_include1.html', '_include2.html', '_include3.html']
    includes = webpage.includes()

    # Set should contain each include from the html
    for correct_include in correct_includes:
        assert correct_include in includes

    assert len(includes) == len(correct_includes)
コード例 #2
0
def test_webpage_write():
    """ Test of webpage.write()
    """

    result = "This is a test!"

    webpage = Webpage(TEST_WEBSITE)
    webpage.html = result
    webpage.filename = 'my-post.html'
    webpage.write()

    # File should have the correct contents
    with open(
            TEST_WEBSITE.config.value('output_path') + webpage.filename,
            'r') as myfile:
        assert myfile.read() == result

    # Page should be included in sitemap
    assert 'https://example.com/my-post.html' in TEST_WEBSITE.sitemap.pages

    TEST_WEBSITE.wipe()