Best Python code snippet using localstack_python
test_swf.py
Source:test_swf.py
...16 def test_run_workflow(self):17 self.given_workflow()18 self.when_workflow_is_started()19 self.then_workflow_components_execute()20 self.then_workflow_history_has_expected_events()21 def given_workflow(self):22 self.swf_client.register_workflow_type(23 domain=self.workflow_domain_name,24 name=self.workflow_type_name,25 version=self.swf_version,26 defaultExecutionStartToCloseTimeout="500",27 defaultTaskStartToCloseTimeout="300",28 defaultTaskList=DEFAULT_TASK_LIST,29 defaultChildPolicy="TERMINATE",30 )31 workflow_types = self.swf_client.list_workflow_types(32 domain=self.workflow_domain_name, registrationStatus="REGISTERED"33 )34 self.assertIn(35 self.workflow_type_name,36 map(37 lambda workflow_type: workflow_type["workflowType"]["name"],38 workflow_types["typeInfos"],39 ),40 )41 self.swf_client.register_activity_type(42 domain=self.workflow_domain_name,43 name=self.workflow_activity_name,44 version=self.swf_version,45 defaultTaskList=DEFAULT_TASK_LIST,46 defaultTaskStartToCloseTimeout="NONE",47 defaultTaskScheduleToStartTimeout="NONE",48 defaultTaskScheduleToCloseTimeout="NONE",49 defaultTaskHeartbeatTimeout="100",50 )51 def when_workflow_is_started(self):52 self.workflow_execution = self.swf_client.start_workflow_execution(53 domain=self.workflow_domain_name,54 workflowId=self.swf_unique_id,55 workflowType={"name": self.workflow_type_name, "version": self.swf_version},56 )57 def then_workflow_components_execute(self):58 decision_task = self.swf_client.poll_for_decision_task(59 domain=self.workflow_domain_name, taskList=DEFAULT_TASK_LIST60 )61 self.swf_client.respond_decision_task_completed(62 taskToken=decision_task["taskToken"],63 decisions=[64 {65 "decisionType": "ScheduleActivityTask",66 "scheduleActivityTaskDecisionAttributes": {67 "activityType": {68 "name": self.workflow_activity_name,69 "version": self.swf_version,70 },71 "activityId": "10",72 },73 }74 ],75 )76 activity_task = self.swf_client.poll_for_activity_task(77 domain=self.workflow_domain_name, taskList=DEFAULT_TASK_LIST78 )79 self.swf_client.respond_activity_task_completed(80 taskToken=activity_task["taskToken"], result="activity success"81 )82 decision_task = self.swf_client.poll_for_decision_task(83 domain=self.workflow_domain_name, taskList=DEFAULT_TASK_LIST84 )85 self.swf_client.respond_decision_task_completed(86 taskToken=decision_task["taskToken"],87 decisions=[88 {89 "decisionType": "CompleteWorkflowExecution",90 "completeWorkflowExecutionDecisionAttributes": {"result": "workflow success"},91 }92 ],93 )94 def then_workflow_history_has_expected_events(self):95 history = self.swf_client.get_workflow_execution_history(96 domain=self.workflow_domain_name,97 execution={98 "workflowId": self.swf_unique_id,99 "runId": self.workflow_execution["runId"],100 },101 )102 events = map(lambda event: event["eventType"], history["events"])103 for event_type in [104 "WorkflowExecutionStarted",105 "DecisionTaskCompleted",106 "ActivityTaskCompleted",107 "WorkflowExecutionCompleted",108 ]:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!