add process model file delete api

This commit is contained in:
burnettk 2022-09-11 22:26:21 -04:00
parent 76ae0a3dcf
commit 191faf2a17
3 changed files with 97 additions and 14 deletions

View File

@ -204,7 +204,7 @@ paths:
tags:
- Process Groups
responses:
"204":
"200":
description: The process group was deleted.
put:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_group_update
@ -299,7 +299,7 @@ paths:
operationId: spiffworkflow_backend.routes.process_api_blueprint.add_file
summary: Add a new workflow spec file
tags:
- Spec Files
- Process Model Files
requestBody:
content:
multipart/form-data:
@ -320,7 +320,7 @@ paths:
# operationId: spiffworkflow_backend.api.process_api_blueprint.get_files
# summary: Provide a list of workflow spec files for the given workflow_spec_id. IMPORTANT, only includes metadata, not the file content.
# tags:
# - Spec Files
# - Process Model Files
# responses:
# '200':
# description: An array of file descriptions (not the file content)
@ -366,7 +366,7 @@ paths:
- Process Models
responses:
"200":
description: The workflow specification has been removed.
description: The process model has been removed.
content:
application/json:
schema:
@ -743,7 +743,7 @@ paths:
operationId: spiffworkflow_backend.routes.process_api_blueprint.get_file
summary: Returns metadata about the file
tags:
- Spec Files
- Process Model Files
responses:
"200":
description: Returns the file information requested.
@ -756,7 +756,7 @@ paths:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_file_update
summary: save the contents to the given file
tags:
- Spec Files
- Process Model Files
requestBody:
description: Log Pagination Request
required: false
@ -775,14 +775,18 @@ paths:
application/json:
schema:
$ref: "#components/schemas/OkTrue"
# delete:
# operationId: crc.api.spec_file.delete
# summary: Removes an existing workflow spec file.
# tags:
# - Spec Files
# responses:
# '204':
# description: The file was removed.
delete:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_file_delete
summary: Removes an existing process model file
tags:
- Process Model Files
responses:
"200":
description: The process model has been removed.
content:
application/json:
schema:
$ref: "#components/schemas/OkTrue"
/tasks:
parameters:

View File

@ -256,6 +256,25 @@ def process_model_file_update(
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
def process_model_file_delete(
process_group_id: str, process_model_id: str, file_name: str
) -> flask.wrappers.Response:
"""Process_model_file_delete."""
process_model = get_process_model(process_model_id, process_group_id)
try:
SpecFileService.delete_file(process_model, file_name)
except FileNotFoundError as exception:
raise (
ApiError(
code="process_model_file_cannot_be_found",
message=f"Process model file cannot be found: {file_name}",
status_code=400,
)
) from exception
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
def add_file(process_group_id: str, process_model_id: str) -> flask.wrappers.Response:
"""Add_file."""
process_model_service = ProcessModelService()

View File

@ -446,6 +446,66 @@ class TestProcessApi(BaseTest):
assert original_file != updated_file
assert updated_file["file_contents"] == new_file_contents.decode()
def test_process_model_file_delete_when_bad_process_model(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
) -> None:
"""Test_process_model_file_update."""
self.create_spec_file(client)
spec = load_test_spec("random_fact")
user = self.find_or_create_user()
response = client.delete(
f"/v1.0/process-models/INCORRECT-NON-EXISTENT-GROUP/{spec.id}/file/random_fact.svg",
follow_redirects=True,
headers=logged_in_headers(user),
)
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "process_model_cannot_be_found"
def test_process_model_file_delete_when_bad_file(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
) -> None:
"""Test_process_model_file_update."""
self.create_spec_file(client)
spec = load_test_spec("random_fact")
user = self.find_or_create_user()
response = client.delete(
f"/v1.0/process-models/{spec.process_group_id}/{spec.id}/file/random_fact_DOES_NOT_EXIST.svg",
follow_redirects=True,
headers=logged_in_headers(user),
)
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "process_model_file_cannot_be_found"
def test_process_model_file_delete(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
) -> None:
"""Test_process_model_file_update."""
self.create_spec_file(client)
spec = load_test_spec("random_fact")
user = self.find_or_create_user()
response = client.delete(
f"/v1.0/process-models/{spec.process_group_id}/{spec.id}/file/random_fact.svg",
follow_redirects=True,
headers=logged_in_headers(user),
)
assert response.status_code == 200
assert response.json is not None
assert response.json["ok"]
response = client.get(
f"/v1.0/process-models/{spec.process_group_id}/{spec.id}/file/random_fact.svg",
headers=logged_in_headers(user),
)
assert response.status_code == 404
def test_get_file(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
) -> None: