| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  | from boto.swf.exceptions import SWFResponseError | 
					
						
							| 
									
										
										
										
											2015-10-31 21:13:44 +01:00
										 |  |  | from freezegun import freeze_time | 
					
						
							| 
									
										
										
										
											2018-01-20 19:44:22 -08:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | from moto import mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | from moto.swf import swf_backend | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 18:05:45 +01:00
										 |  |  | from ..utils import setup_workflow | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # PollForDecisionTask endpoint | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | def test_poll_for_decision_task_when_one(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							|  |  |  |     types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue", identity="srv01") | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     types.should.equal( | 
					
						
							|  |  |  |         ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal( | 
					
						
							|  |  |  |         "srv01" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 01:08:03 +10:00
										 |  |  | @mock_swf_deprecated | 
					
						
							|  |  |  | def test_poll_for_decision_task_previous_started_event_id(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     assert resp["workflowExecution"]["runId"] == conn.run_id | 
					
						
							|  |  |  |     assert "previousStartedEventId" not in resp | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Require a failing decision, in this case a non-existant activity type | 
					
						
							|  |  |  |     attrs = { | 
					
						
							|  |  |  |         "activityId": "spam", | 
					
						
							|  |  |  |         "activityType": {"name": "test-activity", "version": "v1.42"}, | 
					
						
							|  |  |  |         "taskList": "eggs", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     decision = { | 
					
						
							|  |  |  |         "decisionType": "ScheduleActivityTask", | 
					
						
							|  |  |  |         "scheduleActivityTaskDecisionAttributes": attrs, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     conn.respond_decision_task_completed(resp["taskToken"], decisions=[decision]) | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     assert resp["workflowExecution"]["runId"] == conn.run_id | 
					
						
							|  |  |  |     assert resp["previousStartedEventId"] == 3 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-11 14:02:55 +02:00
										 |  |  | def test_poll_for_decision_task_when_none(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     # this is the DecisionTask representation you get from the real SWF | 
					
						
							|  |  |  |     # after waiting 60s when there's no decision to be taken | 
					
						
							| 
									
										
										
										
											2020-02-26 00:19:39 +10:00
										 |  |  |     resp.should.equal( | 
					
						
							|  |  |  |         {"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""} | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-11 19:14:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-11 22:11:07 +02:00
										 |  |  | def test_poll_for_decision_task_on_non_existent_queue(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "non-existent-queue") | 
					
						
							| 
									
										
										
										
											2020-02-26 00:19:39 +10:00
										 |  |  |     resp.should.equal( | 
					
						
							|  |  |  |         {"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""} | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-11 22:11:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-11 19:14:31 +02:00
										 |  |  | def test_poll_for_decision_task_with_reverse_order(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True) | 
					
						
							| 
									
										
										
										
											2015-10-11 19:14:31 +02:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     types.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-11 22:14:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # CountPendingDecisionTasks endpoint | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-11 22:14:16 +02:00
										 |  |  | def test_count_pending_decision_tasks(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     resp = conn.count_pending_decision_tasks("test-domain", "queue") | 
					
						
							|  |  |  |     resp.should.equal({"count": 1, "truncated": False}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-11 22:14:16 +02:00
										 |  |  | def test_count_pending_decision_tasks_on_non_existent_task_list(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.count_pending_decision_tasks("test-domain", "non-existent") | 
					
						
							|  |  |  |     resp.should.equal({"count": 0, "truncated": False}) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-24 12:05:42 +02:00
										 |  |  | def test_count_pending_decision_tasks_after_decision_completes(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     conn.respond_decision_task_completed(resp["taskToken"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.count_pending_decision_tasks("test-domain", "queue") | 
					
						
							|  |  |  |     resp.should.equal({"count": 0, "truncated": False}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # RespondDecisionTaskCompleted endpoint | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | def test_respond_decision_task_completed_with_no_decision(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 21:13:44 +01:00
										 |  |  |     resp = conn.respond_decision_task_completed( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         task_token, execution_context="free-form context" | 
					
						
							| 
									
										
										
										
											2015-10-31 21:13:44 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  |     resp.should.be.none | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     types.should.equal( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             "WorkflowExecutionStarted", | 
					
						
							|  |  |  |             "DecisionTaskScheduled", | 
					
						
							|  |  |  |             "DecisionTaskStarted", | 
					
						
							|  |  |  |             "DecisionTaskCompleted", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  |     evt = resp["events"][-1] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     evt["decisionTaskCompletedEventAttributes"].should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "executionContext": "free-form context", | 
					
						
							|  |  |  |             "scheduledEventId": 2, | 
					
						
							|  |  |  |             "startedEventId": 3, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234") | 
					
						
							| 
									
										
										
										
											2015-10-31 21:13:44 +01:00
										 |  |  |     resp["latestExecutionContext"].should.equal("free-form context") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | def test_respond_decision_task_completed_with_wrong_token(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  |     conn.respond_decision_task_completed.when.called_with( | 
					
						
							|  |  |  |         "not-a-correct-token" | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ).should.throw(SWFResponseError) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | def test_respond_decision_task_completed_on_close_workflow_execution(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     # bad: we're closing workflow execution manually, but endpoints are not | 
					
						
							|  |  |  |     # coded for now.. | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     wfe = swf_backend.domains[0].workflow_executions[-1] | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  |     wfe.execution_status = "CLOSED" | 
					
						
							|  |  |  |     # /bad | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.respond_decision_task_completed.when.called_with(task_token).should.throw( | 
					
						
							|  |  |  |         SWFResponseError | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | def test_respond_decision_task_completed_with_task_already_completed(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  |     conn.respond_decision_task_completed(task_token) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.respond_decision_task_completed.when.called_with(task_token).should.throw( | 
					
						
							|  |  |  |         SWFResponseError | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 23:32:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-12 23:32:11 +02:00
										 |  |  | def test_respond_decision_task_completed_with_complete_workflow_execution(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     decisions = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "decisionType": "CompleteWorkflowExecution", | 
					
						
							|  |  |  |             "completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"}, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     resp = conn.respond_decision_task_completed(task_token, decisions=decisions) | 
					
						
							| 
									
										
										
										
											2015-10-12 23:32:11 +02:00
										 |  |  |     resp.should.be.none | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 23:32:11 +02:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     types.should.equal( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             "WorkflowExecutionStarted", | 
					
						
							|  |  |  |             "DecisionTaskScheduled", | 
					
						
							|  |  |  |             "DecisionTaskStarted", | 
					
						
							|  |  |  |             "DecisionTaskCompleted", | 
					
						
							|  |  |  |             "WorkflowExecutionCompleted", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     resp["events"][-1]["workflowExecutionCompletedEventAttributes"][ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "result" | 
					
						
							|  |  |  |     ].should.equal("foo bar") | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | def test_respond_decision_task_completed_with_close_decision_not_last(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     decisions = [ | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |         {"decisionType": "CompleteWorkflowExecution"}, | 
					
						
							|  |  |  |         {"decisionType": "WeDontCare"}, | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.respond_decision_task_completed.when.called_with( | 
					
						
							|  |  |  |         task_token, decisions=decisions | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ).should.throw(SWFResponseError, r"Close must be last decision in list") | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | def test_respond_decision_task_completed_with_invalid_decision_type(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     decisions = [ | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |         {"decisionType": "BadDecisionType"}, | 
					
						
							|  |  |  |         {"decisionType": "CompleteWorkflowExecution"}, | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.respond_decision_task_completed.when.called_with( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         task_token, decisions=decisions | 
					
						
							|  |  |  |     ).should.throw( | 
					
						
							|  |  |  |         SWFResponseError, | 
					
						
							|  |  |  |         r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'", | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 09:25:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-19 09:25:54 +02:00
										 |  |  | def test_respond_decision_task_completed_with_missing_attributes(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     decisions = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "decisionType": "should trigger even with incorrect decision type", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "startTimerDecisionAttributes": {}, | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-10-19 09:25:54 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.respond_decision_task_completed.when.called_with( | 
					
						
							|  |  |  |         task_token, decisions=decisions | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     ).should.throw( | 
					
						
							|  |  |  |         SWFResponseError, | 
					
						
							|  |  |  |         r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' " | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         r"failed to satisfy constraint: Member must not be null", | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 09:25:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-19 09:25:54 +02:00
										 |  |  | def test_respond_decision_task_completed_with_missing_attributes_totally(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     decisions = [{"decisionType": "StartTimer"}] | 
					
						
							| 
									
										
										
										
											2015-10-19 09:25:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.respond_decision_task_completed.when.called_with( | 
					
						
							|  |  |  |         task_token, decisions=decisions | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     ).should.throw( | 
					
						
							|  |  |  |         SWFResponseError, | 
					
						
							|  |  |  |         r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' " | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         r"failed to satisfy constraint: Member must not be null", | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 04:35:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-24 04:35:21 +02:00
										 |  |  | def test_respond_decision_task_completed_with_fail_workflow_execution(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     decisions = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "decisionType": "FailWorkflowExecution", | 
					
						
							|  |  |  |             "failWorkflowExecutionDecisionAttributes": { | 
					
						
							|  |  |  |                 "reason": "my rules", | 
					
						
							|  |  |  |                 "details": "foo", | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     resp = conn.respond_decision_task_completed(task_token, decisions=decisions) | 
					
						
							| 
									
										
										
										
											2015-10-24 04:35:21 +02:00
										 |  |  |     resp.should.be.none | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-24 04:35:21 +02:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     types.should.equal( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             "WorkflowExecutionStarted", | 
					
						
							|  |  |  |             "DecisionTaskScheduled", | 
					
						
							|  |  |  |             "DecisionTaskStarted", | 
					
						
							|  |  |  |             "DecisionTaskCompleted", | 
					
						
							|  |  |  |             "WorkflowExecutionFailed", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-24 04:35:21 +02:00
										 |  |  |     attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"] | 
					
						
							|  |  |  |     attrs["reason"].should.equal("my rules") | 
					
						
							|  |  |  |     attrs["details"].should.equal("foo") | 
					
						
							| 
									
										
										
										
											2015-10-26 00:43:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-10-31 21:13:44 +01:00
										 |  |  | @freeze_time("2015-01-01 12:00:00") | 
					
						
							| 
									
										
										
										
											2015-10-26 00:43:35 +01:00
										 |  |  | def test_respond_decision_task_completed_with_schedule_activity_task(): | 
					
						
							|  |  |  |     conn = setup_workflow() | 
					
						
							|  |  |  |     resp = conn.poll_for_decision_task("test-domain", "queue") | 
					
						
							|  |  |  |     task_token = resp["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     decisions = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "decisionType": "ScheduleActivityTask", | 
					
						
							|  |  |  |             "scheduleActivityTaskDecisionAttributes": { | 
					
						
							|  |  |  |                 "activityId": "my-activity-001", | 
					
						
							|  |  |  |                 "activityType": {"name": "test-activity", "version": "v1.1"}, | 
					
						
							|  |  |  |                 "heartbeatTimeout": "60", | 
					
						
							|  |  |  |                 "input": "123", | 
					
						
							|  |  |  |                 "taskList": {"name": "my-task-list"}, | 
					
						
							| 
									
										
										
										
											2015-10-26 00:43:35 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ] | 
					
						
							|  |  |  |     resp = conn.respond_decision_task_completed(task_token, decisions=decisions) | 
					
						
							| 
									
										
										
										
											2015-10-26 00:43:35 +01:00
										 |  |  |     resp.should.be.none | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-26 00:43:35 +01:00
										 |  |  |     types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     types.should.equal( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             "WorkflowExecutionStarted", | 
					
						
							|  |  |  |             "DecisionTaskScheduled", | 
					
						
							|  |  |  |             "DecisionTaskStarted", | 
					
						
							|  |  |  |             "DecisionTaskCompleted", | 
					
						
							|  |  |  |             "ActivityTaskScheduled", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     resp["events"][-1]["activityTaskScheduledEventAttributes"].should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "decisionTaskCompletedEventId": 4, | 
					
						
							|  |  |  |             "activityId": "my-activity-001", | 
					
						
							|  |  |  |             "activityType": {"name": "test-activity", "version": "v1.1"}, | 
					
						
							|  |  |  |             "heartbeatTimeout": "60", | 
					
						
							|  |  |  |             "input": "123", | 
					
						
							|  |  |  |             "taskList": {"name": "my-task-list"}, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234") | 
					
						
							| 
									
										
										
										
											2015-11-03 09:09:00 +01:00
										 |  |  |     resp["latestActivityTaskTimestamp"].should.equal(1420113600.0) |