How to use respond_decision_task_completed method in localstack

Best Python code snippet using localstack_python

test_decision_tasks.py

Source:test_decision_tasks.py Github

copy

Full Screen

...36 decision = {37 "decisionType": "ScheduleActivityTask",38 "scheduleActivityTaskDecisionAttributes": attrs,39 }40 conn.respond_decision_task_completed(resp["taskToken"], decisions=[decision])41 resp = conn.poll_for_decision_task("test-domain", "queue")42 assert resp["workflowExecution"]["runId"] == conn.run_id43 assert resp["previousStartedEventId"] == 344@mock_swf_deprecated45def test_poll_for_decision_task_when_none():46 conn = setup_workflow()47 conn.poll_for_decision_task("test-domain", "queue")48 resp = conn.poll_for_decision_task("test-domain", "queue")49 # this is the DecisionTask representation you get from the real SWF50 # after waiting 60s when there's no decision to be taken51 resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})52@mock_swf_deprecated53def test_poll_for_decision_task_on_non_existent_queue():54 conn = setup_workflow()55 resp = conn.poll_for_decision_task("test-domain", "non-existent-queue")56 resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})57@mock_swf_deprecated58def test_poll_for_decision_task_with_reverse_order():59 conn = setup_workflow()60 resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True)61 types = [evt["eventType"] for evt in resp["events"]]62 types.should.equal(63 ["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"]64 )65# CountPendingDecisionTasks endpoint66@mock_swf_deprecated67def test_count_pending_decision_tasks():68 conn = setup_workflow()69 conn.poll_for_decision_task("test-domain", "queue")70 resp = conn.count_pending_decision_tasks("test-domain", "queue")71 resp.should.equal({"count": 1, "truncated": False})72@mock_swf_deprecated73def test_count_pending_decision_tasks_on_non_existent_task_list():74 conn = setup_workflow()75 resp = conn.count_pending_decision_tasks("test-domain", "non-existent")76 resp.should.equal({"count": 0, "truncated": False})77@mock_swf_deprecated78def test_count_pending_decision_tasks_after_decision_completes():79 conn = setup_workflow()80 resp = conn.poll_for_decision_task("test-domain", "queue")81 conn.respond_decision_task_completed(resp["taskToken"])82 resp = conn.count_pending_decision_tasks("test-domain", "queue")83 resp.should.equal({"count": 0, "truncated": False})84# RespondDecisionTaskCompleted endpoint85@mock_swf_deprecated86def test_respond_decision_task_completed_with_no_decision():87 conn = setup_workflow()88 resp = conn.poll_for_decision_task("test-domain", "queue")89 task_token = resp["taskToken"]90 resp = conn.respond_decision_task_completed(91 task_token, execution_context="free-form context"92 )93 resp.should.be.none94 resp = conn.get_workflow_execution_history(95 "test-domain", conn.run_id, "uid-abcd1234"96 )97 types = [evt["eventType"] for evt in resp["events"]]98 types.should.equal(99 [100 "WorkflowExecutionStarted",101 "DecisionTaskScheduled",102 "DecisionTaskStarted",103 "DecisionTaskCompleted",104 ]105 )106 evt = resp["events"][-1]107 evt["decisionTaskCompletedEventAttributes"].should.equal(108 {109 "executionContext": "free-form context",110 "scheduledEventId": 2,111 "startedEventId": 3,112 }113 )114 resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")115 resp["latestExecutionContext"].should.equal("free-form context")116@mock_swf_deprecated117def test_respond_decision_task_completed_with_wrong_token():118 conn = setup_workflow()119 conn.poll_for_decision_task("test-domain", "queue")120 conn.respond_decision_task_completed.when.called_with(121 "not-a-correct-token"122 ).should.throw(SWFResponseError)123@mock_swf_deprecated124def test_respond_decision_task_completed_on_close_workflow_execution():125 conn = setup_workflow()126 resp = conn.poll_for_decision_task("test-domain", "queue")127 task_token = resp["taskToken"]128 # bad: we're closing workflow execution manually, but endpoints are not129 # coded for now..130 wfe = swf_backend.domains[0].workflow_executions[-1]131 wfe.execution_status = "CLOSED"132 # /bad133 conn.respond_decision_task_completed.when.called_with(task_token).should.throw(134 SWFResponseError135 )136@mock_swf_deprecated137def test_respond_decision_task_completed_with_task_already_completed():138 conn = setup_workflow()139 resp = conn.poll_for_decision_task("test-domain", "queue")140 task_token = resp["taskToken"]141 conn.respond_decision_task_completed(task_token)142 conn.respond_decision_task_completed.when.called_with(task_token).should.throw(143 SWFResponseError144 )145@mock_swf_deprecated146def test_respond_decision_task_completed_with_complete_workflow_execution():147 conn = setup_workflow()148 resp = conn.poll_for_decision_task("test-domain", "queue")149 task_token = resp["taskToken"]150 decisions = [151 {152 "decisionType": "CompleteWorkflowExecution",153 "completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"},154 }155 ]156 resp = conn.respond_decision_task_completed(task_token, decisions=decisions)157 resp.should.be.none158 resp = conn.get_workflow_execution_history(159 "test-domain", conn.run_id, "uid-abcd1234"160 )161 types = [evt["eventType"] for evt in resp["events"]]162 types.should.equal(163 [164 "WorkflowExecutionStarted",165 "DecisionTaskScheduled",166 "DecisionTaskStarted",167 "DecisionTaskCompleted",168 "WorkflowExecutionCompleted",169 ]170 )171 resp["events"][-1]["workflowExecutionCompletedEventAttributes"][172 "result"173 ].should.equal("foo bar")174@mock_swf_deprecated175def test_respond_decision_task_completed_with_close_decision_not_last():176 conn = setup_workflow()177 resp = conn.poll_for_decision_task("test-domain", "queue")178 task_token = resp["taskToken"]179 decisions = [180 {"decisionType": "CompleteWorkflowExecution"},181 {"decisionType": "WeDontCare"},182 ]183 conn.respond_decision_task_completed.when.called_with(184 task_token, decisions=decisions185 ).should.throw(SWFResponseError, r"Close must be last decision in list")186@mock_swf_deprecated187def test_respond_decision_task_completed_with_invalid_decision_type():188 conn = setup_workflow()189 resp = conn.poll_for_decision_task("test-domain", "queue")190 task_token = resp["taskToken"]191 decisions = [192 {"decisionType": "BadDecisionType"},193 {"decisionType": "CompleteWorkflowExecution"},194 ]195 conn.respond_decision_task_completed.when.called_with(196 task_token, decisions=decisions197 ).should.throw(198 SWFResponseError,199 r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'",200 )201@mock_swf_deprecated202def test_respond_decision_task_completed_with_missing_attributes():203 conn = setup_workflow()204 resp = conn.poll_for_decision_task("test-domain", "queue")205 task_token = resp["taskToken"]206 decisions = [207 {208 "decisionType": "should trigger even with incorrect decision type",209 "startTimerDecisionAttributes": {},210 }211 ]212 conn.respond_decision_task_completed.when.called_with(213 task_token, decisions=decisions214 ).should.throw(215 SWFResponseError,216 r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "217 r"failed to satisfy constraint: Member must not be null",218 )219@mock_swf_deprecated220def test_respond_decision_task_completed_with_missing_attributes_totally():221 conn = setup_workflow()222 resp = conn.poll_for_decision_task("test-domain", "queue")223 task_token = resp["taskToken"]224 decisions = [{"decisionType": "StartTimer"}]225 conn.respond_decision_task_completed.when.called_with(226 task_token, decisions=decisions227 ).should.throw(228 SWFResponseError,229 r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "230 r"failed to satisfy constraint: Member must not be null",231 )232@mock_swf_deprecated233def test_respond_decision_task_completed_with_fail_workflow_execution():234 conn = setup_workflow()235 resp = conn.poll_for_decision_task("test-domain", "queue")236 task_token = resp["taskToken"]237 decisions = [238 {239 "decisionType": "FailWorkflowExecution",240 "failWorkflowExecutionDecisionAttributes": {241 "reason": "my rules",242 "details": "foo",243 },244 }245 ]246 resp = conn.respond_decision_task_completed(task_token, decisions=decisions)247 resp.should.be.none248 resp = conn.get_workflow_execution_history(249 "test-domain", conn.run_id, "uid-abcd1234"250 )251 types = [evt["eventType"] for evt in resp["events"]]252 types.should.equal(253 [254 "WorkflowExecutionStarted",255 "DecisionTaskScheduled",256 "DecisionTaskStarted",257 "DecisionTaskCompleted",258 "WorkflowExecutionFailed",259 ]260 )261 attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"]262 attrs["reason"].should.equal("my rules")263 attrs["details"].should.equal("foo")264@mock_swf_deprecated265@freeze_time("2015-01-01 12:00:00")266def test_respond_decision_task_completed_with_schedule_activity_task():267 conn = setup_workflow()268 resp = conn.poll_for_decision_task("test-domain", "queue")269 task_token = resp["taskToken"]270 decisions = [271 {272 "decisionType": "ScheduleActivityTask",273 "scheduleActivityTaskDecisionAttributes": {274 "activityId": "my-activity-001",275 "activityType": {"name": "test-activity", "version": "v1.1"},276 "heartbeatTimeout": "60",277 "input": "123",278 "taskList": {"name": "my-task-list"},279 },280 }281 ]282 resp = conn.respond_decision_task_completed(task_token, decisions=decisions)283 resp.should.be.none284 resp = conn.get_workflow_execution_history(285 "test-domain", conn.run_id, "uid-abcd1234"286 )287 types = [evt["eventType"] for evt in resp["events"]]288 types.should.equal(289 [290 "WorkflowExecutionStarted",291 "DecisionTaskScheduled",292 "DecisionTaskStarted",293 "DecisionTaskCompleted",294 "ActivityTaskScheduled",295 ]296 )...

Full Screen

Full Screen

decider.py

Source:decider.py Github

copy

Full Screen

...12 else:13 eventHistory = [evt for evt in task["events"] if not evt['eventType'].startswith('Decision')]14 last_event = eventHistory[-1]15 if last_event["eventType"] == 'WorkflowExecutionStarted':16 swf.respond_decision_task_completed(17 taskToken=task["taskToken"],18 decisions=[19 {20 'decisionType': "ScheduleActivityTask",21 'scheduleActivityTaskDecisionAttributes': {22 'activityType': {23 "name": SWFConfig.ACTIVITY_LIST[0]["name"],24 "version":SWFConfig.ACTIVITY_LIST[0]["version"]25 },26 'activityId': str(uuid.uuid4()),27 "input": "achakalasreenath1997@gmail.com"28 }29 }30 ]31 )32 elif last_event["eventType"] == 'ActivityTaskCompleted':33 activity_tasks_scheduled_history = [event for event in eventHistory if34 event["eventType"] == "ActivityTaskScheduled"]35 last_activity_scheduled = activity_tasks_scheduled_history[-1]36 if not last_activity_scheduled:37 swf.respond_decision_task_completed(38 taskToken=task["taskToken"],39 decisions=[40 {41 'decisionType': "WorkflowExecutionFailed",42 'failWorkflowExecutionDecisionAttributes': {43 'reason': 'last activity task scheduled cannot be found',44 'details': 'string'45 }46 }47 ]48 )49 continue50 activity = last_activity_scheduled["activityTaskScheduledEventAttributes"]["activityType"]["name"]51 input_param = last_event["activityTaskCompletedEventAttributes"]["result"]52 for i,act in enumerate(SWFConfig.ACTIVITY_LIST):53 if act["name"] == activity:54 if i != len(SWFConfig.ACTIVITY_LIST)-1:55 next_activity = SWFConfig.ACTIVITY_LIST[i+1]56 else:57 next_activity = None58 if next_activity == None:59 swf.respond_decision_task_completed(60 taskToken=task["taskToken"],61 decisions=[62 {63 'decisionType': "CompleteWorkflowExecution",64 'completeWorkflowExecutionDecisionAttributes': {65 'result': 'work flow completed',66 }67 }68 ]69 )70 else:71 swf.respond_decision_task_completed(72 taskToken=task["taskToken"],73 decisions=[74 {75 'decisionType': "ScheduleActivityTask",76 'scheduleActivityTaskDecisionAttributes': {77 'activityType': {78 "name": next_activity["name"],79 "version": next_activity["version"]80 },81 'activityId': str(uuid.uuid4()),82 "input": input_param83 }84 }85 ]86 )87 elif last_event == "ActivityTaskTimedOut":88 swf.respond_decision_task_completed(89 taskToken=task["taskToken"],90 decisions=[91 {92 'decisionType': "FailWorkflowExecution",93 'failWorkflowExecutionDecisionAttributes': {94 'reason': 'task timeout',95 'details': 'string'96 }97 }98 ]99 )100 elif last_event == "ActivityTaskFailed":101 swf.respond_decision_task_completed(102 taskToken=task["taskToken"],103 decisions=[104 {105 'decisionType': "FailWorkflowExecution",106 'failWorkflowExecutionDecisionAttributes': {107 'reason': 'task failed',108 'details': 'string'109 }110 }111 ]112 )113 elif last_event["eventType"] == "WorkflowExecutionCompleted":...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful