Skip to content

Commit

Permalink
add status code to error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 13, 2023
1 parent 5944c1a commit 2e3482c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/ap/ap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_all_aps_of_project(
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/ap/{project_iri}"
response = requests.get(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
aps: list[dict[str, Any]] = response.json()["administrative_permissions"]
ap_objects = [create_ap_from_admin_route_object(ap) for ap in aps]
return ap_objects
Expand Down
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/ap/ap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _delete_single_ap(
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/{ap_iri}"
response = requests.delete(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
logger.info(f"Deleted Administrative Permission {ap.iri} on host {host}")


Expand All @@ -52,7 +52,7 @@ def _update_ap(
url = f"{protocol}://{host}/admin/permissions/{iri}/hasPermissions"
payload = {"hasPermissions": create_admin_route_object_from_ap(ap)["hasPermissions"]}
response = requests.put(url, headers=headers, json=payload, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
ap_updated: dict[str, Any] = response.json()["administrative_permission"]
ap_object_updated = create_ap_from_admin_route_object(ap_updated)
return ap_object_updated
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/doap/doap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_all_doaps_of_project(
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/doap/{project_iri}"
response = requests.get(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
doaps: list[dict[str, Any]] = response.json()["default_object_access_permissions"]
doap_objects = [create_doap_from_admin_route_response(doap) for doap in doaps]
return doap_objects
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _update_doap_scope(
url = f"{protocol}://{host}/admin/permissions/{iri}/hasPermissions"
payload = {"hasPermissions": create_admin_route_object_from_scope(scope)}
response = requests.put(url, headers=headers, json=payload, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
new_doap = create_doap_from_admin_route_response(response.json()["default_object_access_permission"])
return new_doap

Expand Down
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/oap/oap_get_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_resource(
url = f"{protocol}://{host}/v2/resources/{iri}"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
data: dict[str, Any] = response.json()
return data

Expand Down Expand Up @@ -143,7 +143,7 @@ def _update_permissions_for_resource(
url = f"{protocol}://{host}/v2/resources"
headers = {"Authorization": f"Bearer {token}"}
response = requests.put(url, headers=headers, json=payload, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
logger.info(f"Updated permissions of resource {resource_iri}")


Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _get_token(host: str, email: str, pw: str) -> str:
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/authentication"
response = requests.post(url, json={"email": email, "password": pw}, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
token: str = response.json()["token"]
return token

Expand Down
8 changes: 4 additions & 4 deletions dsp_permissions_scripts/utils/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_onto_iris_of_project(
url = f"{protocol}://{host}/v2/ontologies/metadata"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
all_ontologies = response.json().get("@graph")
project_onto_iris = [o["@id"] for o in all_ontologies if o["knora-api:attachedToProject"]["@id"] == project_iri]
return project_onto_iris
Expand All @@ -58,7 +58,7 @@ def _get_class_iris_of_onto(
url = f"{protocol}://{host}/v2/ontologies/allentities/{quote_plus(onto_iri)}"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
all_entities = response.json()["@graph"]
context = response.json()["@context"]
class_ids = [c["@id"] for c in all_entities if c.get("knora-api:isResourceClass")]
Expand Down Expand Up @@ -113,7 +113,7 @@ def _get_next_page(
"""
url = f"{protocol}://{host}/v2/resources?resourceClass={quote_plus(resclass_iri)}&page={page}"
response = requests.get(url, headers=headers, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
result = response.json()
if "@graph" in result:
# result contains several resources: return them, then continue with next page
Expand All @@ -138,7 +138,7 @@ def get_project_iri_by_shortcode(shortcode: str, host: str) -> str:
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/projects/shortcode/{shortcode}"
response = requests.get(url, timeout=5)
assert response.status_code == 200, f"Error message from DSP-API: {response.text}"
assert response.status_code == 200, f"Status {response.status_code}. Error message from DSP-API: {response.text}"
iri: str = response.json()["project"]["id"]
return iri

Expand Down

0 comments on commit 2e3482c

Please sign in to comment.