Skip to content

Commit

Permalink
streamline logic for KPI link type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Jun 13, 2024
1 parent c2eebe0 commit bed95a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions pywcmp/wcmp2/kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def kpi_links_health(self) -> tuple:
valid_link_mime_types = list(mimetypes.types_map.values())
valid_link_mime_types.extend([
'application/x-bufr',
'application/x-grib'
'application/x-grib',
'text/turtle'
])

LOGGER.info(f'Running {name}')
Expand Down Expand Up @@ -370,11 +371,17 @@ def kpi_links_health(self) -> tuple:
comments.append(f"URL not accessible: {link['href']}")

LOGGER.debug('Checking whether link has a valid media type')
if (link.get('type') is not None and
link['type'] not in valid_link_mime_types):
comments.append(f"invalid link type {link['type']}")
else:
score += 1
link_type = link.get('type')

if link_type is None:
LOGGER.debug('Deriving link type from HTTP Content-Type')
link_type = result.get('mime-type')

if link_type is not None:
if link_type in valid_link_mime_types:
score += 1
else:
comments.append(f"invalid link type {link_type}")

return name, total, score, comments

Expand Down
2 changes: 1 addition & 1 deletion tests/data/wcmp2-passing.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"id": "weather"
}
],
"scheme": "https://github.com/wmo-im/wis2-topic-hierarchy/blob/main/topic-hierarchy/earth-system-discipline/index.csv"
"scheme": "https://codes.wmo.int/wis/topic-hierarchy/earth-system-discipline"
}
],
"contacts": [
Expand Down

0 comments on commit bed95a1

Please sign in to comment.