Skip to content

Commit e3de222

Browse files
authored
best practice keyword naming (#80)
* 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
1 parent 9fa4a2d commit e3de222

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: [3.7, 3.8, 3.9, 3.10]
14+
python-version: ['3.7', '3.8', '3.9', '3.10']
1515

1616
steps:
1717
- uses: actions/checkout@v2

CamundaLibrary/CamundaLibrary.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, host="http://localhost:8080"):
9999
self.set_camunda_configuration(configuration={'host': host})
100100
self.DEFAULT_LOCK_DURATION = self.reset_task_lock_duration()
101101

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

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

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

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

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

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

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

257256
return json
258257

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

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

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

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

392-
393-
@keyword("Get fetch response", tags=['task'])
390+
@keyword(tags=['task'])
394391
def get_fetch_response(self):
395392
"""Returns cached response from the last call of `fetch workload`.
396393
@@ -423,9 +420,9 @@ def drop_fetch_response(self):
423420
"""
424421
self.FETCH_RESPONSE = {}
425422

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

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

486-
@keyword("Get incidents")
483+
@keyword(tags=['incident'])
487484
def get_incidents(self, **kwargs):
488485
"""
489486
Retrieves incidents matching given filter arguments.
@@ -504,8 +501,8 @@ def get_incidents(self, **kwargs):
504501

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

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

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

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

584-
@keyword("Start process", tags=['process'])
581+
@keyword(tags=['process'])
585582
def start_process(self, process_key: str, variables: Dict = None, files: Dict = None,
586583
before_activity_id: str = None, after_activity_id: str = None, **kwargs) -> Dict:
587584
"""
@@ -636,7 +633,7 @@ def start_process(self, process_key: str, variables: Dict = None, files: Dict =
636633

637634
return response.to_dict()
638635

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

652-
@keyword("Get all active process instances", tags=['process'])
649+
@keyword(tags=['process'])
653650
def get_all_active_process_instances(self, process_definition_key):
654651
"""
655652
Returns a list of process instances that are active for a certain process definition identified by key.
656653
"""
657654
return self.get_process_instances(process_definition_key=process_definition_key, active='true')
658655

659-
@keyword("Get process instances")
656+
@keyword(tags=['process'])
660657
def get_process_instances(self, **kwargs):
661658
"""
662659
Queries Camunda for process instances that match certain criteria.
@@ -716,7 +713,7 @@ def get_process_instances(self, **kwargs):
716713

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

719-
@keyword("Get Version", tags=['version'])
716+
@keyword(tags=['version'])
720717
def get_version(self):
721718
"""
722719
Returns Version of Camunda.
@@ -729,7 +726,7 @@ def get_version(self):
729726
api_instance: VersionApi = openapi_client.VersionApi(api_client)
730727
return api_instance.get_rest_api_version()
731728

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

750747
return response
751748

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

771-
@keyword("Get Process Instance Variable", tags=['process'])
768+
@keyword(tags=['process'])
772769
def get_process_instance_variable(self, process_instance_id: str, variable_name: str, auto_type_conversion: bool = True):
773770
"""
774771
Returns the variable with the given name from the process instance with
@@ -800,7 +797,7 @@ def get_process_instance_variable(self, process_instance_id: str, variable_name:
800797
return CamundaResources.convert_variable_dto(response)
801798
return response
802799

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

0 commit comments

Comments
 (0)