From ec19be0de5d743af19ff3b2f761a4850a6a26f7f Mon Sep 17 00:00:00 2001 From: Hadley King Date: Tue, 9 Aug 2022 16:40:40 -0400 Subject: [PATCH] Update Validate API and run black Update Validate API for malformed `extension_domain` Ran black linter on other files. Changes to be committed: modified: api/scripts/method_specific/POST_api_objects_drafts_create.py modified: api/scripts/method_specific/POST_api_objects_drafts_modify.py modified: api/scripts/utilities/DbUtils.py modified: api/scripts/utilities/JsonUtils.py --- .../POST_api_objects_drafts_create.py | 4 +++- .../POST_api_objects_drafts_modify.py | 6 +++--- bco_api/api/scripts/utilities/DbUtils.py | 1 - bco_api/api/scripts/utilities/JsonUtils.py | 21 ++++++++++++++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/bco_api/api/scripts/method_specific/POST_api_objects_drafts_create.py b/bco_api/api/scripts/method_specific/POST_api_objects_drafts_create.py index df95e68a..d9aec941 100755 --- a/bco_api/api/scripts/method_specific/POST_api_objects_drafts_create.py +++ b/bco_api/api/scripts/method_specific/POST_api_objects_drafts_create.py @@ -138,7 +138,9 @@ def post_api_objects_drafts_create(request): prefix_counter.save() # Update the request status. returning.append( - db_utils.messages(parameters={"object_id": creation_object['object_id']})["201_create"] + db_utils.messages( + parameters={"object_id": creation_object["object_id"]} + )["201_create"] ) else: diff --git a/bco_api/api/scripts/method_specific/POST_api_objects_drafts_modify.py b/bco_api/api/scripts/method_specific/POST_api_objects_drafts_modify.py index 10730462..f93c57de 100755 --- a/bco_api/api/scripts/method_specific/POST_api_objects_drafts_modify.py +++ b/bco_api/api/scripts/method_specific/POST_api_objects_drafts_modify.py @@ -70,13 +70,13 @@ def post_api_objects_drafts_modify(request): # group that has object-level change permissions. # To check these options, we need the actual object. - if draft_object['object_id'] != draft_object["contents"]["object_id"]: + if draft_object["object_id"] != draft_object["contents"]["object_id"]: returning.append( db_utils.messages( parameters={ "object_id": draft_object["contents"]["object_id"], - "draft_object_id": draft_object["object_id"] - } + "draft_object_id": draft_object["object_id"], + } )["409_draft_object_id_conflict"] ) any_failed = True diff --git a/bco_api/api/scripts/utilities/DbUtils.py b/bco_api/api/scripts/utilities/DbUtils.py index 7a4a82c2..f9ef0a01 100755 --- a/bco_api/api/scripts/utilities/DbUtils.py +++ b/bco_api/api/scripts/utilities/DbUtils.py @@ -19,7 +19,6 @@ from django.utils import timezone - class DbUtils: """Class Description ----------------- diff --git a/bco_api/api/scripts/utilities/JsonUtils.py b/bco_api/api/scripts/utilities/JsonUtils.py index a8dad1d4..6e257792 100755 --- a/bco_api/api/scripts/utilities/JsonUtils.py +++ b/bco_api/api/scripts/utilities/JsonUtils.py @@ -58,7 +58,6 @@ def validate(schema, json_object, results): results : dict A dictionary that is used to collect the validation results. """ - if "object_id" in json_object: identifier = json_object["object_id"] @@ -99,6 +98,18 @@ def parse_bco(bco, results): results[identifier] = {"number_of_errors": 0, "error_detail": []} try: spec_version = get_schema(bco["spec_version"]) + + except AttributeError: + file_path = os.path.dirname( + os.path.abspath("api/validation_definitions/IEEE/2791object.json") + ) + + ieee = "api/validation_definitions/IEEE/2791object.json" + with open(ieee, "r", encoding="utf-8") as file: + spec_version = jsonref.load( + file, base_uri=f"file://{file_path}/", jsonschema=True + ) + except ErrorConnecting: file_path = os.path.dirname( os.path.abspath("api/validation_definitions/IEEE/2791object.json") @@ -109,8 +120,16 @@ def parse_bco(bco, results): spec_version = jsonref.load( file, base_uri=f"file://{file_path}/", jsonschema=True ) + results = validate(spec_version, bco, results) if "extension_domain" in bco.keys(): + if bco["extension_domain"] is not list: + results[identifier]["extension_domain"] = { + "number_of_errors": 1, + "error_detail": ["extension_doamin invalid"], + } + + return results for extension in bco["extension_domain"]: extension_id = extension["extension_schema"] results[identifier][extension_id] = {