"""Check REDIRECTIONS"""

import io
import os

import pytest

import nikola.plugins.command.init
from nikola import __main__

from .helper import append_config, cd
from .test_demo_build import prepare_demo_site
from .test_empty_build import (  # NOQA
    test_archive_exists,
    test_avoid_double_slash_in_rss,
    test_check_files,
    test_check_links,
    test_index_in_sitemap,
)


@pytest.fixture(scope="module")
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    redirects_dir = os.path.join(target_dir, "files", "redirects")
    nikola.utils.makedirs(redirects_dir)

    target_path = os.path.join(redirects_dir, "absolute_source.html")
    with io.open(target_path, "w+", encoding="utf8") as outf:
        outf.write("absolute")

    append_config(
        target_dir,
        """
REDIRECTIONS = [ ("posts/absolute.html", "/redirects/absolute_source.html"), ]
""",
    )

    with cd(target_dir):
        __main__.main(["build"])

@@ -380,16 +380,717 @@
 ap,%0A)%0A%0A%0A
+def test_absolute_redirection(build, output_dir):%0A    abs_source = os.path.join(output_dir, %22redirects%22, %22absolute_source.html%22)%0A    assert os.path.exists(abs_source)%0A%0A    abs_destination = os.path.join(output_dir, %22posts%22, %22absolute.html%22)%0A    assert os.path.exists(abs_destination)%0A%0A    with open(abs_destination) as abs_destination_fd:%0A        abs_destination_content = abs_destination_fd.read()%0A%0A    redirect_tag = '%3Cmeta http-equiv=%22refresh%22 content=%220; url=/redirects/absolute_source.html%22%3E'%0A    assert redirect_tag in abs_destination_content%0A%0A    with open(abs_source) as abs_source_fd:%0A        absolute_source_content = abs_source_fd.read()%0A%0A    assert absolute_source_content == 'absolute'%0A%0A%0A
 @pytest.

Add test for absolute redirection.