From 0aaf503c3f298c74530cadbaa5e339e01198e5ee Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Wed, 28 Dec 2022 17:04:47 -0500 Subject: [PATCH] Make list available to script tasks (#86) --- spiffworkflow-backend/migrations/env.py | 2 -- .../services/process_instance_processor.py | 1 + .../spiffworkflow_backend/integration/test_process_api.py | 8 +++++--- .../unit/test_process_instance_processor.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-backend/migrations/env.py b/spiffworkflow-backend/migrations/env.py index 68feded2a..630e381ad 100644 --- a/spiffworkflow-backend/migrations/env.py +++ b/spiffworkflow-backend/migrations/env.py @@ -1,5 +1,3 @@ -from __future__ import with_statement - import logging from logging.config import fileConfig diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index bd588a373..1925fff06 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -152,6 +152,7 @@ class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore "decimal": decimal, "_strptime": _strptime, "enumerate": enumerate, + "list": list, } # This will overwrite the standard builtins 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 66b6fa672..abcc4715e 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -1,6 +1,5 @@ """Test Process Api Blueprint.""" import io -from flask_bpmn.api.api_error import ApiError import json import os import time @@ -2049,6 +2048,7 @@ class TestProcessApi(BaseTest): with_db_and_bpmn_file_cleanup: None, with_super_admin_user: UserModel, ) -> None: + """Test_task_data_is_set_even_if_process_instance_errors.""" process_model = load_test_spec( process_model_id="group/error_with_task_data", bpmn_file_name="script_error_with_task_data.bpmn", @@ -2063,9 +2063,11 @@ class TestProcessApi(BaseTest): headers=self.logged_in_headers(with_super_admin_user), ) assert response.status_code == 400 - assert process_instance.status == 'error' + assert process_instance.status == "error" processor = ProcessInstanceProcessor(process_instance) - spiff_task = processor.get_task_by_bpmn_identifier('script_task_one', processor.bpmn_process_instance) + spiff_task = processor.get_task_by_bpmn_identifier( + "script_task_one", processor.bpmn_process_instance + ) assert spiff_task is not None assert spiff_task.data != {} diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py index e727dba2f..4f7db3ad3 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py @@ -31,7 +31,7 @@ class TestProcessInstanceProcessor(BaseTest): with_db_and_bpmn_file_cleanup: None, ) -> None: """Test_script_engine_takes_data_and_returns_expected_results.""" - app.config["THREAD_LOCAL_DATA"].process_model_identifier = 'hey' + app.config["THREAD_LOCAL_DATA"].process_model_identifier = "hey" app.config["THREAD_LOCAL_DATA"].process_instance_id = 0 script_engine = ProcessInstanceProcessor._script_engine @@ -46,7 +46,7 @@ class TestProcessInstanceProcessor(BaseTest): with_db_and_bpmn_file_cleanup: None, ) -> None: """Test_script_engine_takes_data_and_returns_expected_results.""" - app.config["THREAD_LOCAL_DATA"].process_model_identifier = 'hey' + app.config["THREAD_LOCAL_DATA"].process_model_identifier = "hey" app.config["THREAD_LOCAL_DATA"].process_instance_id = 0 script_engine = ProcessInstanceProcessor._script_engine result = script_engine._evaluate("fact_service(type='norris')", {})