test_redirects.py

Tests the redirects plugin


test_redirect_exists function

ensure that the default workflow works

test_redirect_exists source
def test_redirect_exists(tmp_files: Path, old: str, new: str) -> None:
    "ensure that the default workflow works"
    with set_directory(tmp_files):
        m = Markata()
        redirects.save(m)
        redirect_file = Path("markout") / old / "index.html"
        assert redirect_file.exists()
        assert (
            f'<meta http-equiv="Refresh" content="0; url=\'{new}\'" />'
            in redirect_file.read_text()
        )

test_redirect_ignore_splat function

splats cannot be supported statically, test that they are ignored

test_redirect_ignore_splat source
def test_redirect_ignore_splat(tmp_files: Path, old: str) -> None:
    "splats cannot be supported statically, test that they are ignored"
    with set_directory(tmp_files):
        m = Markata()
        redirects.save(m)
        redirect_file = Path("markout") / old / "index.html"
        assert not redirect_file.exists()

test_redirect_ignore_more_params function

status codes cannot be supported statically as they are issued by the server

test_redirect_ignore_more_params source
def test_redirect_ignore_more_params(tmp_files: Path, old: str) -> None:
    "status codes cannot be supported statically as they are issued by the server"
    with set_directory(tmp_files):
        m = Markata()
        redirects.save(m)
        redirect_file = Path("markout") / old / "index.html"
        assert not redirect_file.exists()

test_redirect_configure_redirect_file function

ensure that the redirects file can be configured

test_redirect_configure_redirect_file source
def test_redirect_configure_redirect_file(
    tmp_files: Path, redirect_file: str, old: str, new: str
) -> None:
    "ensure that the redirects file can be configured"
    with set_directory(tmp_files):
        m = Markata()
        m.config["redirects"] = redirect_file
        redirects.save(m)
        redirect_html = Path("markout") / old / "index.html"
        assert redirect_html.exists()
        assert (
            f'<meta http-equiv="Refresh" content="0; url=\'{new}\'" />'
            in redirect_html.read_text()
        )

test_redirect_custom_template function

ensure the template can be configured

test_redirect_custom_template source
def test_redirect_custom_template(
    tmp_files: Path, redirect_template: str, old: str, new: str
) -> None:
    "ensure the template can be configured"
    with set_directory(tmp_files):
        m = Markata()
        m.config["redirect_template"] = redirect_template
        redirects.save(m)
        redirect_file = Path("markout") / old / "index.html"
        assert redirect_file.exists()
        assert f"{old} is now {new}" in redirect_file.read_text()

test_redirect_empty function

ensure empty redirects files work

test_redirect_empty source
def test_redirect_empty(tmp_files: Path, old: str, new: str) -> None:
    "ensure empty redirects files work"
    with set_directory(tmp_files):
        m = Markata()
        redirects.save(m)

test_redirect_file_missing function

ensure missing redirects file works

test_redirect_file_missing source
def test_redirect_file_missing(tmpdir: Path) -> None:
    "ensure missing redirects file works"
    with set_directory(tmpdir):
        m = Markata()
        redirects.save(m)