mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add testcase for combination of allow_redirects and warn_redirects
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
exclude_patterns = ['_build']
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
`local server1 <http://localhost:7777/path1>`_
|
||||||
|
`local server2 <http://localhost:7777/path2>`_
|
||||||
@@ -289,33 +289,55 @@ def test_follows_redirects_on_GET(app, capsys, warning):
|
|||||||
assert warning.getvalue() == ''
|
assert warning.getvalue() == ''
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True,
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-warn-redirects',
|
||||||
confoverrides={'linkcheck_warn_redirects': True})
|
freshenv=True, confoverrides={'linkcheck_warn_redirects': True})
|
||||||
def test_linkcheck_warn_redirects(app, warning):
|
def test_linkcheck_warn_redirects(app, warning):
|
||||||
with http_server(make_redirect_handler(support_head=False)):
|
with http_server(make_redirect_handler(support_head=False)):
|
||||||
app.build()
|
app.build()
|
||||||
assert ("index.rst.rst:1: WARNING: redirect http://localhost:7777/ - with Found to "
|
assert ("index.rst.rst:1: WARNING: redirect http://localhost:7777/path1 - with Found to "
|
||||||
"http://localhost:7777/?redirected=1\n" in strip_escseq(warning.getvalue()))
|
"http://localhost:7777/?redirected=1\n" in strip_escseq(warning.getvalue()))
|
||||||
|
assert ("index.rst.rst:1: WARNING: redirect http://localhost:7777/path2 - with Found to "
|
||||||
|
"http://localhost:7777/?redirected=1\n" in strip_escseq(warning.getvalue()))
|
||||||
|
assert len(warning.getvalue().splitlines()) == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True,
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-warn-redirects',
|
||||||
confoverrides={
|
freshenv=True, confoverrides={
|
||||||
'linkcheck_allowed_redirects': {'http://localhost:.*/': '.*'}
|
'linkcheck_allowed_redirects': {'http://localhost:7777/.*1': '.*'}
|
||||||
})
|
})
|
||||||
def test_linkcheck_allowed_redirects(app):
|
def test_linkcheck_allowed_redirects(app, warning):
|
||||||
with http_server(make_redirect_handler(support_head=False)):
|
with http_server(make_redirect_handler(support_head=False)):
|
||||||
app.build()
|
app.build()
|
||||||
|
|
||||||
with open(app.outdir / 'output.json') as fp:
|
with open(app.outdir / 'output.json') as fp:
|
||||||
content = json.load(fp)
|
records = [json.loads(l) for l in fp.readlines()]
|
||||||
assert content == {
|
|
||||||
"code": 0,
|
assert len(records) == 2
|
||||||
"status": "working",
|
result = {r["uri"]: r["status"] for r in records}
|
||||||
"filename": "index.rst",
|
assert result["http://localhost:7777/path1"] == "working"
|
||||||
"lineno": 1,
|
assert result["http://localhost:7777/path2"] == "redirected"
|
||||||
"uri": "http://localhost:7777/",
|
assert warning.getvalue() == ''
|
||||||
"info": "",
|
|
||||||
}
|
|
||||||
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-warn-redirects',
|
||||||
|
freshenv=True, confoverrides={
|
||||||
|
'linkcheck_allowed_redirects': {'http://localhost:7777/.*1': '.*'},
|
||||||
|
'linkcheck_warn_redirects': True,
|
||||||
|
})
|
||||||
|
def test_linkcheck_allowed_redirects_and_linkcheck_warn_redirects(app, warning):
|
||||||
|
with http_server(make_redirect_handler(support_head=False)):
|
||||||
|
app.build()
|
||||||
|
|
||||||
|
with open(app.outdir / 'output.json') as fp:
|
||||||
|
records = [json.loads(l) for l in fp.readlines()]
|
||||||
|
|
||||||
|
assert len(records) == 2
|
||||||
|
result = {r["uri"]: r["status"] for r in records}
|
||||||
|
assert result["http://localhost:7777/path1"] == "working"
|
||||||
|
assert result["http://localhost:7777/path2"] == "redirected"
|
||||||
|
assert ("index.rst.rst:1: WARNING: redirect http://localhost:7777/path2 - with Found to "
|
||||||
|
"http://localhost:7777/?redirected=1\n" in strip_escseq(warning.getvalue()))
|
||||||
|
assert len(warning.getvalue().splitlines()) == 1
|
||||||
|
|
||||||
|
|
||||||
class OKHandler(http.server.BaseHTTPRequestHandler):
|
class OKHandler(http.server.BaseHTTPRequestHandler):
|
||||||
|
|||||||
Reference in New Issue
Block a user