| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  | from collections import namedtuple | 
					
						
							| 
									
										
										
										
											2018-01-20 19:44:22 -08:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  | from moto.swf.exceptions import SWFUnknownResourceFault | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | from moto.swf.models import Domain | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  | # Ensure 'assert_raises' context manager support for Python 2.6 | 
					
						
							|  |  |  | import tests.backport_assert_raises  # noqa | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  | # Fake WorkflowExecution for tests purposes | 
					
						
							|  |  |  | WorkflowExecution = namedtuple( | 
					
						
							|  |  |  |     "WorkflowExecution", | 
					
						
							| 
									
										
										
										
											2015-11-04 22:35:45 +01:00
										 |  |  |     ["workflow_id", "run_id", "execution_status", "open"] | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | def test_domain_short_dict_representation(): | 
					
						
							|  |  |  |     domain = Domain("foo", "52") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     domain.to_short_dict().should.equal( | 
					
						
							|  |  |  |         {"name": "foo", "status": "REGISTERED"}) | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     domain.description = "foo bar" | 
					
						
							|  |  |  |     domain.to_short_dict()["description"].should.equal("foo bar") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | def test_domain_full_dict_representation(): | 
					
						
							|  |  |  |     domain = Domain("foo", "52") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     domain.to_full_dict()["domainInfo"].should.equal(domain.to_short_dict()) | 
					
						
							|  |  |  |     _config = domain.to_full_dict()["configuration"] | 
					
						
							|  |  |  |     _config["workflowExecutionRetentionPeriodInDays"].should.equal("52") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | def test_domain_string_representation(): | 
					
						
							|  |  |  |     domain = Domain("my-domain", "60") | 
					
						
							|  |  |  |     str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  | def test_domain_add_to_activity_task_list(): | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  |     domain = Domain("my-domain", "60") | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  |     domain.add_to_activity_task_list("foo", "bar") | 
					
						
							|  |  |  |     domain.activity_task_lists.should.equal({ | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  |         "foo": ["bar"] | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  | def test_domain_activity_tasks(): | 
					
						
							|  |  |  |     domain = Domain("my-domain", "60") | 
					
						
							|  |  |  |     domain.add_to_activity_task_list("foo", "bar") | 
					
						
							|  |  |  |     domain.add_to_activity_task_list("other", "baz") | 
					
						
							| 
									
										
										
										
											2015-11-03 10:56:31 +01:00
										 |  |  |     sorted(domain.activity_tasks).should.equal(["bar", "baz"]) | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  | def test_domain_add_to_decision_task_list(): | 
					
						
							|  |  |  |     domain = Domain("my-domain", "60") | 
					
						
							|  |  |  |     domain.add_to_decision_task_list("foo", "bar") | 
					
						
							|  |  |  |     domain.decision_task_lists.should.equal({ | 
					
						
							|  |  |  |         "foo": ["bar"] | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 10:55:55 +01:00
										 |  |  | def test_domain_decision_tasks(): | 
					
						
							|  |  |  |     domain = Domain("my-domain", "60") | 
					
						
							|  |  |  |     domain.add_to_decision_task_list("foo", "bar") | 
					
						
							|  |  |  |     domain.add_to_decision_task_list("other", "baz") | 
					
						
							| 
									
										
										
										
											2015-11-03 10:56:31 +01:00
										 |  |  |     sorted(domain.decision_tasks).should.equal(["bar", "baz"]) | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  | def test_domain_get_workflow_execution(): | 
					
						
							|  |  |  |     domain = Domain("my-domain", "60") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     wfe1 = WorkflowExecution( | 
					
						
							|  |  |  |         workflow_id="wf-id-1", run_id="run-id-1", execution_status="OPEN", open=True) | 
					
						
							|  |  |  |     wfe2 = WorkflowExecution( | 
					
						
							|  |  |  |         workflow_id="wf-id-1", run_id="run-id-2", execution_status="CLOSED", open=False) | 
					
						
							|  |  |  |     wfe3 = WorkflowExecution( | 
					
						
							|  |  |  |         workflow_id="wf-id-2", run_id="run-id-3", execution_status="OPEN", open=True) | 
					
						
							|  |  |  |     wfe4 = WorkflowExecution( | 
					
						
							|  |  |  |         workflow_id="wf-id-3", run_id="run-id-4", execution_status="CLOSED", open=False) | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     domain.workflow_executions = [wfe1, wfe2, wfe3, wfe4] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # get workflow execution through workflow_id and run_id | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     domain.get_workflow_execution( | 
					
						
							|  |  |  |         "wf-id-1", run_id="run-id-1").should.equal(wfe1) | 
					
						
							|  |  |  |     domain.get_workflow_execution( | 
					
						
							|  |  |  |         "wf-id-1", run_id="run-id-2").should.equal(wfe2) | 
					
						
							|  |  |  |     domain.get_workflow_execution( | 
					
						
							|  |  |  |         "wf-id-3", run_id="run-id-4").should.equal(wfe4) | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     domain.get_workflow_execution.when.called_with( | 
					
						
							|  |  |  |         "wf-id-1", run_id="non-existent" | 
					
						
							|  |  |  |     ).should.throw( | 
					
						
							|  |  |  |         SWFUnknownResourceFault, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # get OPEN workflow execution by default if no run_id | 
					
						
							|  |  |  |     domain.get_workflow_execution("wf-id-1").should.equal(wfe1) | 
					
						
							|  |  |  |     domain.get_workflow_execution.when.called_with( | 
					
						
							|  |  |  |         "wf-id-3" | 
					
						
							|  |  |  |     ).should.throw( | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |         SWFUnknownResourceFault | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |     domain.get_workflow_execution.when.called_with( | 
					
						
							|  |  |  |         "wf-id-non-existent" | 
					
						
							|  |  |  |     ).should.throw( | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |         SWFUnknownResourceFault | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # raise_if_closed attribute | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     domain.get_workflow_execution( | 
					
						
							|  |  |  |         "wf-id-1", run_id="run-id-1", raise_if_closed=True).should.equal(wfe1) | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     domain.get_workflow_execution.when.called_with( | 
					
						
							|  |  |  |         "wf-id-3", run_id="run-id-4", raise_if_closed=True | 
					
						
							|  |  |  |     ).should.throw( | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |         SWFUnknownResourceFault | 
					
						
							| 
									
										
										
										
											2015-11-01 21:55:07 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-11-01 22:23:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # raise_if_none attribute | 
					
						
							|  |  |  |     domain.get_workflow_execution("foo", raise_if_none=False).should.be.none |