Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make a script engine for bpmn unit tests #1145

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
import traceback
from abc import abstractmethod
from dataclasses import dataclass
from typing import Any

from lxml import etree # type: ignore
from SpiffWorkflow.bpmn.exceptions import WorkflowTaskException # type: ignore
from SpiffWorkflow.bpmn.script_engine import PythonScriptEngine # type: ignore
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore
from SpiffWorkflow.util.task import TaskState # type: ignore

from spiffworkflow_backend.services.custom_parser import MyCustomParser
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor


class UnrunnableTestCaseError(Exception):
Expand All @@ -41,6 +42,29 @@ class BpmnFileMissingExecutableProcessError(Exception):
pass


class ProcessModelTestRunnerScriptEngine(PythonScriptEngine): # type: ignore
def execute(self, task: SpiffTask, script: str, external_context: Any = None) -> bool:
methods = {
"get_process_initiator_user": lambda: {
"username": "test_username_a",
"tenant_specific_field_1": "test_tenant_specific_field_1_a",
},
}
if external_context:
methods.update(external_context)
if script:
super().execute(task, script, methods)
return True

def call_service(
self,
operation_name: str,
operation_params: dict[str, Any],
spiff_task: SpiffTask,
) -> str:
raise Exception("please override this service task in your bpmn unit test json")

burnettk marked this conversation as resolved.
Show resolved Hide resolved

@dataclass
class TestCaseErrorDetails:
error_messages: list[str]
Expand Down Expand Up @@ -122,7 +146,7 @@ def instantiate_executer(self, bpmn_file: str) -> BpmnWorkflow:
bpmn_process_spec,
subprocess_specs=subprocesses,
)
bpmn_process_instance.script_engine = ProcessInstanceProcessor._default_script_engine
bpmn_process_instance.script_engine = ProcessModelTestRunnerScriptEngine()

# we do not want to call the real get_process_initiator_user script, since it depends on a process instance
# that does not actually exist
Expand Down
Loading