Skip to content

Commit

Permalink
Tests: linkcheck: add remote-URL-redirection-ignored test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Dec 10, 2024
1 parent 4e21c08 commit a067500
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_builders/test_build_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def test_TooManyRedirects_on_HEAD(app, monkeypatch):


@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver')
def test_ignore_redirection(app):
def test_ignore_local_redirection(app):
with serve_application(app, InfiniteRedirectOnHeadHandler) as address:
app.config.linkcheck_ignore = [f'http://{address}/redirected']
app.build()
Expand All @@ -983,6 +983,37 @@ def test_ignore_redirection(app):
}


class RemoteDomainRedirectHandler(InfiniteRedirectOnHeadHandler):
protocol_version = 'HTTP/1.1'

def do_GET(self):
self.send_response(301, 'Found')
if self.path == '/':
self.send_header('Location', '/local')
elif self.path == '/local':
self.send_header('Location', 'http://example.test/migrated')
self.send_header('Content-Length', '0')
self.end_headers()


@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver')
def test_ignore_remote_redirection(app):
with serve_application(app, RemoteDomainRedirectHandler) as address:
app.config.linkcheck_ignore = [f'http://example.test']

Check failure on line 1002 in tests/test_builders/test_build_linkcheck.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

tests/test_builders/test_build_linkcheck.py:1002:40: F541 f-string without any placeholders
app.build()

with open(app.outdir / 'output.json', encoding='utf-8') as fp:
content = json.load(fp)
assert content == {
'code': 301,
'status': 'ignored',
'filename': 'index.rst',
'lineno': 1,
'uri': f'http://{address}/',
'info': f'ignored redirect: http://example.test/migrated',

Check failure on line 1013 in tests/test_builders/test_build_linkcheck.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

tests/test_builders/test_build_linkcheck.py:1013:17: F541 f-string without any placeholders
}


def make_retry_after_handler(
responses: list[tuple[int, str | None]],
) -> type[BaseHTTPRequestHandler]:
Expand Down

0 comments on commit a067500

Please sign in to comment.