Skip to content

Commit d02c1dd

Browse files
committed
Bugifx and tests for external_need handling
* Calculated link gets .html file extension after docname * Tests are updated to really check data Fixes #137
1 parent 1829027 commit d02c1dd

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

sphinxcontrib/needs/api/need.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,6 @@ def add_external_need(
441441
kwargs["external_css"] = external_css
442442

443443
return add_need(app=app, **kwargs)
444-
# need_type=need_type, title=title, id=id,
445-
# content=content, status=status, tags=tags, links_string=links_string,
446-
# is_external=True, external_url=external_url, external_css=external_css)
447444

448445

449446
def _prepare_template(app, needs_info, template_key):

sphinxcontrib/needs/external_needs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
def load_external_needs(app, env, _docname):
1414
for source in app.config.needs_external_needs:
15+
if source["base_url"].endswith("/"):
16+
source["base_url"] = source["base_url"][:-1]
17+
1518
log.info(f'Loading external needs from {source["json_url"]}')
1619

1720
s = requests.Session()
@@ -53,7 +56,7 @@ def load_external_needs(app, env, _docname):
5356
need_params["need_type"] = need["type"]
5457
need_params["id"] = f'{prefix}{need["id"]}'
5558
need_params["external_css"] = source.get("css_class", None)
56-
need_params["external_url"] = f'{source["base_url"]}/{need.get("docname", "__error__")}#{need["id"]}'
59+
need_params["external_url"] = f'{source["base_url"]}/{need.get("docname", "__error__")}.html#{need["id"]}'
5760
need_params["content"] = need["description"]
5861
need_params["links"] = need.get("links", [])
5962
need_params["tags"] = ",".join(need.get("tags", []))

sphinxcontrib/needs/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
# "parent_needs",
4646
"parent_need",
4747
# "child_needs",
48+
"is_external",
49+
"external_css",
4850
]
4951

5052

tests/doc_test/external_doc/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
test_json = os.path.join(test_dir, "needs_test_small.json")
4747
# test_json = os.path.join(test_dir, 'needs_test_invalid.json')
4848

49-
needs_external_needs = [{"base_url": f"file://{test_dir}", "json_url": f"file://{test_json}", "id_prefix": "ext_"}]
49+
# needs_external_needs = [{"base_url": f"file://{test_dir}", "json_url": f"file://{test_json}", "id_prefix": "ext_"}]
50+
needs_external_needs = [
51+
{"base_url": "http://my_company.com/docs/v1/", "json_url": f"file://{test_json}", "id_prefix": "ext_"}
52+
]
5053

5154
plantuml = "java -jar %s" % os.path.join(os.path.dirname(__file__), "..", "utils", "plantuml.1.2021.5.jar")
5255
plantuml_output_format = "svg"

tests/test_external.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from pathlib import Path
23

34
from sphinx_testing import with_app
@@ -6,10 +7,19 @@
67
@with_app(buildername="html", srcdir="doc_test/external_doc") # , warningiserror=True)
78
def test_external_html(app, status, warning):
89
app.build()
9-
Path(app.outdir, "index.html").read_text()
10+
html = Path(app.outdir, "index.html").read_text()
11+
assert (
12+
'<a class="external_link reference external" href="http://my_company.com/docs/v1/index.html#TEST_02">'
13+
"EXT_TEST_02</a>" in html
14+
)
1015

1116

1217
@with_app(buildername="needs", srcdir="doc_test/external_doc") # , warningiserror=True)
1318
def test_external_json(app, status, warning):
1419
app.build()
15-
Path(app.outdir, "needs.json").read_text()
20+
json_data = Path(app.outdir, "needs.json").read_text()
21+
needs = json.loads(json_data)
22+
external_need = needs["versions"]["1.0"]["needs"]["EXT_TEST_01"]
23+
assert external_need["external_url"] == "http://my_company.com/docs/v1/index.html#TEST_01"
24+
assert external_need["external_css"] == "external_link"
25+
assert external_need["is_external"] is True

0 commit comments

Comments
 (0)