Skip to content

Commit a97e5de

Browse files
committed
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
1 parent 3be9adb commit a97e5de

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

bco_api/api/scripts/method_specific/POST_api_objects_drafts_create.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def post_api_objects_drafts_create(request):
138138
prefix_counter.save()
139139
# Update the request status.
140140
returning.append(
141-
db_utils.messages(parameters={"object_id": creation_object['object_id']})["201_create"]
141+
db_utils.messages(
142+
parameters={"object_id": creation_object["object_id"]}
143+
)["201_create"]
142144
)
143145

144146
else:

bco_api/api/scripts/method_specific/POST_api_objects_drafts_modify.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ def post_api_objects_drafts_modify(request):
7070
# group that has object-level change permissions.
7171
# To check these options, we need the actual object.
7272

73-
if draft_object['object_id'] != draft_object["contents"]["object_id"]:
73+
if draft_object["object_id"] != draft_object["contents"]["object_id"]:
7474
returning.append(
7575
db_utils.messages(
7676
parameters={
7777
"object_id": draft_object["contents"]["object_id"],
78-
"draft_object_id": draft_object["object_id"]
79-
}
78+
"draft_object_id": draft_object["object_id"],
79+
}
8080
)["409_draft_object_id_conflict"]
8181
)
8282
any_failed = True

bco_api/api/scripts/utilities/DbUtils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from django.utils import timezone
2020

2121

22-
2322
class DbUtils:
2423
"""Class Description
2524
-----------------

bco_api/api/scripts/utilities/JsonUtils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def validate(schema, json_object, results):
5858
results : dict
5959
A dictionary that is used to collect the validation results.
6060
"""
61-
6261
if "object_id" in json_object:
6362
identifier = json_object["object_id"]
6463

@@ -99,6 +98,18 @@ def parse_bco(bco, results):
9998
results[identifier] = {"number_of_errors": 0, "error_detail": []}
10099
try:
101100
spec_version = get_schema(bco["spec_version"])
101+
102+
except AttributeError:
103+
file_path = os.path.dirname(
104+
os.path.abspath("api/validation_definitions/IEEE/2791object.json")
105+
)
106+
107+
ieee = "api/validation_definitions/IEEE/2791object.json"
108+
with open(ieee, "r", encoding="utf-8") as file:
109+
spec_version = jsonref.load(
110+
file, base_uri=f"file://{file_path}/", jsonschema=True
111+
)
112+
102113
except ErrorConnecting:
103114
file_path = os.path.dirname(
104115
os.path.abspath("api/validation_definitions/IEEE/2791object.json")
@@ -109,8 +120,16 @@ def parse_bco(bco, results):
109120
spec_version = jsonref.load(
110121
file, base_uri=f"file://{file_path}/", jsonschema=True
111122
)
123+
112124
results = validate(spec_version, bco, results)
113125
if "extension_domain" in bco.keys():
126+
if bco["extension_domain"] is not list:
127+
results[identifier]["extension_domain"] = {
128+
"number_of_errors": 1,
129+
"error_detail": ["extension_doamin invalid"],
130+
}
131+
132+
return results
114133
for extension in bco["extension_domain"]:
115134
extension_id = extension["extension_schema"]
116135
results[identifier][extension_id] = {

0 commit comments

Comments
 (0)