Skip to content

Commit eb73cc0

Browse files
committed
remove JSON Schema validation in lieu of ETS
1 parent d806c24 commit eb73cc0

File tree

5 files changed

+27
-111
lines changed

5 files changed

+27
-111
lines changed

pywis_pubsub/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from pywis_pubsub.publish import publish
2929
from pywis_pubsub.schema import schema
3030
from pywis_pubsub.subscribe import subscribe
31-
from pywis_pubsub.validation import validate_
3231
from pywis_pubsub.verification import verify
3332

3433

@@ -47,7 +46,6 @@ def message():
4746
pass
4847

4948

50-
message.add_command(validate_)
5149
message.add_command(verify)
5250

5351
cli.add_command(message)

pywis_pubsub/publish.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from pywis_pubsub import util
3636
from pywis_pubsub.message import LINK_TYPES
3737
from pywis_pubsub.mqtt import MQTTPubSubClient
38-
from pywis_pubsub.validation import validate_
38+
from pywis_pubsub.ets import validate
3939

4040

4141
LOGGER = logging.getLogger(__name__)
@@ -248,7 +248,7 @@ def publish(ctx, file_, config, url, topic, datetime_, identifier,
248248

249249
if file_ is not None:
250250
if config.get('validate_message', False):
251-
ctx.invoke(validate_, message=file_)
251+
ctx.invoke(validate, message=file_)
252252
file_.seek(0)
253253
message = json.load(file_)
254254
else:

pywis_pubsub/subscribe.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
from pywis_pubsub import cli_options
3030
from pywis_pubsub import util
31+
from pywis_pubsub.ets import WNMTestSuite
3132
from pywis_pubsub.geometry import is_message_within_bbox
3233
from pywis_pubsub.hook import load_hook
3334
from pywis_pubsub.message import get_link, get_data
3435
from pywis_pubsub.mqtt import MQTTPubSubClient
3536
from pywis_pubsub.storage import STORAGES
36-
from pywis_pubsub.validation import validate_message
3737
from pywis_pubsub.verification import data_verified
3838

3939

@@ -51,11 +51,11 @@ def on_message_handler(client, userdata, msg):
5151
try:
5252
if userdata.get('validate_message', False):
5353
LOGGER.debug('Validating message')
54-
success, err = validate_message(msg_dict)
55-
if not success:
56-
LOGGER.error(f'Message is not a valid notification: {err}')
57-
return
58-
except RuntimeError as err:
54+
55+
ts = WNMTestSuite(msg_dict)
56+
_ = ts.run_tests(fail_on_schema_validation=True)
57+
58+
except Exception as err:
5959
LOGGER.error(f'Cannot validate message: {err}')
6060
return
6161

pywis_pubsub/validation.py

-82
This file was deleted.

tests/run_tests.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from requests import Session
2828
from pywis_pubsub.ets import WNMTestSuite
2929
from pywis_pubsub.kpi import calculate_grade, WNMKeyPerformanceIndicators
30-
from pywis_pubsub.validation import validate_message
3130
from pywis_pubsub.verification import verify_data
3231

3332
TESTDATA_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -54,24 +53,6 @@ def tearDown(self):
5453
"""return to pristine state"""
5554
pass
5655

57-
def test_validation(self):
58-
"""Test validation"""
59-
60-
with open(get_abspath('test_valid.json')) as fh:
61-
data = json.load(fh)
62-
is_valid, errors = validate_message(data)
63-
self.assertTrue(is_valid)
64-
65-
with open(get_abspath('test_invalid.json')) as fh:
66-
data = json.load(fh)
67-
is_valid, errors = validate_message(data)
68-
self.assertFalse(is_valid)
69-
70-
with open(get_abspath('test_malformed.json')) as fh:
71-
with self.assertRaises(json.decoder.JSONDecodeError):
72-
data = json.load(fh)
73-
is_valid, errors = validate_message(data)
74-
7556
@patch.object(Session, 'get')
7657
def test_verification(self, mock_get):
7758
"""Test verification"""
@@ -127,6 +108,25 @@ def test_fail(self):
127108
with self.assertRaises(ValueError):
128109
ts.run_tests(fail_on_schema_validation=True)
129110

111+
with self.assertRaises(ValueError):
112+
with open(get_abspath('test_invalid.json')) as fh:
113+
record = json.load(fh)
114+
ts = WNMTestSuite(record)
115+
results = ts.run_tests(fail_on_schema_validation=True)
116+
117+
codes = [r['code'] for r in results['ets-report']['tests']]
118+
119+
print(codes)
120+
self.assertEqual(codes.count('FAILED'), 1)
121+
self.assertEqual(codes.count('PASSED'), 6)
122+
self.assertEqual(codes.count('SKIPPED'), 0)
123+
124+
with self.assertRaises(json.decoder.JSONDecodeError):
125+
with open(get_abspath('test_malformed.json')) as fh:
126+
record = json.load(fh)
127+
ts = WNMTestSuite(record)
128+
results = ts.run_tests()
129+
130130

131131
class WNMKPITest(unittest.TestCase):
132132
"""WNM KPI tests of tests"""

0 commit comments

Comments
 (0)