From 191faf2a1791ff8ec38f24f368d238518b072317 Mon Sep 17 00:00:00 2001 From: burnettk Date: Sun, 11 Sep 2022 22:26:21 -0400 Subject: [PATCH] add process model file delete api --- src/spiffworkflow_backend/api.yml | 32 +++++----- .../routes/process_api_blueprint.py | 19 ++++++ .../integration/test_process_api.py | 60 +++++++++++++++++++ 3 files changed, 97 insertions(+), 14 deletions(-) diff --git a/src/spiffworkflow_backend/api.yml b/src/spiffworkflow_backend/api.yml index da38ce11..0e7b7380 100755 --- a/src/spiffworkflow_backend/api.yml +++ b/src/spiffworkflow_backend/api.yml @@ -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: diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index 73244c66..561c5436 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -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() diff --git a/tests/spiffworkflow_backend/integration/test_process_api.py b/tests/spiffworkflow_backend/integration/test_process_api.py index 6abce936..417e7efc 100644 --- a/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/tests/spiffworkflow_backend/integration/test_process_api.py @@ -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: