From 43eb0284ce626abd9f09534d49751342af127f5b Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Sun, 6 Nov 2022 14:23:16 -0500 Subject: [PATCH] Fix urls for uspend and resume endpoints --- .../src/spiffworkflow_backend/api.yml | 388 +----------------- .../routes/process_api_blueprint.py | 10 +- .../tests/data/manual_task/manual_task.bpmn | 41 ++ .../integration/test_process_api.py | 73 +++- 4 files changed, 123 insertions(+), 389 deletions(-) create mode 100644 spiffworkflow-backend/tests/data/manual_task/manual_task.bpmn diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 6bbe4eb1..31aae7fa 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -318,57 +318,6 @@ paths: schema: $ref: "#/components/schemas/File" - /process-models/{process_group_id}/{process_model_id}/files: - parameters: - - name: process_group_id - in: path - required: true - description: The group containing the models we want to return - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model to validate. - schema: - type: string - # add_file - post: - operationId: spiffworkflow_backend.routes.process_api_blueprint.add_file - summary: Add a new workflow spec file - tags: - - Process Model Files - requestBody: - content: - multipart/form-data: - schema: - type: object - properties: - file: - type: string - format: binary - responses: - "201": - description: Metadata about the uploaded file, but not the file content. - content: - application/json: - schema: - $ref: "#/components/schemas/File" - # get: - # 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: - # - Process Model Files - # responses: - # '200': - # description: An array of file descriptions (not the file content) - # content: - # application/json: - # schema: - # type: array - # items: - # $ref: "#/components/schemas/File" - /process-models/{modified_process_model_identifier}: parameters: - name: modified_process_model_identifier @@ -419,64 +368,6 @@ paths: schema: $ref: "#/components/schemas/OkTrue" - /process-models/{process_group_id}/{process_model_id}: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - # process_model_show - get: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_show - summary: Returns a single process model - tags: - - Process Models - responses: - "200": - description: Workflow spec. - content: - application/json: - schema: - $ref: "#/components/schemas/ProcessModel" - # process_model_delete - delete: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_delete - summary: Removes an existing process model - tags: - - Process Models - responses: - "200": - description: The process model has been removed. - content: - application/json: - schema: - $ref: "#/components/schemas/OkTrue" - put: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_update - summary: Modifies an existing process mosel with the given parameters. - tags: - - Process Models - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/ProcessModel" - responses: - "200": - description: Process model updated successfully. - content: - application/json: - schema: - $ref: "#/components/schemas/ProcessModel" - /process-instances: parameters: - name: process_group_identifier @@ -652,34 +543,6 @@ paths: schema: $ref: "#/components/schemas/Workflow" - /process-models/{process_group_id}/{process_model_id}/process-instances: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - # process_instance_create - post: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_create - summary: Creates an process instance from a process model and returns the instance - tags: - - Process Instances - responses: - "201": - description: Workflow generated successfully - content: - application/json: - schema: - $ref: "#/components/schemas/Workflow" - /process-instances/{process_instance_id}: parameters: - name: process_instance_id @@ -727,40 +590,6 @@ paths: application/json: schema: $ref: "#/components/schemas/Workflow" - - /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - - name: process_instance_id - in: path - required: true - description: The unique id of an existing process instance. - schema: - type: integer - get: - tags: - - Process Instances - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_show - summary: Show information about a process instance - responses: - "200": - description: One Process Instance - content: - application/json: - schema: - $ref: "#/components/schemas/Workflow" - # process_instance_delete delete: operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_delete summary: Deletes a single process instance @@ -802,46 +631,6 @@ paths: schema: $ref: "#/components/schemas/Workflow" - /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}/run: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - - name: process_instance_id - in: path - required: true - description: The unique id of an existing process instance. - schema: - type: integer - - name: do_engine_steps - in: query - required: false - description: Defaults to true, can be set to false if you are just looking at the workflow not completeing it. - schema: - type: boolean - # process_instance_run - post: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_run - summary: Run a process instance - tags: - - Process Instances - responses: - "200": - description: Returns details about the workflows state and current task - content: - application/json: - schema: - $ref: "#/components/schemas/Workflow" - /process-instances/{process_instance_id}/terminate: parameters: - name: process_instance_id @@ -863,20 +652,8 @@ paths: schema: $ref: "#/components/schemas/OkTrue" - /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}/terminate: + /process-instances/{process_instance_id}/suspend: parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - name: process_instance_id in: path required: true @@ -884,40 +661,7 @@ paths: schema: type: integer post: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_terminate - summary: Terminate a process instance - tags: - - Process Instances - responses: - "200": - description: Empty ok true response on successful termination. - content: - application/json: - schema: - $ref: "#/components/schemas/OkTrue" - - /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}/suspend: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - - name: process_instance_id - in: path - required: true - description: The unique id of an existing process instance. - schema: - type: integer - post: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_suspend + operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_suspend_2 summary: Suspend a process instance tags: - Process Instances @@ -929,20 +673,8 @@ paths: schema: $ref: "#/components/schemas/OkTrue" - /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}/resume: + /process-instances/{process_instance_id}/resume: parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - name: process_instance_id in: path required: true @@ -1224,75 +956,6 @@ paths: schema: $ref: "#/components/schemas/OkTrue" - /process-models/{process_group_id}/{process_model_id}/files/{file_name}: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model to validate. - schema: - type: string - - name: file_name - in: path - required: true - description: The id of the spec file - schema: - type: string - # get_file - get: - operationId: spiffworkflow_backend.routes.process_api_blueprint.get_file - summary: Returns metadata about the file - tags: - - Process Model Files - responses: - "200": - description: Returns the file information requested. - content: - application/json: - schema: - $ref: "#/components/schemas/File" - put: - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_file_update - summary: save the contents to the given file - tags: - - Process Model Files - requestBody: - description: Log Pagination Request - required: false - content: - multipart/form-data: - schema: - type: object - properties: - file: - type: string - format: binary - responses: - "200": - description: Metadata about the uploaded file, but not the file content. - content: - application/json: - schema: - $ref: "#/components/schemas/OkTrue" - 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: - name: page @@ -1569,51 +1232,6 @@ paths: schema: $ref: "#/components/schemas/ProcessInstanceLog" - /process-models/{process_group_id}/{process_model_id}/process-instances/{process_instance_id}/logs: - parameters: - - name: process_group_id - in: path - required: true - description: The unique id of an existing process group - schema: - type: string - - name: process_model_id - in: path - required: true - description: The unique id of an existing process model. - schema: - type: string - - name: process_instance_id - in: path - required: true - description: the id of the process instance - schema: - type: integer - - name: page - in: query - required: false - description: The page number to return. Defaults to page 1. - schema: - type: integer - - name: per_page - in: query - required: false - description: The number of items to show per page. Defaults to page 10. - schema: - type: integer - get: - tags: - - Process Instances - operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_log_list - summary: returns a list of logs associated with the process instance - responses: - "200": - description: list of logs - content: - application/json: - schema: - $ref: "#/components/schemas/ProcessInstanceLog" - /secrets: parameters: - name: page diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index 57d298eb..a76f3a79 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -555,6 +555,10 @@ def process_instance_terminate( return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") +def process_instance_suspend_2(process_instance_id: int) -> flask.wrappers.Response: + return process_instance_suspend(None, None, process_instance_id) + + def process_instance_suspend( process_group_id: str, process_model_id: str, @@ -569,6 +573,10 @@ def process_instance_suspend( return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") +def process_instance_resume_2(process_instance_id) -> flask.wrappers.Response: + return process_instance_resume(None, None, process_instance_id) + + def process_instance_resume( process_group_id: str, process_model_id: str, @@ -1283,7 +1291,7 @@ def task_submit( def script_unit_test_create( process_group_id: str, process_model_id: str, body: Dict[str, Union[str, bool, int]] ) -> flask.wrappers.Response: - """Script_unit_test_run.""" + """Script_unit_test_create.""" bpmn_task_identifier = _get_required_parameter_or_raise( "bpmn_task_identifier", body ) diff --git a/spiffworkflow-backend/tests/data/manual_task/manual_task.bpmn b/spiffworkflow-backend/tests/data/manual_task/manual_task.bpmn new file mode 100644 index 00000000..aefbb376 --- /dev/null +++ b/spiffworkflow-backend/tests/data/manual_task/manual_task.bpmn @@ -0,0 +1,41 @@ + + + + + Flow_1xlck7g + + + + Flow_0nnh2x9 + + + + + ## Hello + + Flow_1xlck7g + Flow_0nnh2x9 + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index b65dd5a0..88d0bf68 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -9,6 +9,8 @@ import pytest from flask.app import Flask from flask.testing import FlaskClient from flask_bpmn.models.db import db + +from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService from tests.spiffworkflow_backend.helpers.base_test import BaseTest from tests.spiffworkflow_backend.helpers.test_data import load_test_spec @@ -259,6 +261,7 @@ class TestProcessApi(BaseTest): bpmn_file_name = "sample.bpmn" bpmn_file_location = "sample" process_model_identifier = f"{test_process_group_id}/{test_process_model_id}" + modified_process_model_identifier = process_model_identifier.replace("/", ":") self.create_process_group(client, with_super_admin_user, test_process_group_id) self.create_process_model_with_api(client, process_model_identifier, user=with_super_admin_user) bpmn_file_data_bytes = self.get_test_data_file_contents( @@ -284,7 +287,7 @@ class TestProcessApi(BaseTest): # try to delete the model response = client.delete( - f"/v1.0/process-models/{test_process_group_id}/{test_process_model_id}", + f"/v1.0/process-models/{modified_process_model_identifier}", headers=self.logged_in_headers(with_super_admin_user), ) @@ -707,8 +710,9 @@ class TestProcessApi(BaseTest): # process_model = load_test_spec("random_fact") bad_process_model_identifier = f"x{process_model_identifier}" + modified_bad_process_model_identifier = bad_process_model_identifier.replace("/", ":") response = client.delete( - f"/v1.0/process-models/{bad_process_model_identifier}/files/random_fact.svg", + f"/v1.0/process-models/{modified_bad_process_model_identifier}/files/random_fact.svg", follow_redirects=True, headers=self.logged_in_headers(with_super_admin_user), ) @@ -894,8 +898,10 @@ class TestProcessApi(BaseTest): """Test_get_process_model_when_not_found.""" process_model_dir_name = "THIS_NO_EXISTS" group_id = self.create_process_group(client, with_super_admin_user, "my_group") + bad_process_model_id = f"{group_id}/{process_model_dir_name}" + modified_bad_process_model_id = bad_process_model_id.replace("/", ":") response = client.get( - f"/v1.0/process-models/{group_id}/{process_model_dir_name}", + f"/v1.0/process-models/{modified_bad_process_model_id}", headers=self.logged_in_headers(with_super_admin_user), ) assert response.status_code == 400 @@ -2220,3 +2226,64 @@ class TestProcessApi(BaseTest): # assert "pagingInfo" in rpc_json_data["result"] # # print("get_waku_messages") + + def test_process_instance_suspend( + self, + app: Flask, + client: FlaskClient, + with_db_and_bpmn_file_cleanup: None, + with_super_admin_user: UserModel, + ) -> None: + bpmn_file_name = "manual_task.bpmn" + bpmn_file_location = "manual_task" + process_model_identifier = self.basic_test_setup( + client=client, + user=with_super_admin_user, + process_model_id="manual_task", + bpmn_file_name=bpmn_file_name, + bpmn_file_location=bpmn_file_location + ) + + bpmn_file_data_bytes = self.get_test_data_file_contents( + bpmn_file_name, bpmn_file_location + ) + self.create_spec_file( + client=client, + process_model_id=process_model_identifier, + process_model_location=process_model_identifier, + file_name=bpmn_file_name, + file_data=bpmn_file_data_bytes, + user=with_super_admin_user + ) + + headers = self.logged_in_headers(with_super_admin_user) + response = self.create_process_instance( + client, process_model_identifier, headers + ) + assert response.json is not None + process_instance_id = response.json["id"] + + client.post( + f"/v1.0/process-instances/{process_instance_id}/run", + headers=self.logged_in_headers(with_super_admin_user), + ) + + process_instance = ProcessInstanceService().get_process_instance(process_instance_id) + assert process_instance.status == "user_input_required" + + client.post( + f"/v1.0/process-instances/{process_instance_id}/suspend", + headers=self.logged_in_headers(with_super_admin_user), + ) + process_instance = ProcessInstanceService().get_process_instance(process_instance_id) + assert process_instance.status == "suspended" + + # TODO: Why can I run a suspended process instance? + response = client.post( + f"/v1.0/process-instances/{process_instance_id}/run", + headers=self.logged_in_headers(with_super_admin_user), + ) + + # task = response.json['next_task'] + + print("test_process_instance_suspend")