| 1 |
from unittest.mock import Mock |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from sphinx_reredirects import Reredirects |
| 6 |
|
| 7 |
|
| 8 |
def test_placeholder1(): |
| 9 |
actual = Reredirects._apply_placeholders( |
| 10 |
"features/one", "https://elsewhere/$source.html" |
| 11 |
) |
| 12 |
expected = "https://elsewhere/features/one.html" |
| 13 |
assert actual == expected |
| 14 |
|
| 15 |
|
| 16 |
def test_placeholder2(): |
| 17 |
actual = Reredirects._apply_placeholders( |
| 18 |
"features", "https://elsewhere/$source.html" |
| 19 |
) |
| 20 |
expected = "https://elsewhere/features.html" |
| 21 |
assert actual == expected |
| 22 |
|
| 23 |
|
| 24 |
def test_no_placeholder(): |
| 25 |
actual = Reredirects._apply_placeholders( |
| 26 |
"features", "https://elsewhere/features.html" |
| 27 |
) |
| 28 |
expected = "https://elsewhere/features.html" |
| 29 |
assert actual == expected |
| 30 |
|
| 31 |
|
| 32 |
@pytest.mark.xfail( |
| 33 |
reason="To be fixed. Reported in https://gitlab.com/documatt/sphinx-reredirects/-/issues/1" # noqa: E501 |
| 34 |
) |
| 35 |
def test_source_placeholder_returns_just_matched_part(): |
| 36 |
sphinx_mock = Mock() |
| 37 |
sphinx_mock.config = { |
| 38 |
"redirects": {"faq/*": "http://new.com/$source.html"}, |
| 39 |
"redirect_html_template_file": None, |
| 40 |
} |
| 41 |
sphinx_mock.env.found_docs = ["faq/one", "faq/two"] |
| 42 |
|
| 43 |
actual = Reredirects(sphinx_mock).grab_redirects() |
| 44 |
expected = { |
| 45 |
"faq/one": "http://new.com/one.html", |
| 46 |
"faq/two": "http://new.com/two.html", |
| 47 |
} |
| 48 |
assert actual == expected |