mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-02-05 14:13:44 +00:00
do not require task to be given to evaluate a task unless that script specifically needs it w/ burnettk
This commit is contained in:
parent
afec26fbd5
commit
90b1772215
@ -1,5 +1,6 @@
|
|||||||
"""Script_attributes_context."""
|
"""Script_attributes_context."""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
|||||||
class ScriptAttributesContext:
|
class ScriptAttributesContext:
|
||||||
"""ScriptAttributesContext."""
|
"""ScriptAttributesContext."""
|
||||||
|
|
||||||
task: SpiffTask
|
task: Optional[SpiffTask]
|
||||||
environment_identifier: str
|
environment_identifier: str
|
||||||
process_instance_id: int
|
process_instance_id: int
|
||||||
process_model_identifier: str
|
process_model_identifier: str
|
||||||
|
@ -10,6 +10,10 @@ from spiffworkflow_backend.services.process_instance_processor import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TaskNotGivenToScriptError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GetDataSizes(Script):
|
class GetDataSizes(Script):
|
||||||
"""GetDataSizes."""
|
"""GetDataSizes."""
|
||||||
|
|
||||||
@ -30,6 +34,11 @@ class GetDataSizes(Script):
|
|||||||
**kwargs: Any
|
**kwargs: Any
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Run."""
|
"""Run."""
|
||||||
|
if script_attributes_context.task is None:
|
||||||
|
raise TaskNotGivenToScriptError(
|
||||||
|
"The task was not given to script 'get_data_sizes'. "
|
||||||
|
"This script needs to be run from within the context of a task."
|
||||||
|
)
|
||||||
workflow = script_attributes_context.task.workflow
|
workflow = script_attributes_context.task.workflow
|
||||||
task_data_size = ProcessInstanceProcessor.get_task_data_size(workflow)
|
task_data_size = ProcessInstanceProcessor.get_task_data_size(workflow)
|
||||||
task_data_keys_by_task = {
|
task_data_keys_by_task = {
|
||||||
|
@ -316,7 +316,7 @@ class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore
|
|||||||
|
|
||||||
super().__init__(environment=environment)
|
super().__init__(environment=environment)
|
||||||
|
|
||||||
def __get_augment_methods(self, task: SpiffTask) -> Dict[str, Callable]:
|
def __get_augment_methods(self, task: Optional[SpiffTask]) -> Dict[str, Callable]:
|
||||||
"""__get_augment_methods."""
|
"""__get_augment_methods."""
|
||||||
tld = current_app.config["THREAD_LOCAL_DATA"]
|
tld = current_app.config["THREAD_LOCAL_DATA"]
|
||||||
|
|
||||||
@ -356,8 +356,6 @@ class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore
|
|||||||
external_methods: Optional[Dict[str, Any]] = None,
|
external_methods: Optional[Dict[str, Any]] = None,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""_evaluate."""
|
"""_evaluate."""
|
||||||
methods = {}
|
|
||||||
if task:
|
|
||||||
methods = self.__get_augment_methods(task)
|
methods = self.__get_augment_methods(task)
|
||||||
if external_methods:
|
if external_methods:
|
||||||
methods.update(external_methods)
|
methods.update(external_methods)
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
"""Test_environment_var_script."""
|
||||||
|
from flask import Flask
|
||||||
|
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||||
|
|
||||||
|
from spiffworkflow_backend.models.script_attributes_context import (
|
||||||
|
ScriptAttributesContext,
|
||||||
|
)
|
||||||
|
from spiffworkflow_backend.scripts.get_env import GetEnv
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetEnv(BaseTest):
|
||||||
|
def test_get_env_script(
|
||||||
|
self,
|
||||||
|
app: Flask,
|
||||||
|
with_db_and_bpmn_file_cleanup: None,
|
||||||
|
) -> None:
|
||||||
|
process_model_identifier = "test_process_model"
|
||||||
|
process_instance_id = 1
|
||||||
|
script_attributes_context = ScriptAttributesContext(
|
||||||
|
task=None,
|
||||||
|
environment_identifier="unit_testing",
|
||||||
|
process_instance_id=process_instance_id,
|
||||||
|
process_model_identifier=process_model_identifier,
|
||||||
|
)
|
||||||
|
result = GetEnv().run(
|
||||||
|
script_attributes_context,
|
||||||
|
)
|
||||||
|
assert result == "unit_testing"
|
@ -1,23 +0,0 @@
|
|||||||
"""Test_environment_var_script."""
|
|
||||||
from flask import Flask
|
|
||||||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
|
||||||
|
|
||||||
from spiffworkflow_backend.services.process_instance_processor import (
|
|
||||||
ProcessInstanceProcessor,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestEnvironmentVarScript(BaseTest):
|
|
||||||
"""TestEnvironmentVarScript."""
|
|
||||||
|
|
||||||
# it's not totally obvious we want to keep this test/file
|
|
||||||
def test_script_engine_can_use_custom_scripts(
|
|
||||||
self,
|
|
||||||
app: Flask,
|
|
||||||
with_db_and_bpmn_file_cleanup: None,
|
|
||||||
) -> None:
|
|
||||||
"""Test_script_engine_takes_data_and_returns_expected_results."""
|
|
||||||
with app.app_context():
|
|
||||||
script_engine = ProcessInstanceProcessor._script_engine
|
|
||||||
result = script_engine._evaluate("get_env()", {})
|
|
||||||
assert result == "unit_testing"
|
|
Loading…
x
Reference in New Issue
Block a user