diff options
author | efiacor <fiachra.corcoran@est.tech> | 2020-05-06 01:14:00 +0100 |
---|---|---|
committer | efiacor <fiachra.corcoran@est.tech> | 2020-05-12 13:37:28 +0100 |
commit | 125390ba301915c0829ad4c0b7eff0c935b6956c (patch) | |
tree | c49de4f058ebb4ce93fe90b72816246db7c938e4 /tests/usecases-5G-bulkpm/5G-bulkpm/resources/JsonValidatorLibrary.py | |
parent | 9c41697bdcef2eddd9af6436f3feb5821c238b44 (diff) |
Seperating usecase test suite dependencies
# Refactoring BulkPM Dataplane test suite
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: I4b2ad0dc5147e10ffc55f4ec210a29f073cd865b
Issue-ID: INT-832
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Diffstat (limited to 'tests/usecases-5G-bulkpm/5G-bulkpm/resources/JsonValidatorLibrary.py')
-rw-r--r-- | tests/usecases-5G-bulkpm/5G-bulkpm/resources/JsonValidatorLibrary.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/usecases-5G-bulkpm/5G-bulkpm/resources/JsonValidatorLibrary.py b/tests/usecases-5G-bulkpm/5G-bulkpm/resources/JsonValidatorLibrary.py new file mode 100644 index 00000000..ed376ff2 --- /dev/null +++ b/tests/usecases-5G-bulkpm/5G-bulkpm/resources/JsonValidatorLibrary.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +import logging + +from jsonschema import validate, ValidationError, SchemaError +from simplejson import load + + +class JsonValidatorLibrary(object): + + def __init__(self): + pass + + @staticmethod + def validate(schema_path, json_path): + logging.info("Schema path: " + schema_path) + logging.info("JSON path: " + json_path) + schema = None + data = None + try: + schema = load(open(schema_path, 'r')) + data = load(open(json_path, 'r')) + except (IOError, ValueError, OSError) as e: + logging.error(e.message) + return 1 + + try: + validate(data, schema) + except (ValidationError, SchemaError) as e: + logging.error(e.message) + return 1 + + # logger.log("JSON validation successful") + print("JSON validation successful") + return 0 + + +if __name__ == '__main__': + lib = JsonValidatorLibrary() +# sys.exit(JsonValidatorLibrary().validate(sys.argv[1], sys.argv[2])) |