Add some basic checks on SWF decisions, more to come later

This commit is contained in:
Jean-Baptiste Barth 2015-10-19 00:09:51 +02:00
commit 0749b30fb4
4 changed files with 160 additions and 1 deletions

View file

@ -6,6 +6,7 @@ from moto.swf import swf_backend
from moto.swf.exceptions import (
SWFUnknownResourceFault,
SWFValidationException,
SWFDecisionValidationException,
)
from .utils import mock_basic_workflow_type
@ -157,3 +158,36 @@ def test_respond_decision_task_completed_with_complete_workflow_execution():
"DecisionTaskCompleted",
"WorkflowExecutionCompleted",
])
@mock_swf
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 = [
{ "decisionType": "CompleteWorkflowExecution" },
{ "decisionType": "WeDontCare" },
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(SWFValidationException, r"Close must be last decision in list")
@mock_swf
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 = [
{ "decisionType": "BadDecisionType" },
{ "decisionType": "CompleteWorkflowExecution" },
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
SWFDecisionValidationException,
r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'"
)

View file

@ -11,6 +11,7 @@ from moto.swf.exceptions import (
SWFWorkflowExecutionAlreadyStartedFault,
SWFDefaultUndefinedFault,
SWFValidationException,
SWFDecisionValidationException,
)
from moto.swf.models import (
WorkflowType,
@ -124,3 +125,28 @@ def test_swf_validation_exception():
"__type": "com.amazon.coral.validate#ValidationException",
"message": "Invalid token",
})
def test_swf_decision_validation_error():
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"},
])
ex.status.should.equal(400)
ex.error_code.should.equal("ValidationException")
ex.body["__type"].should.equal("com.amazon.coral.validate#ValidationException")
msg = ex.body["message"]
msg.should.match(r"^2 validation errors detected:")
msg.should.match(
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.startToFireTimeout' "\
r"failed to satisfy constraint: Member must not be null;"
)
msg.should.match(
r"Value 'FooBar' at 'decisions.1.member.decisionType' failed to satisfy constraint: " \
r"Member must satisfy enum value set: \[Foo, Bar, Baz\]"
)