Skip to content

Commit

Permalink
Update Validate API and run black
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HadleyKing committed Aug 9, 2022
1 parent ab1e0cc commit ec19be0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion bco_api/api/scripts/utilities/DbUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from django.utils import timezone



class DbUtils:
"""Class Description
-----------------
Expand Down
21 changes: 20 additions & 1 deletion bco_api/api/scripts/utilities/JsonUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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")
Expand All @@ -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] = {
Expand Down

0 comments on commit ec19be0

Please sign in to comment.