Skip to content

Commit e22c6cf

Browse files
add test
1 parent d0f9602 commit e22c6cf

File tree

4 files changed

+75
-17
lines changed

4 files changed

+75
-17
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@
7979
"accent_color": "grass",
8080
}
8181
# -- Configure link checking behavior ----------------------------------------
82-
linkcheck_rate_limit_timeout = 15
82+
linkcheck_rate_limit_timeout = 15

exasol/toolbox/nox/_documentation.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import argparse
34
import json
45
import os
56
import re
@@ -8,18 +9,19 @@
89
import sys
910
import tempfile
1011
import webbrowser
12+
from collections.abc import (
13+
Container,
14+
Iterable,
15+
)
1116
from itertools import repeat
1217
from pathlib import Path
1318
from typing import (
14-
Container,
15-
Iterable,
1619
Optional,
1720
Tuple,
1821
)
19-
import argparse
2022

2123
import nox
22-
import requests # type: ignore
24+
import requests # type: ignore
2325
from nox import Session
2426

2527
from exasol.toolbox.nox._shared import DOCS_OUTPUT_DIR
@@ -58,10 +60,14 @@ def _check_failed_links(results: list[str]):
5860
match = re.search(r"https?://[^\s\"\'<>]+", data["uri"])
5961
if match:
6062
try:
61-
request = requests.head(match.group(), timeout=15)
63+
request = requests.get(match.group(), timeout=15)
6264
if request.status_code == 200:
6365
data["status"] = "working"
6466
data["code"] = request.status_code
67+
if request.history:
68+
data["info"] = (
69+
f"redirected: {" -> ".join(step.url for step in request.history)} -> {request.url}"
70+
)
6571
results[line] = json.dumps(data)
6672
except requests.exceptions.Timeout:
6773
pass

poetry.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/unit/documentation_test.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from unittest.mock import (
2+
MagicMock,
3+
patch,
4+
)
5+
6+
import pytest
7+
8+
from exasol.toolbox.nox._documentation import _check_failed_links
9+
10+
11+
@pytest.mark.parametrize(
12+
"results, expected",
13+
[
14+
([""], ([""], [])),
15+
(
16+
[
17+
'{"filename": "ftest.rst", "lineno": 1, "status": "broken", "code": 0, "uri": "https://ftest", "info": ""}',
18+
'{"filename": "ttest.rst", "lineno": 1, "status": "working", "code": 0, "uri": "https://ttest", "info": ""}',
19+
'{"filename": "rtest.rst", "lineno": 1, "status": "redirected", "code": 0, "uri": "https://rtest", "info": ""}',
20+
],
21+
(
22+
[
23+
'{"filename": "ftest.rst", "lineno": 1, "status": "broken", "code": 0, "uri": "https://ftest", "info": ""}',
24+
'{"filename": "ttest.rst", "lineno": 1, "status": "working", "code": 0, "uri": "https://ttest", "info": ""}',
25+
'{"filename": "rtest.rst", "lineno": 1, "status": "redirected", "code": 0, "uri": "https://rtest", "info": ""}',
26+
],
27+
[
28+
'{"filename": "ftest.rst", "lineno": 1, "status": "broken", "code": 0, '
29+
'"uri": "https://ftest", "info": ""}'
30+
],
31+
),
32+
),
33+
],
34+
)
35+
def test_failed_links(results, expected):
36+
frequest = MagicMock()
37+
frequest.status_code = 404
38+
trequest = MagicMock()
39+
trequest.status_code = 200
40+
history1 = MagicMock()
41+
history1.url = "https://rtest"
42+
history2 = MagicMock()
43+
history2.url = "https://rtest.next"
44+
rrequest = MagicMock()
45+
rrequest.history = [history1, history2]
46+
rrequest.url = "https://rtest.end"
47+
with patch(
48+
"exasol.toolbox.nox._documentation.requests.get",
49+
side_effect=[frequest, rrequest],
50+
):
51+
actual = _check_failed_links(results)
52+
assert actual == expected

0 commit comments

Comments
 (0)