Skip to content

Commit 6d1277e

Browse files
authored
add comparison check between MQTT channel data policy and wmo:dataPolicy (#138)
This reverts commit feee74e.
1 parent 93e1759 commit 6d1277e

File tree

3 files changed

+201
-1
lines changed

3 files changed

+201
-1
lines changed

pywcmp/wcmp2/ets.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,11 @@ def test_requirement_links(self):
506506
return status
507507

508508
if link['channel'].startswith(('origin/a/wis2', 'cache/a/wis2')): # noqa
509+
channel_tokens = link['channel'].split('/')
509510
try:
510-
centre_id = link['channel'].split('/')[3]
511+
LOGGER.debug('Validating centre-id in topic')
512+
centre_id = channel_tokens[3]
513+
511514
if (not centre_id.endswith('-test') and
512515
centre_id not in self.th.topics[3]):
513516
status['code'] = 'FAILED'
@@ -516,6 +519,19 @@ def test_requirement_links(self):
516519
except IndexError:
517520
LOGGER.debug('Topic has no centre-id')
518521

522+
try:
523+
LOGGER.debug('Validating data policy in channel with record properties.wmo:dataPolicy') # noqa
524+
notification_type = channel_tokens[4]
525+
if notification_type == 'data':
526+
channel_data_policy = channel_tokens[5]
527+
if channel_data_policy != self.record['properties']['wmo:dataPolicy']: # noqa
528+
status['code'] = 'FAILED'
529+
status['message'] = 'Inconsistent data policy in channel with wmo:dataPolicy' # noqa
530+
return status
531+
532+
except IndexError:
533+
LOGGER.debug('Topic has no data policy')
534+
519535
LOGGER.debug('Validating topic in link channel')
520536
if not self.th.validate(link['channel']):
521537
status['code'] = 'FAILED'
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"id": "urn:wmo:md:ca-eccc-msc:weather.observations.swob-realtime",
3+
"conformsTo": [
4+
"http://wis.wmo.int/spec/wcmp/2/conf/core"
5+
],
6+
"time": {
7+
"interval": [
8+
"2010-11-11T11:11:11Z",
9+
".."
10+
],
11+
"resolution": "PT1H"
12+
},
13+
"type": "Feature",
14+
"geometry": {
15+
"type": "Polygon",
16+
"coordinates": [
17+
[
18+
[
19+
-142,
20+
28
21+
],
22+
[
23+
-142,
24+
82
25+
],
26+
[
27+
-52,
28+
82
29+
],
30+
[
31+
-52,
32+
28
33+
],
34+
[
35+
-142,
36+
28
37+
]
38+
]
39+
]
40+
},
41+
"properties": {
42+
"title": "Surface weather observations",
43+
"description": "Surface Observations measured at the automatic and manual stations of the Environment and Climate Change Canada and partners networks, either for a single station, or for the stations of specific provinces and territories (last 30 days)",
44+
"themes": [
45+
{
46+
"concepts": [
47+
{
48+
"id": "Weather"
49+
},
50+
{
51+
"id": "Archives"
52+
},
53+
{
54+
"id": "Precipitation"
55+
},
56+
{
57+
"id": "Air temperature"
58+
},
59+
{
60+
"id": "Humidity"
61+
},
62+
{
63+
"id": "Snow"
64+
},
65+
{
66+
"id": "Wind"
67+
},
68+
{
69+
"id": "Meteorological data"
70+
}
71+
],
72+
"scheme": "https://library-archives.canada.ca/eng/services/government-canada/controlled-vocabularies-government-canada/pages/controlled-vocabularies-government-canada.aspx"
73+
},
74+
{
75+
"concepts": [
76+
{
77+
"id": "weather"
78+
}
79+
],
80+
"scheme": "https://codes.wmo.int/wis/topic-hierarchy/earth-system-discipline"
81+
}
82+
],
83+
"contacts": [
84+
{
85+
"organization": "Government of Canada; Environment and Climate Change Canada; Meteorological Service of Canada",
86+
"position": "National Inquiry Response Team",
87+
"phones": [
88+
{
89+
"value": "+18199972800"
90+
}
91+
],
92+
"emails": [
93+
{
94+
"value": "enviroinfo@ec.gc.ca"
95+
}
96+
],
97+
"addresses": [
98+
{
99+
"deliveryPoint": [
100+
"77 Westmorland Street, suite 260"
101+
],
102+
"city": "Fredericton",
103+
"administrativeArea": "NB",
104+
"postalCode": "E3B 6Z4",
105+
"country": "Canada"
106+
}
107+
],
108+
"links": [
109+
{
110+
"rel": "canonical",
111+
"type": "text/html",
112+
"href": "https://eccc-msc.github.io/open-data"
113+
}
114+
],
115+
"contactInstructions": "via email",
116+
"roles": [
117+
"host",
118+
"producer"
119+
]
120+
}
121+
],
122+
"type": "dataset",
123+
"created": "2018-01-01T11:11:11Z",
124+
"updated": "2022-06-22T12:42:46Z",
125+
"wmo:dataPolicy": "recommended"
126+
},
127+
"links": [
128+
{
129+
"rel": "stations",
130+
"href": "https://dd.weather.gc.ca/observations/doc/swob-xml_station_list.csv",
131+
"type": "text/csv",
132+
"title": "Stations associated with this dataset"
133+
},
134+
{
135+
"rel": "data",
136+
"href": "https://dd.weather.gc.ca/observations/swob-ml",
137+
"type": "text/html",
138+
"hreflang": "en",
139+
"title": "Raw data download (CSV files)"
140+
},
141+
{
142+
"rel": "items",
143+
"href": "https://api.weather.gc.ca/collections/swob-realtime/items",
144+
"type": "application/json",
145+
"title": "Data access API interface"
146+
},
147+
{
148+
"rel": "related",
149+
"href": "https://eccc-msc.github.io/open-data/msc-data/obs_station/readme_obs_insitu_swobdatamart_en",
150+
"type": "text/html",
151+
"title": "Documentation"
152+
},
153+
{
154+
"href": "https://eccc-msc.github.io/open-data/licence/readme_en",
155+
"type": "text/html",
156+
"rel": "license",
157+
"title": "Environment and Climate Change Canada Data Servers End-use Licence"
158+
},
159+
{
160+
"rel": "items",
161+
"href": "mqtt://example.org:8883",
162+
"channel": "origin/a/wis2/ca-eccc-msc/data/core/weather/experimental/surface-based-observations/synop",
163+
"type": "application/json",
164+
"title": "Data notifications"
165+
}
166+
]
167+
}

tests/run_tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ def test_fail_invalid_link_channel_centre_id(self):
265265
self.assertEqual(codes.count('PASSED'), 11)
266266
self.assertEqual(codes.count('SKIPPED'), 0)
267267

268+
def test_fail_invalid_link_channel_data_policy(self):
269+
"""
270+
Simple tests for a failing record with a link channel data policy that
271+
does not match wmo:dataPolicy
272+
"""
273+
274+
with open(get_test_file_path('data/wcmp2-failing-invalid-link-channel-data-policy.json')) as fh: # noqa
275+
record = json.load(fh)
276+
ts = WMOCoreMetadataProfileTestSuite2(record)
277+
results = ts.run_tests()
278+
279+
codes = [r['code'] for r in results['tests']]
280+
281+
self.assertEqual(codes.count('FAILED'), 1)
282+
self.assertEqual(codes.count('PASSED'), 11)
283+
self.assertEqual(codes.count('SKIPPED'), 0)
284+
268285

269286
class WCMP2KPITest(unittest.TestCase):
270287
"""WCMP KPI tests of tests"""

0 commit comments

Comments
 (0)