| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  | import json | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | from moto.swf.exceptions import ( | 
					
						
							|  |  |  |     SWFClientError, | 
					
						
							|  |  |  |     SWFUnknownResourceFault, | 
					
						
							|  |  |  |     SWFDomainAlreadyExistsFault, | 
					
						
							|  |  |  |     SWFDomainDeprecatedFault, | 
					
						
							|  |  |  |     SWFSerializationException, | 
					
						
							|  |  |  |     SWFTypeAlreadyExistsFault, | 
					
						
							|  |  |  |     SWFTypeDeprecatedFault, | 
					
						
							|  |  |  |     SWFWorkflowExecutionAlreadyStartedFault, | 
					
						
							|  |  |  |     SWFDefaultUndefinedFault, | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  |     SWFValidationException, | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  |     SWFDecisionValidationException, | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | from moto.swf.models import WorkflowType | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_client_error(): | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex = SWFClientError("ASpecificType", "error message") | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         {"__type": "ASpecificType", "message": "error message"} | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_unknown_resource_fault(): | 
					
						
							|  |  |  |     ex = SWFUnknownResourceFault("type", "detail") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#UnknownResourceFault", | 
					
						
							|  |  |  |             "message": "Unknown type: detail", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | def test_swf_unknown_resource_fault_with_only_one_parameter(): | 
					
						
							|  |  |  |     ex = SWFUnknownResourceFault("foo bar baz") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#UnknownResourceFault", | 
					
						
							|  |  |  |             "message": "Unknown foo bar baz", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_domain_already_exists_fault(): | 
					
						
							|  |  |  |     ex = SWFDomainAlreadyExistsFault("domain-name") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#DomainAlreadyExistsFault", | 
					
						
							|  |  |  |             "message": "domain-name", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_domain_deprecated_fault(): | 
					
						
							|  |  |  |     ex = SWFDomainDeprecatedFault("domain-name") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#DomainDeprecatedFault", | 
					
						
							|  |  |  |             "message": "domain-name", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_serialization_exception(): | 
					
						
							|  |  |  |     ex = SWFSerializationException("value") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#SerializationException", | 
					
						
							|  |  |  |             "message": "class java.lang.Foo can not be converted to an String  (not a real SWF exception ; happened on: value)", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_type_already_exists_fault(): | 
					
						
							|  |  |  |     wft = WorkflowType("wf-name", "wf-version") | 
					
						
							|  |  |  |     ex = SWFTypeAlreadyExistsFault(wft) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#TypeAlreadyExistsFault", | 
					
						
							|  |  |  |             "message": "WorkflowType=[name=wf-name, version=wf-version]", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_type_deprecated_fault(): | 
					
						
							|  |  |  |     wft = WorkflowType("wf-name", "wf-version") | 
					
						
							|  |  |  |     ex = SWFTypeDeprecatedFault(wft) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#TypeDeprecatedFault", | 
					
						
							|  |  |  |             "message": "WorkflowType=[name=wf-name, version=wf-version]", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_workflow_execution_already_started_fault(): | 
					
						
							|  |  |  |     ex = SWFWorkflowExecutionAlreadyStartedFault() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#WorkflowExecutionAlreadyStartedFault", | 
					
						
							|  |  |  |             "message": "Already Started", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 10:05:35 +02:00
										 |  |  | def test_swf_default_undefined_fault(): | 
					
						
							|  |  |  |     ex = SWFDefaultUndefinedFault("execution_start_to_close_timeout") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazonaws.swf.base.model#DefaultUndefinedFault", | 
					
						
							|  |  |  |             "message": "executionStartToCloseTimeout", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-12 11:08:52 +02:00
										 |  |  | def test_swf_validation_exception(): | 
					
						
							|  |  |  |     ex = SWFValidationException("Invalid token") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json.loads(ex.get_body()).should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "__type": "com.amazon.coral.validate#ValidationException", | 
					
						
							|  |  |  |             "message": "Invalid token", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | def test_swf_decision_validation_error(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ex = SWFDecisionValidationException( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "type": "null_value", | 
					
						
							|  |  |  |                 "where": "decisions.1.member.startTimerDecisionAttributes.startToFireTimeout", | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "type": "bad_decision_type", | 
					
						
							|  |  |  |                 "value": "FooBar", | 
					
						
							|  |  |  |                 "where": "decisions.1.member.decisionType", | 
					
						
							|  |  |  |                 "possible_values": "Foo, Bar, Baz", | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     ex.code.should.equal(400) | 
					
						
							|  |  |  |     ex.error_type.should.equal("com.amazon.coral.validate#ValidationException") | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 18:00:57 -05:00
										 |  |  |     msg = ex.get_body() | 
					
						
							|  |  |  |     msg.should.match(r"2 validation errors detected:") | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  |     msg.should.match( | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |         r"Value null at 'decisions.1.member.startTimerDecisionAttributes.startToFireTimeout' " | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  |         r"failed to satisfy constraint: Member must not be null;" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     msg.should.match( | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |         r"Value 'FooBar' at 'decisions.1.member.decisionType' failed to satisfy constraint: " | 
					
						
							| 
									
										
										
										
											2015-10-19 00:09:51 +02:00
										 |  |  |         r"Member must satisfy enum value set: \[Foo, Bar, Baz\]" | 
					
						
							|  |  |  |     ) |