Skip to content

Commit

Permalink
best practice keyword naming (#80)
Browse files Browse the repository at this point in the history
* best practice keyword naming

- remove name attributes and let robot determine title case from python methods
- add tags to all keywords

* python version must be string
  • Loading branch information
Noordsestern authored Apr 5, 2022
1 parent 9fa4a2d commit e3de222
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, 3.10]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
61 changes: 29 additions & 32 deletions CamundaLibrary/CamundaLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, host="http://localhost:8080"):
self.set_camunda_configuration(configuration={'host': host})
self.DEFAULT_LOCK_DURATION = self.reset_task_lock_duration()

@keyword
@keyword(tags=['configuration'])
def set_camunda_configuration(self,configuration: dict):
if 'host' not in configuration.keys():
raise ValueError(f"Incomplete configuration. Configuration must include at least the Camunda host url:\t{configuration}")
Expand All @@ -124,7 +124,7 @@ def set_camunda_configuration(self,configuration: dict):
logger.debug(f"New configuration for Camunda client:\t{camunda_config}")
self._shared_resources.client_configuration = Configuration(**camunda_config)

@keyword("Set Camunda URL")
@keyword(tags=['configuration'])
def set_camunda_url(self, url: str):
"""
Sets url for camunda eninge. Only necessary when URL cannot be set during initialization of this library or
Expand All @@ -134,7 +134,7 @@ def set_camunda_url(self, url: str):
raise ValueError('Cannot set camunda engine url: no url given.')
self._shared_resources.camunda_url = url_normalize(f'{url}/engine-rest')

@keyword("Set Task Lock Duration", tags=["task"])
@keyword(tags=['task', 'configuration'])
def set_task_lock_duration(self, lock_duration: int):
"""
Sets lock duration used as default when fetching. Camunda locks a process instance for the period. If the
Expand All @@ -148,7 +148,7 @@ def set_task_lock_duration(self, lock_duration: int):
except ValueError:
logger.error(f'Failed to set lock duration. Value does not seem a valid integer:\t{lock_duration}')

@keyword("Reset Task Lock Duration", tags=["task"])
@keyword(tags=['task', 'configuration'])
def reset_task_lock_duration(self):
"""
Counter keyword for "Set Task Lock Duration". Resets lock duration to the default. The default is either
Expand All @@ -162,11 +162,11 @@ def reset_task_lock_duration(self):
lock_duration = 600000
return lock_duration

@keyword("Get Camunda URL")
@keyword(tags=['configuration'])
def get_camunda_url(self) -> str:
return self._shared_resources.camunda_url

@keyword("Get amount of workloads")
@keyword(tags=['task'])
def get_amount_of_workloads(self, topic: str, **kwargs) -> int:
"""
Retrieves count of tasks. By default expects a topic name, but all parameters from the original endpoint
Expand All @@ -183,8 +183,7 @@ def get_amount_of_workloads(self, topic: str, **kwargs) -> int:
logger.info(f'Amount of workloads for "{topic}":\t{response.count}')
return response.count


@keyword(name='Deploy', tags=['deployment'])
@keyword(tags=['deployment'])
def deploy(self, *args):
"""Creates a deployment from all given files and uploads them to camunda.
Expand Down Expand Up @@ -256,7 +255,7 @@ def deploy_multiple_files(self, *args):

return json

@keyword(name='Get deployments', tags=['deployment'])
@keyword(tags=['deployment'])
def get_deployments(self, deployment_id: str = None, **kwargs):
"""
Retrieves all deployments that match given criteria. All parameters are available from https://docs.camunda.org/manual/latest/reference/rest/deployment/get-query/
Expand All @@ -280,7 +279,7 @@ def get_deployments(self, deployment_id: str = None, **kwargs):

return [r.to_dict() for r in response]

@keyword("Deliver Message", tags=["message"])
@keyword(tags=['message'])
def deliver_message(self, message_name, **kwargs):
"""
Delivers a message using Camunda REST API: https://docs.camunda.org/manual/7.15/reference/rest/message/post-message/
Expand Down Expand Up @@ -324,8 +323,7 @@ def deliver_message(self, message_name, **kwargs):
else:
return {}


@keyword("Fetch Workload", tags=['task'])
@keyword(tags=['task'])
def fetch_workload(self, topic: str, async_response_timeout=None, use_priority=None, **kwargs) -> Dict:
"""
Locks and fetches workloads from camunda on a given topic. Returns a list of variable dictionary.
Expand Down Expand Up @@ -389,8 +387,7 @@ def fetch_workload(self, topic: str, async_response_timeout=None, use_priority=N
variables: Dict[str, VariableValueDto] = self.FETCH_RESPONSE.variables
return CamundaResources.convert_openapi_variables_to_dict(variables)


@keyword("Get fetch response", tags=['task'])
@keyword(tags=['task'])
def get_fetch_response(self):
"""Returns cached response from the last call of `fetch workload`.
Expand Down Expand Up @@ -423,9 +420,9 @@ def drop_fetch_response(self):
"""
self.FETCH_RESPONSE = {}

@keyword("Throw BPMN Error", tags=['task'])
def bpmn_error(self, error_code: str, error_message: str = None, variables: Dict[str, Any] = None,
files: Dict = None):
@keyword(tags=['task', 'complete'])
def throw_bpmn_error(self, error_code: str, error_message: str = None, variables: Dict[str, Any] = None,
files: Dict = None):
if not self.FETCH_RESPONSE:
logger.warn('No task to complete. Maybe you did not fetch and lock a workitem before?')
else:
Expand All @@ -446,7 +443,7 @@ def bpmn_error(self, error_code: str, error_message: str = None, variables: Dict
except ApiException as e:
raise ApiException(f"Exception when calling ExternalTaskApi->handle_external_task_bpmn_error: {e}\n")

@keyword("Notify failure", tags=["task"])
@keyword(tags=['task', 'complete'])
def notify_failure(self, **kwargs):
"""
Raises a failure to Camunda. When retry counter is less than 1, an incident is created by Camunda.
Expand Down Expand Up @@ -483,7 +480,7 @@ def notify_failure(self, **kwargs):
except ApiException as e:
raise ApiException("Exception when calling ExternalTaskApi->handle_failure: %s\n" % e)

@keyword("Get incidents")
@keyword(tags=['incident'])
def get_incidents(self, **kwargs):
"""
Retrieves incidents matching given filter arguments.
Expand All @@ -504,8 +501,8 @@ def get_incidents(self, **kwargs):

return [incident.to_dict() for incident in response]

@keyword("Complete task", tags=['task'])
def complete(self, result_set: Dict[str, Any] = None, files: Dict = None):
@keyword(tags=['task', 'complete'])
def complete_task(self, result_set: Dict[str, Any] = None, files: Dict = None):
"""
Completes the task that was fetched before with `fetch workload`.
Expand Down Expand Up @@ -549,7 +546,7 @@ def complete(self, result_set: Dict[str, Any] = None, files: Dict = None):
except ApiException as e:
raise ApiException(f"Exception when calling ExternalTaskApi->complete_external_task_resource: {e}\n")

@keyword("Download file from variable", tags=['task'])
@keyword(tags=['task', 'variable', 'file'])
def download_file_from_variable(self, variable_name: str) -> str:
if not self.FETCH_RESPONSE:
logger.warn('Could not download file for variable. Maybe you did not fetch and lock a workitem before?')
Expand All @@ -565,7 +562,7 @@ def download_file_from_variable(self, variable_name: str) -> str:
raise ApiException(f"Exception when calling ExternalTaskApi->get_process_instance_variable_binary: {e}\n")
return response

@keyword("Unlock", tags=['task'])
@keyword(tags=['task', 'complete'])
def unlock(self):
"""
Unlocks recent task.
Expand All @@ -581,7 +578,7 @@ def unlock(self):
except ApiException as e:
raise ApiException(f"Exception when calling ExternalTaskApi->unlock: {e}\n")

@keyword("Start process", tags=['process'])
@keyword(tags=['process'])
def start_process(self, process_key: str, variables: Dict = None, files: Dict = None,
before_activity_id: str = None, after_activity_id: str = None, **kwargs) -> Dict:
"""
Expand Down Expand Up @@ -636,7 +633,7 @@ def start_process(self, process_key: str, variables: Dict = None, files: Dict =

return response.to_dict()

@keyword("Delete process instance", tags=['process'])
@keyword(tags=['process'])
def delete_process_instance(self, process_instance_id):
"""
USE WITH CARE: Deletes a process instance by id. All data in this process instance will be lost.
Expand All @@ -649,14 +646,14 @@ def delete_process_instance(self, process_instance_id):
except ApiException as e:
raise ApiException(f'Failed to delete process instance {process_instance_id}:\n{e}')

@keyword("Get all active process instances", tags=['process'])
@keyword(tags=['process'])
def get_all_active_process_instances(self, process_definition_key):
"""
Returns a list of process instances that are active for a certain process definition identified by key.
"""
return self.get_process_instances(process_definition_key=process_definition_key, active='true')

@keyword("Get process instances")
@keyword(tags=['process'])
def get_process_instances(self, **kwargs):
"""
Queries Camunda for process instances that match certain criteria.
Expand Down Expand Up @@ -716,7 +713,7 @@ def get_process_instances(self, **kwargs):

return [process_instance.to_dict() for process_instance in response]

@keyword("Get Version", tags=['version'])
@keyword(tags=['version'])
def get_version(self):
"""
Returns Version of Camunda.
Expand All @@ -729,7 +726,7 @@ def get_version(self):
api_instance: VersionApi = openapi_client.VersionApi(api_client)
return api_instance.get_rest_api_version()

@keyword("Get Process Definitions", tags=['process'])
@keyword(tags=['process'])
def get_process_definitions(self, **kwargs):
"""
Returns a list of process definitions that fulfill given parameters.
Expand All @@ -749,7 +746,7 @@ def get_process_definitions(self, **kwargs):

return response

@keyword("Get Activity Instance", tags=['process'])
@keyword(tags=['process'])
def get_activity_instance(self, id: str):
"""
Returns an Activity Instance (Tree) for a given process instance.
Expand All @@ -768,7 +765,7 @@ def get_activity_instance(self, id: str):
raise ApiException(f'failed to get activity tree for process instance with id {id}:\n{e}')
return response.to_dict()

@keyword("Get Process Instance Variable", tags=['process'])
@keyword(tags=['process'])
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
Expand Down Expand Up @@ -800,7 +797,7 @@ def get_process_instance_variable(self, process_instance_id: str, variable_name:
return CamundaResources.convert_variable_dto(response)
return response

@keyword("Evaluate Decision", tags=['decision'])
@keyword(tags=['decision'])
def evaluate_decision(self, key: str, variables: dict) -> list:
"""
Evaluates a given decision and returns the result.
Expand Down

0 comments on commit e3de222

Please sign in to comment.