<commit_before>"""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,
)<commit_msg>Add test for absolute redirection.<commit_after>"""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,
)


def test_absolute_redirection(build, output_dir):
    abs_source = os.path.join(output_dir, "redirects", "absolute_source.html")
    assert os.path.exists(abs_source)

    abs_destination = os.path.join(output_dir, "posts", "absolute.html")
    assert os.path.exists(abs_destination)

    with open(abs_destination) as abs_destination_fd:
        abs_destination_content = abs_destination_fd.read()

    redirect_tag = '<meta http-equiv="refresh" content="0; url=/redirects/absolute_source.html">'
    assert redirect_tag in abs_destination_content

    with open(abs_source) as abs_source_fd:
        absolute_source_content = abs_source_fd.read()

    assert absolute_source_content == 'absolute'
{'fraction_non_alphanumeric': 0.07772020725388601, 'fraction_numerical': 0.0006476683937823834, 'mean_word_length': 5.03515625, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3736', 'n_tokens_mistral': 510, 'n_tokens_neox': 493, 'n_words': 107}