Skip to content

Commit e181af6

Browse files
committed
add a KPI contacts check for ISO 3166 alpha-3 country (#140)
1 parent b09fde7 commit e181af6

18 files changed

+38
-19
lines changed

pywcmp/resources/example-ca-eccc-msc.nwp-gdps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"city": "Fredericton",
9898
"administrativeArea": "NB",
9999
"postalCode": "E3B 6Z4",
100-
"country": "Canada"
100+
"country": "CAN"
101101
}
102102
],
103103
"contactInstructions": "email",

pywcmp/wcmp2/kpi.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Authors: Tom Kralidis <tomkralidis@gmail.com>
44
#
5-
# Copyright (c) 2024 Tom Kralidis
5+
# Copyright (c) 2025 Tom Kralidis
66
#
77
# Licensed to the Apache Software Foundation (ASF) under one
88
# or more contributor license agreements. See the NOTICE file
@@ -31,6 +31,7 @@
3131
import uuid
3232

3333
from bs4 import BeautifulSoup
34+
import pycountry
3435

3536
import pywcmp
3637
from pywcmp.util import (check_spelling, check_url,
@@ -414,8 +415,10 @@ def kpi_contacts(self) -> tuple:
414415

415416
host_contact = None
416417
email_found = False
418+
countries = []
419+
valid_countries = True
417420

418-
total = 3
421+
total = 4
419422
score = 0
420423
comments = []
421424

@@ -428,6 +431,21 @@ def kpi_contacts(self) -> tuple:
428431
if 'host' in contact['roles']:
429432
host_contact = contact
430433

434+
for address in contact.get('addresses', []):
435+
if address.get('country') is not None:
436+
countries.append(address['country'])
437+
438+
if countries:
439+
for country in countries:
440+
if pycountry.countries.get(alpha_3=country) is None:
441+
valid_countries = False
442+
break
443+
444+
if not valid_countries:
445+
comments.append('countries should be ISO 3166-1 alpha-3')
446+
else:
447+
score += 1
448+
431449
if host_contact is None:
432450
comments.append('No host contact found')
433451
else:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
beautifulsoup4
22
click
33
jsonschema
4+
pycountry
45
pyspellchecker
56
pywis-topics
67
rfc3339-validator

tests/data/wcmp2-failing-created-none.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

tests/data/wcmp2-failing-invalid-centre-id.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

tests/data/wcmp2-failing-invalid-geometry-range.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

tests/data/wcmp2-failing-invalid-identifier-empty.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

tests/data/wcmp2-failing-invalid-identifier-space.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

tests/data/wcmp2-failing-invalid-link-channel-centre-id.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

tests/data/wcmp2-failing-invalid-link-channel-data-policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"city": "Fredericton",
103103
"administrativeArea": "NB",
104104
"postalCode": "E3B 6Z4",
105-
"country": "Canada"
105+
"country": "CAN"
106106
}
107107
],
108108
"links": [

0 commit comments

Comments
 (0)