From aea56fc7500469a45fc0994828e2f6b0d2a7babf Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 23 Sep 2022 14:19:57 -0400 Subject: [PATCH] allow process_status filter to be a csv string --- .../routes/process_api_blueprint.py | 3 ++- .../services/process_instance_processor.py | 2 +- .../integration/test_process_api.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index 998e4dff..898d9f11 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -583,8 +583,9 @@ def process_instance_list( ProcessInstanceModel.end_in_seconds <= end_till ) if process_status is not None: + process_status_array = process_status.split(",") process_instance_query = process_instance_query.filter( - ProcessInstanceModel.status == process_status + ProcessInstanceModel.status.in_(process_status_array) # type: ignore ) process_instances = process_instance_query.order_by( diff --git a/src/spiffworkflow_backend/services/process_instance_processor.py b/src/spiffworkflow_backend/services/process_instance_processor.py index 17c9a8b0..8fc15192 100644 --- a/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/src/spiffworkflow_backend/services/process_instance_processor.py @@ -357,7 +357,7 @@ class ProcessInstanceProcessor: @staticmethod def __get_bpmn_process_instance( process_instance_model: ProcessInstanceModel, - spec: WorkflowSpec = None, + spec: Optional[WorkflowSpec] = None, validate_only: bool = False, subprocesses: Optional[IdToBpmnProcessSpecMapping] = None, ) -> BpmnWorkflow: diff --git a/tests/spiffworkflow_backend/integration/test_process_api.py b/tests/spiffworkflow_backend/integration/test_process_api.py index 192a7270..1aea2422 100644 --- a/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/tests/spiffworkflow_backend/integration/test_process_api.py @@ -1050,6 +1050,16 @@ class TestProcessApi(BaseTest): assert len(results) == 1 assert results[0]["status"] == ProcessInstanceStatus[statuses[i]].value + response = client.get( + f"/v1.0/process-instances?process_status=not_started,complete&process_group_identifier={test_process_group_id}&process_model_identifier={test_process_model_id}", + headers=self.logged_in_headers(user), + ) + assert response.json is not None + results = response.json["results"] + assert len(results) == 2 + assert results[0]["status"] in ['complete', 'not_started'] + assert results[1]["status"] in ['complete', 'not_started'] + # filter by start/end seconds # start > 1000 - this should eliminate the first response = client.get(