From 3cc97135717d295051d21fe498d842fd8fc352c6 Mon Sep 17 00:00:00 2001 From: Markus Stahl Date: Wed, 16 Mar 2022 21:35:10 +0100 Subject: [PATCH] introduce autotype conversion for process instance variables #69 --- CamundaLibrary/CamundaLibrary.py | 11 +++++++---- tests/robot/ExternalTask/test_dict_vars_to_json.robot | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CamundaLibrary/CamundaLibrary.py b/CamundaLibrary/CamundaLibrary.py index 6c1a2a7..b3a2e7c 100644 --- a/CamundaLibrary/CamundaLibrary.py +++ b/CamundaLibrary/CamundaLibrary.py @@ -768,7 +768,7 @@ def get_activity_instance(self, id: str): return response.to_dict() @keyword("Get Process Instance Variable", tags=['process']) - def get_process_instance_variable(self, process_instance_id: str, variable_name: str): + def get_process_instance_variable(self, process_instance_id: str, variable_name: str, auto_type_conversion: bool = True): """ Returns the variable with the given name from the process instance with the given process_instance_id. @@ -776,6 +776,7 @@ def get_process_instance_variable(self, process_instance_id: str, variable_name: Parameters: - ``process_instance_id``: ID of the target process instance - ``variable_name``: name of the variable to read + - ``auto_type_conversion``: Converts JSON structures automatically in to python data structures. Default: True. When False, values are not retrieved for JSON variables, but metadata is. Only useful when you want to verify that Camunda holds certain data types.% == Example == | ${variable} | Get Process Instance Variable | @@ -783,18 +784,20 @@ def get_process_instance_variable(self, process_instance_id: str, variable_name: | ... | variable_name=foo | See also: - https://docs.camunda.org/manual/7.5/reference/rest/process-instance/variables/get-single-variable/ + https://docs.camunda.org/manual/latest/reference/rest/process-instance/variables/get-single-variable/ """ with self._shared_resources.api_client as api_client: api_instance: ProcessInstanceApi = openapi_client.ProcessInstanceApi(api_client) try: response = api_instance.get_process_instance_variable( - id=process_instance_id, var_name=variable_name, deserialize_value=False) + id=process_instance_id, var_name=variable_name, deserialize_value=not auto_type_conversion) except ApiException as e: raise ApiException(f'Failed to get variable {variable_name} from ' f'process instance {process_instance_id}:\n{e}') - return CamundaResources.convert_variable_dto(response) + if automated_type_conversion: + return CamundaResources.convert_variable_dto(response) + return response @keyword("Evaluate Decision", tags=['decision']) def evaluate_decision(self, key: str, variables: dict) -> list: diff --git a/tests/robot/ExternalTask/test_dict_vars_to_json.robot b/tests/robot/ExternalTask/test_dict_vars_to_json.robot index 6e3abc3..d1199bd 100644 --- a/tests/robot/ExternalTask/test_dict_vars_to_json.robot +++ b/tests/robot/ExternalTask/test_dict_vars_to_json.robot @@ -35,6 +35,7 @@ Dictionary variable is of type JSON in camunda ${variable_instance} Get Process Instance Variable ... process_instance_id=${process_instance}[id] ... variable_name=map + ... automated_type_conversion=${False} Should Be Equal Json ${variable_instance.type} Datatype for dictionary was supposed to be Json