Beispiel #1
0
def test_website_install_verify_remove():
    """Integration test: initializes, installs, verifies, and removes website."""
    with patch(_INPUT, return_value="y"):
        website = Website("example.com")

    assert not website.is_installed(), "Website 'example.com' should not exist on this server."
    assert not website.verify(), "Verification on a non-existing website should fail."

    with patch(_INPUT, return_value="y"):
        website.install()

    @localhost
    def installed_website_tests(website):
        """Function testing installed website. Wrapped by localhost() decorator."""
        print("test_domain *should* point to this server inside the decorated function.")
        assert website.is_installed()
        assert website.verify(), "Freshly installed website should verify as true."

    installed_website_tests(website)

    website.remove(ask=False)
    assert not website.is_installed()
    assert not website.verify(), "Verification on a non-existing website should fail."

    # Repeat the test for good measure:
    with patch(_INPUT, return_value="y"):
        website.install()

    installed_website_tests(website)

    website.remove(ask=False)
    assert not website.is_installed()
    assert not website.verify(), "Verification on a non-existing website should fail."
Beispiel #2
0
def test_website_pack_unpack():
    """Integration test: initializes, installs, verifies, packs, removes,
    unpacks and removes website."""
    with patch(_INPUT, return_value="y"):
        website = Website("example.com")

    assert not website.is_installed(), "Website 'example.com' should not exist on this server."
    assert not website.verify(), "Verification on a non-existing website should fail."

    with patch(_INPUT, return_value="y"):
        website.install()

    # Create a test file in htdocs
    the_file = File({"path": website.htdocs + "/index.html"})
    the_file.data = "Test file."
    the_file.create()

    # Pack the site
    website.pack()

    website.remove(ask=False)
    assert not website.is_installed()
    assert not website.verify(), "Verification on a non-existing website should fail."
    assert not the_file.exists()

    with patch(_INPUT, return_value="y"):
        website.unpack()

    assert website.is_installed()

    def verify(website):
        """Verify function to wrap with localhost decorator."""
        assert website.verify()

    localhost(verify)(website)
    assert the_file.exists()

    # Remove and check again for good measure
    website.remove(ask=False)
    assert not website.is_installed()
    assert not website.verify(), "Verification on a non-existing website should fail."
    assert not the_file.exists()