Skip to content

Commit

Permalink
Fix URLs in HTML test report
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Mar 22, 2024
1 parent 460d205 commit c150183
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
print(f"Writing full validation report to {test_outputs_path / 'report.html'}", file=sys.stderr)
if base_url:
full_validation_report_url = f"{base_url}{os.path.relpath(Path(test_outputs_path).resolve(), cwd)}/report.html"
report_to_html(json_reports=validation_reports, report_fn=test_outputs_path / 'report.html')
report_to_html(json_reports=validation_reports,
report_fn=test_outputs_path / 'report.html',
base_url=base_url)

if output_file and (not steps or 'register' in steps):

Expand Down
6 changes: 3 additions & 3 deletions ogc/bblocks/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from mako import exceptions as mako_exceptions, template as mako_template
import requests
from jsonschema.validators import validator_for
from ogc.na.annotate_schema import SchemaResolver
from ogc.na.util import load_yaml, is_url, copy_triples
from pyparsing import ParseBaseException
from rdflib import Graph
Expand Down Expand Up @@ -175,7 +174,7 @@ def report_to_dict(bblock: BuildingBlock,
if item.source.filename:
source['filename'] = str(os.path.relpath(item.source.filename, cwd))
if base_url:
source['filename'] = urljoin(base_url, source['filename'])
source['url'] = urljoin(base_url, source['filename'])
if item.source.example_index:
source['exampleIndex'] = item.source.example_index
if item.source.snippet_index:
Expand Down Expand Up @@ -236,6 +235,7 @@ def report_to_dict(bblock: BuildingBlock,


def report_to_html(json_reports: list[dict],
base_url: str | None = None,
report_fn: Path | None = None) -> str | None:

pass_count = sum(r['result'] for r in json_reports)
Expand All @@ -246,7 +246,7 @@ def report_to_html(json_reports: list[dict],
}
template = mako_template.Template(filename=str(Path(__file__).parent / 'validation/report.html.mako'))
try:
result = template.render(reports=json_reports, counts=counts)
result = template.render(reports=json_reports, counts=counts, report_fn=report_fn, base_url=base_url)
except:
raise ValueError(mako_exceptions.text_error_template().render())

Expand Down
16 changes: 14 additions & 2 deletions ogc/bblocks/validation/report.html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from html import escape as e
from datetime import datetime, timezone
from urllib.parse import urlparse, urljoin
from os.path import basename
from os.path import basename, relpath
from pathlib import Path
from ogc.na.util import is_url
import re
Expand All @@ -16,6 +16,18 @@ def get_uid():
last_uid = f"uid-{globals()['uid']}"
return last_uid
get_filename = lambda s: basename(urlparse(s).path)
%>
<%
def get_source_url(source):
if source.get('sourceUrl'):
return source['sourceUrl']
source_fn = source['filename']
if is_url(source_fn) or not report_fn:
return source_fn
if report_fn:
return os.path.relpath(source_fn, report_fn.resolve().parent)
return source.get('url', source_fn)
%>
<!doctype html>
<html>
Expand Down Expand Up @@ -114,7 +126,7 @@ get_filename = lambda s: basename(urlparse(s).path)
<i class="bi bi-caret-right-fill caret"></i>
Details
</button>
<a href="${e(item['source']['filename'])}" target="_blank">${e(re.sub(r'.*/', '', item['source']['filename']))}</a>
<a href="${e(get_source_url(item['source']))}" target="_blank">${e(re.sub(r'.*/', '', item['source']['filename']))}</a>
<span class="badge bg-secondary ${e(item['source']['type'].lower())}">${e(item['source']['type'].replace('_', ' ').capitalize())}</span>
% if item['source']['requireFail']:
<span class="badge text-bg-info">Requires fail</span>
Expand Down

0 comments on commit c150183

Please sign in to comment.