File: test_placeholders.py

package info (click to toggle)
sphinx-reredirects 0.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 204 kB
  • sloc: python: 315; makefile: 25
file content (48 lines) | stat: -rw-r--r-- 1,348 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from unittest.mock import Mock

import pytest

from sphinx_reredirects import Reredirects


def test_placeholder1():
    actual = Reredirects._apply_placeholders(
        "features/one", "https://elsewhere/$source.html"
    )
    expected = "https://elsewhere/features/one.html"
    assert actual == expected


def test_placeholder2():
    actual = Reredirects._apply_placeholders(
        "features", "https://elsewhere/$source.html"
    )
    expected = "https://elsewhere/features.html"
    assert actual == expected


def test_no_placeholder():
    actual = Reredirects._apply_placeholders(
        "features", "https://elsewhere/features.html"
    )
    expected = "https://elsewhere/features.html"
    assert actual == expected


@pytest.mark.xfail(
    reason="To be fixed. Reported in https://gitlab.com/documatt/sphinx-reredirects/-/issues/1"  # noqa: E501
)
def test_source_placeholder_returns_just_matched_part():
    sphinx_mock = Mock()
    sphinx_mock.config = {
        "redirects": {"faq/*": "http://new.com/$source.html"},
        "redirect_html_template_file": None,
    }
    sphinx_mock.env.found_docs = ["faq/one", "faq/two"]

    actual = Reredirects(sphinx_mock).grab_redirects()
    expected = {
        "faq/one": "http://new.com/one.html",
        "faq/two": "http://new.com/two.html",
    }
    assert actual == expected