Fix style issues

This commit is contained in:
Ian Fillion-de Kiewit 2016-02-02 14:02:37 -05:00
parent ac4ce7d53f
commit 129b4faff8
21 changed files with 244 additions and 163 deletions

View File

@ -4,82 +4,82 @@
# and subsequent docs for each decision type.
DECISIONS_FIELDS = {
"cancelTimerDecisionAttributes": {
"timerId": { "type": "string", "required": True }
"timerId": {"type": "string", "required": True}
},
"cancelWorkflowExecutionDecisionAttributes": {
"details": { "type": "string", "required": False }
"details": {"type": "string", "required": False}
},
"completeWorkflowExecutionDecisionAttributes": {
"result": { "type": "string", "required": False }
"result": {"type": "string", "required": False}
},
"continueAsNewWorkflowExecutionDecisionAttributes": {
"childPolicy": { "type": "string", "required": False },
"executionStartToCloseTimeout": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"lambdaRole": { "type": "string", "required": False },
"tagList": { "type": "string", "array": True, "required": False },
"taskList": { "type": "TaskList", "required": False },
"taskPriority": { "type": "string", "required": False },
"taskStartToCloseTimeout": { "type": "string", "required": False },
"workflowTypeVersion": { "type": "string", "required": False }
"childPolicy": {"type": "string", "required": False},
"executionStartToCloseTimeout": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"lambdaRole": {"type": "string", "required": False},
"tagList": {"type": "string", "array": True, "required": False},
"taskList": {"type": "TaskList", "required": False},
"taskPriority": {"type": "string", "required": False},
"taskStartToCloseTimeout": {"type": "string", "required": False},
"workflowTypeVersion": {"type": "string", "required": False}
},
"failWorkflowExecutionDecisionAttributes": {
"details": { "type": "string", "required": False },
"reason": { "type": "string", "required": False }
"details": {"type": "string", "required": False},
"reason": {"type": "string", "required": False}
},
"recordMarkerDecisionAttributes": {
"details": { "type": "string", "required": False },
"markerName": { "type": "string", "required": True }
"details": {"type": "string", "required": False},
"markerName": {"type": "string", "required": True}
},
"requestCancelActivityTaskDecisionAttributes": {
"activityId": { "type": "string", "required": True }
"activityId": {"type": "string", "required": True}
},
"requestCancelExternalWorkflowExecutionDecisionAttributes": {
"control": { "type": "string", "required": False },
"runId": { "type": "string", "required": False },
"workflowId": { "type": "string", "required": True }
"control": {"type": "string", "required": False},
"runId": {"type": "string", "required": False},
"workflowId": {"type": "string", "required": True}
},
"scheduleActivityTaskDecisionAttributes": {
"activityId": { "type": "string", "required": True },
"activityType": { "type": "ActivityType", "required": True },
"control": { "type": "string", "required": False },
"heartbeatTimeout": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"scheduleToCloseTimeout": { "type": "string", "required": False },
"scheduleToStartTimeout": { "type": "string", "required": False },
"startToCloseTimeout": { "type": "string", "required": False },
"taskList": { "type": "TaskList", "required": False },
"taskPriority": { "type": "string", "required": False }
"activityId": {"type": "string", "required": True},
"activityType": {"type": "ActivityType", "required": True},
"control": {"type": "string", "required": False},
"heartbeatTimeout": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"scheduleToCloseTimeout": {"type": "string", "required": False},
"scheduleToStartTimeout": {"type": "string", "required": False},
"startToCloseTimeout": {"type": "string", "required": False},
"taskList": {"type": "TaskList", "required": False},
"taskPriority": {"type": "string", "required": False}
},
"scheduleLambdaFunctionDecisionAttributes": {
"id": { "type": "string", "required": True },
"input": { "type": "string", "required": False },
"name": { "type": "string", "required": True },
"startToCloseTimeout": { "type": "string", "required": False }
"id": {"type": "string", "required": True},
"input": {"type": "string", "required": False},
"name": {"type": "string", "required": True},
"startToCloseTimeout": {"type": "string", "required": False}
},
"signalExternalWorkflowExecutionDecisionAttributes": {
"control": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"runId": { "type": "string", "required": False },
"signalName": { "type": "string", "required": True },
"workflowId": { "type": "string", "required": True }
"control": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"runId": {"type": "string", "required": False},
"signalName": {"type": "string", "required": True},
"workflowId": {"type": "string", "required": True}
},
"startChildWorkflowExecutionDecisionAttributes": {
"childPolicy": { "type": "string", "required": False },
"control": { "type": "string", "required": False },
"executionStartToCloseTimeout": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"lambdaRole": { "type": "string", "required": False },
"tagList": { "type": "string", "array": True, "required": False },
"taskList": { "type": "TaskList", "required": False },
"taskPriority": { "type": "string", "required": False },
"taskStartToCloseTimeout": { "type": "string", "required": False },
"workflowId": { "type": "string", "required": True },
"workflowType": { "type": "WorkflowType", "required": True }
"childPolicy": {"type": "string", "required": False},
"control": {"type": "string", "required": False},
"executionStartToCloseTimeout": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"lambdaRole": {"type": "string", "required": False},
"tagList": {"type": "string", "array": True, "required": False},
"taskList": {"type": "TaskList", "required": False},
"taskPriority": {"type": "string", "required": False},
"taskStartToCloseTimeout": {"type": "string", "required": False},
"workflowId": {"type": "string", "required": True},
"workflowType": {"type": "WorkflowType", "required": True}
},
"startTimerDecisionAttributes": {
"control": { "type": "string", "required": False },
"startToFireTimeout": { "type": "string", "required": True },
"timerId": { "type": "string", "required": True }
"control": {"type": "string", "required": False},
"startToFireTimeout": {"type": "string", "required": True},
"timerId": {"type": "string", "required": True}
}
}

View File

@ -98,13 +98,13 @@ class SWFDecisionValidationException(SWFClientError):
for pb in problems:
if pb["type"] == "null_value":
messages.append(
"Value null at '%(where)s' failed to satisfy constraint: "\
"Value null at '%(where)s' failed to satisfy constraint: "
"Member must not be null" % pb
)
elif pb["type"] == "bad_decision_type":
messages.append(
"Value '%(value)s' at '%(where)s' failed to satisfy constraint: " \
"Member must satisfy enum value set: " \
"Value '%(value)s' at '%(where)s' failed to satisfy constraint: "
"Member must satisfy enum value set: "
"[%(possible_values)s]" % pb
)
else:

View File

@ -1,5 +1,4 @@
from __future__ import unicode_literals
import six
import boto.swf

View File

@ -92,7 +92,7 @@ class Domain(object):
if not wfe and raise_if_none:
if run_id:
args = ["execution", "WorkflowExecution=[workflowId={0}, runId={1}]".format(
workflow_id, run_id)]
workflow_id, run_id)]
else:
args = ["execution, workflowId = {0}".format(workflow_id)]
raise SWFUnknownResourceFault(*args)
@ -100,7 +100,7 @@ class Domain(object):
return wfe
def add_to_activity_task_list(self, task_list, obj):
if not task_list in self.activity_task_lists:
if task_list not in self.activity_task_lists:
self.activity_task_lists[task_list] = []
self.activity_task_lists[task_list].append(obj)
@ -112,7 +112,7 @@ class Domain(object):
return _all
def add_to_decision_task_list(self, task_list, obj):
if not task_list in self.decision_task_lists:
if task_list not in self.decision_task_lists:
self.decision_task_lists[task_list] = []
self.decision_task_lists[task_list].append(obj)

View File

@ -2,8 +2,6 @@ import json
import six
from moto.core.responses import BaseResponse
from werkzeug.exceptions import HTTPException
from moto.core.utils import camelcase_to_underscores, method_names_from_class
from .exceptions import SWFSerializationException
from .models import swf_backends
@ -90,14 +88,14 @@ class SWFResponse(BaseResponse):
self._check_string(retention)
self._check_string(name)
self._check_none_or_string(description)
domain = self.swf_backend.register_domain(name, retention,
description=description)
self.swf_backend.register_domain(name, retention,
description=description)
return ""
def deprecate_domain(self):
name = self._params["name"]
self._check_string(name)
domain = self.swf_backend.deprecate_domain(name)
self.swf_backend.deprecate_domain(name)
return ""
def describe_domain(self):
@ -136,7 +134,7 @@ class SWFResponse(BaseResponse):
self._check_none_or_string(description)
# TODO: add defaultTaskPriority when boto gets to support it
activity_type = self.swf_backend.register_type(
self.swf_backend.register_type(
"activity", domain, name, version, task_list=task_list,
default_task_heartbeat_timeout=default_task_heartbeat_timeout,
default_task_schedule_to_close_timeout=default_task_schedule_to_close_timeout,
@ -180,7 +178,7 @@ class SWFResponse(BaseResponse):
# TODO: add defaultTaskPriority when boto gets to support it
# TODO: add defaultLambdaRole when boto gets to support it
workflow_type = self.swf_backend.register_type(
self.swf_backend.register_type(
"workflow", domain, name, version, task_list=task_list,
default_child_policy=default_child_policy,
default_task_start_to_close_timeout=default_task_start_to_close_timeout,

View File

@ -1,5 +1,4 @@
from freezegun import freeze_time
from sure import expect
from moto.swf.exceptions import SWFWorkflowExecutionClosedError
from moto.swf.models import (
@ -43,9 +42,9 @@ def test_activity_task_creation():
task.fail()
task.state.should.equal("FAILED")
def test_activity_task_full_dict_representation():
wfe = make_workflow_execution()
wft = wfe.workflow_type
at = ActivityTask(
activity_id="my-activity-123",
activity_type=ActivityType("foo", "v1.0"),
@ -68,6 +67,7 @@ def test_activity_task_full_dict_representation():
fd = at.to_full_dict()
fd["startedEventId"].should.equal(1234)
def test_activity_task_reset_heartbeat_clock():
wfe = make_workflow_execution()
@ -88,6 +88,7 @@ def test_activity_task_reset_heartbeat_clock():
task.last_heartbeat_timestamp.should.equal(1420117200.0)
def test_activity_task_first_timeout():
wfe = make_workflow_execution()
@ -109,6 +110,7 @@ def test_activity_task_first_timeout():
task.state.should.equal("TIMED_OUT")
task.timeout_type.should.equal("HEARTBEAT")
def test_activity_task_cannot_timeout_on_closed_workflow_execution():
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution()
@ -130,6 +132,7 @@ def test_activity_task_cannot_timeout_on_closed_workflow_execution():
process_first_timeout(wfe)
task.first_timeout().should.be.none
def test_activity_task_cannot_change_state_on_closed_workflow_execution():
wfe = make_workflow_execution()
wfe.start()

View File

@ -16,6 +16,7 @@ def test_decision_task_creation():
dt.task_token.should_not.be.empty
dt.started_event_id.should.be.none
def test_decision_task_full_dict_representation():
wfe = make_workflow_execution()
wft = wfe.workflow_type
@ -33,6 +34,7 @@ def test_decision_task_full_dict_representation():
fd = dt.to_full_dict()
fd["startedEventId"].should.equal(1234)
def test_decision_task_first_timeout():
wfe = make_workflow_execution()
dt = DecisionTask(wfe, 123)
@ -49,6 +51,7 @@ def test_decision_task_first_timeout():
dt.complete()
dt.first_timeout().should.be.none
def test_decision_task_cannot_timeout_on_closed_workflow_execution():
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution()
@ -64,6 +67,7 @@ def test_decision_task_cannot_timeout_on_closed_workflow_execution():
process_first_timeout(wfe)
dt.first_timeout().should.be.none
def test_decision_task_cannot_change_state_on_closed_workflow_execution():
wfe = make_workflow_execution()
wfe.start()

View File

@ -1,12 +1,10 @@
from collections import namedtuple
from sure import expect
from moto.swf.exceptions import SWFUnknownResourceFault
from moto.swf.models import Domain
# Ensure 'assert_raises' context manager support for Python 2.6
import tests.backport_assert_raises # noqa
from nose.tools import assert_raises
# Fake WorkflowExecution for tests purposes
WorkflowExecution = namedtuple(
@ -17,11 +15,12 @@ WorkflowExecution = namedtuple(
def test_domain_short_dict_representation():
domain = Domain("foo", "52")
domain.to_short_dict().should.equal({"name":"foo", "status":"REGISTERED"})
domain.to_short_dict().should.equal({"name": "foo", "status": "REGISTERED"})
domain.description = "foo bar"
domain.to_short_dict()["description"].should.equal("foo bar")
def test_domain_full_dict_representation():
domain = Domain("foo", "52")
@ -29,10 +28,12 @@ def test_domain_full_dict_representation():
_config = domain.to_full_dict()["configuration"]
_config["workflowExecutionRetentionPeriodInDays"].should.equal("52")
def test_domain_string_representation():
domain = Domain("my-domain", "60")
str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)")
def test_domain_add_to_activity_task_list():
domain = Domain("my-domain", "60")
domain.add_to_activity_task_list("foo", "bar")
@ -40,12 +41,14 @@ def test_domain_add_to_activity_task_list():
"foo": ["bar"]
})
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")
sorted(domain.activity_tasks).should.equal(["bar", "baz"])
def test_domain_add_to_decision_task_list():
domain = Domain("my-domain", "60")
domain.add_to_decision_task_list("foo", "bar")
@ -53,12 +56,14 @@ def test_domain_add_to_decision_task_list():
"foo": ["bar"]
})
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")
sorted(domain.decision_tasks).should.equal(["bar", "baz"])
def test_domain_get_workflow_execution():
domain = Domain("my-domain", "60")

View File

@ -1,5 +1,3 @@
from sure import expect
from moto.swf.models import GenericType
@ -18,6 +16,7 @@ def test_type_short_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_short_dict().should.equal({"name": "test-foo", "version": "v1.0"})
def test_type_medium_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_medium_dict()["fooType"].should.equal(_type.to_short_dict())
@ -32,13 +31,14 @@ def test_type_medium_dict_representation():
_type.status = "DEPRECATED"
_type.to_medium_dict().should.contain("deprecationDate")
def test_type_full_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_full_dict()["typeInfo"].should.equal(_type.to_medium_dict())
_type.to_full_dict()["configuration"].should.equal({})
_type.task_list = "foo"
_type.to_full_dict()["configuration"]["defaultTaskList"].should.equal({"name":"foo"})
_type.to_full_dict()["configuration"]["defaultTaskList"].should.equal({"name": "foo"})
_type.just_an_example_timeout = "60"
_type.to_full_dict()["configuration"]["justAnExampleTimeout"].should.equal("60")
@ -47,6 +47,7 @@ def test_type_full_dict_representation():
keys = _type.to_full_dict()["configuration"].keys()
sorted(keys).should.equal(["defaultTaskList", "justAnExampleTimeout"])
def test_type_string_representation():
_type = FooType("test-foo", "v1.0")
str(_type).should.equal("FooType(name: test-foo, version: v1.0, status: REGISTERED)")

View File

@ -1,4 +1,3 @@
from sure import expect
from freezegun import freeze_time
from moto.swf.models import HistoryEvent
@ -11,6 +10,7 @@ def test_history_event_creation():
he.event_type.should.equal("DecisionTaskStarted")
he.event_timestamp.should.equal(1420113600.0)
@freeze_time("2015-01-01 12:00:00")
def test_history_event_to_dict_representation():
he = HistoryEvent(123, "DecisionTaskStarted", scheduled_event_id=2)
@ -23,6 +23,7 @@ def test_history_event_to_dict_representation():
}
})
def test_history_event_breaks_on_initialization_if_not_implemented():
HistoryEvent.when.called_with(
123, "UnknownHistoryEvent"

View File

@ -1,10 +1,10 @@
from freezegun import freeze_time
from sure import expect
from moto.swf.models import Timeout, WorkflowExecution
from moto.swf.models import Timeout
from ..utils import make_workflow_execution
def test_timeout_creation():
wfe = make_workflow_execution()

View File

@ -1,4 +1,3 @@
from sure import expect
from freezegun import freeze_time
from moto.swf.models import (
@ -18,14 +17,15 @@ from ..utils import (
VALID_ACTIVITY_TASK_ATTRIBUTES = {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity", "version": "v1.1" },
"taskList": { "name": "task-list-name" },
"activityType": {"name": "test-activity", "version": "v1.1"},
"taskList": {"name": "task-list-name"},
"scheduleToStartTimeout": "600",
"scheduleToCloseTimeout": "600",
"startToCloseTimeout": "600",
"heartbeatTimeout": "300",
}
def test_workflow_execution_creation():
domain = get_basic_domain()
wft = get_basic_workflow_type()
@ -35,6 +35,7 @@ def test_workflow_execution_creation():
wfe.workflow_type.should.equal(wft)
wfe.child_policy.should.equal("TERMINATE")
def test_workflow_execution_creation_child_policy_logic():
domain = get_basic_domain()
@ -65,10 +66,12 @@ def test_workflow_execution_creation_child_policy_logic():
WorkflowType("test-workflow", "v1.0"), "ab1234"
).should.throw(SWFDefaultUndefinedFault)
def test_workflow_execution_string_representation():
wfe = make_workflow_execution(child_policy="TERMINATE")
str(wfe).should.match(r"^WorkflowExecution\(run_id: .*\)")
def test_workflow_execution_generates_a_random_run_id():
domain = get_basic_domain()
wft = get_basic_workflow_type()
@ -76,6 +79,7 @@ def test_workflow_execution_generates_a_random_run_id():
wfe2 = WorkflowExecution(domain, wft, "ab1235", child_policy="TERMINATE")
wfe1.run_id.should_not.equal(wfe2.run_id)
def test_workflow_execution_short_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
@ -90,6 +94,7 @@ def test_workflow_execution_short_dict_representation():
sd["workflowId"].should.equal("ab1234")
sd.should.contain("runId")
def test_workflow_execution_medium_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
@ -112,6 +117,7 @@ def test_workflow_execution_medium_dict_representation():
md = wfe.to_medium_dict()
md["tagList"].should.equal(["foo", "bar", "baz"])
def test_workflow_execution_full_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
@ -134,12 +140,14 @@ def test_workflow_execution_full_dict_representation():
"taskStartToCloseTimeout": "300",
})
def test_workflow_execution_schedule_decision_task():
wfe = make_workflow_execution()
wfe.open_counts["openDecisionTasks"].should.equal(0)
wfe.schedule_decision_task()
wfe.open_counts["openDecisionTasks"].should.equal(1)
def test_workflow_execution_start_decision_task():
wfe = make_workflow_execution()
wfe.schedule_decision_task()
@ -150,6 +158,7 @@ def test_workflow_execution_start_decision_task():
wfe.events()[-1].event_type.should.equal("DecisionTaskStarted")
wfe.events()[-1].event_attributes["identity"].should.equal("srv01")
def test_workflow_execution_history_events_ids():
wfe = make_workflow_execution()
wfe._add_event("WorkflowExecutionStarted")
@ -158,6 +167,7 @@ def test_workflow_execution_history_events_ids():
ids = [evt.event_id for evt in wfe.events()]
ids.should.equal([1, 2, 3])
@freeze_time("2015-01-01 12:00:00")
def test_workflow_execution_start():
wfe = make_workflow_execution()
@ -169,6 +179,7 @@ def test_workflow_execution_start():
wfe.events()[0].event_type.should.equal("WorkflowExecutionStarted")
wfe.events()[1].event_type.should.equal("DecisionTaskScheduled")
@freeze_time("2015-01-02 12:00:00")
def test_workflow_execution_complete():
wfe = make_workflow_execution()
@ -181,6 +192,7 @@ def test_workflow_execution_complete():
wfe.events()[-1].event_attributes["decisionTaskCompletedEventId"].should.equal(123)
wfe.events()[-1].event_attributes["result"].should.equal("foo")
@freeze_time("2015-01-02 12:00:00")
def test_workflow_execution_fail():
wfe = make_workflow_execution()
@ -194,6 +206,7 @@ def test_workflow_execution_fail():
wfe.events()[-1].event_attributes["details"].should.equal("some details")
wfe.events()[-1].event_attributes["reason"].should.equal("my rules")
@freeze_time("2015-01-01 12:00:00")
def test_workflow_execution_schedule_activity_task():
wfe = make_workflow_execution()
@ -215,6 +228,7 @@ def test_workflow_execution_schedule_activity_task():
task.activity_type.name.should.equal("test-activity")
wfe.domain.activity_task_lists["task-list-name"].should.contain(task)
def test_workflow_execution_schedule_activity_task_without_task_list_should_take_default():
wfe = make_workflow_execution()
wfe.domain.add_type(
@ -222,7 +236,7 @@ def test_workflow_execution_schedule_activity_task_without_task_list_should_take
)
wfe.schedule_activity_task(123, {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity", "version": "v1.2" },
"activityType": {"name": "test-activity", "version": "v1.2"},
"scheduleToStartTimeout": "600",
"scheduleToCloseTimeout": "600",
"startToCloseTimeout": "600",
@ -237,6 +251,7 @@ def test_workflow_execution_schedule_activity_task_without_task_list_should_take
task = wfe.activity_tasks[0]
wfe.domain.activity_task_lists["foobar"].should.contain(task)
def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attributes():
wfe = make_workflow_execution()
at = ActivityType("test-activity", "v1.1")
@ -246,7 +261,7 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
hsh = {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity-does-not-exists", "version": "v1.1" },
"activityType": {"name": "test-activity-does-not-exists", "version": "v1.1"},
}
wfe.schedule_activity_task(123, hsh)
@ -266,7 +281,7 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_TASK_LIST_UNDEFINED")
hsh["taskList"] = { "name": "foobar" }
hsh["taskList"] = {"name": "foobar"}
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
@ -304,29 +319,37 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
wfe.open_counts["openDecisionTasks"].should.equal(0)
wfe.open_counts["openActivityTasks"].should.equal(1)
def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision():
wfe = make_workflow_execution()
wfe.start()
task_token = wfe.decision_tasks[-1].task_token
wfe.start_decision_task(task_token)
wfe.complete_decision_task(task_token,
execution_context="free-form execution context",
decisions=[
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity-does-not-exist", "version": "v1.2" },
}
},
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity-does-not-exist", "version": "v1.2" },
}
},
])
wfe.complete_decision_task(
task_token,
execution_context="free-form execution context",
decisions=[
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": {
"name": "test-activity-does-not-exist",
"version": "v1.2"
},
}
},
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": {
"name": "test-activity-does-not-exist",
"version": "v1.2"
},
}
},
])
wfe.latest_execution_context.should.equal("free-form execution context")
wfe.open_counts["openActivityTasks"].should.equal(0)
@ -336,6 +359,7 @@ def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision
last_events[1].event_type.should.equal("ScheduleActivityTaskFailed")
last_events[2].event_type.should.equal("DecisionTaskScheduled")
def test_workflow_execution_schedule_activity_task_with_same_activity_id():
wfe = make_workflow_execution()
@ -350,6 +374,7 @@ def test_workflow_execution_schedule_activity_task_with_same_activity_id():
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("ACTIVITY_ID_ALREADY_IN_USE")
def test_workflow_execution_start_activity_task():
wfe = make_workflow_execution()
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
@ -360,6 +385,7 @@ def test_workflow_execution_start_activity_task():
wfe.events()[-1].event_type.should.equal("ActivityTaskStarted")
wfe.events()[-1].event_attributes["identity"].should.equal("worker01")
def test_complete_activity_task():
wfe = make_workflow_execution()
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
@ -379,6 +405,7 @@ def test_complete_activity_task():
wfe.open_counts["openActivityTasks"].should.equal(0)
wfe.open_counts["openDecisionTasks"].should.equal(1)
def test_terminate():
wfe = make_workflow_execution()
wfe.schedule_decision_task()
@ -394,6 +421,7 @@ def test_terminate():
# take default child_policy if not provided (as here)
last_event.event_attributes["childPolicy"].should.equal("ABANDON")
def test_first_timeout():
wfe = make_workflow_execution()
wfe.first_timeout().should.be.none
@ -406,6 +434,7 @@ def test_first_timeout():
# 2 hours timeout reached
wfe.first_timeout().should.be.a(Timeout)
# See moto/swf/models/workflow_execution.py "_process_timeouts()" for more details
def test_timeouts_are_processed_in_order_and_reevaluated():
# Let's make a Workflow Execution with the following properties:
@ -420,8 +449,8 @@ def test_timeouts_are_processed_in_order_and_reevaluated():
# - but the last scheduled decision task should *not* timeout (workflow closed)
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution(
execution_start_to_close_timeout=8*60,
task_start_to_close_timeout=5*60,
execution_start_to_close_timeout=8 * 60,
task_start_to_close_timeout=5 * 60,
)
# decision will automatically start
wfe = auto_start_decision_tasks(wfe)

View File

@ -1,7 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
from moto.swf import swf_backend
@ -24,15 +22,17 @@ def test_poll_for_activity_task_when_one():
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted")
resp["events"][-1]["activityTaskStartedEventAttributes"].should.equal(
{ "identity": "surprise", "scheduledEventId": 5 }
{"identity": "surprise", "scheduledEventId": 5}
)
@mock_swf
def test_poll_for_activity_task_when_none():
conn = setup_workflow()
resp = conn.poll_for_activity_task("test-domain", "activity-task-list")
resp.should.equal({"startedEventId": 0})
@mock_swf
def test_poll_for_activity_task_on_non_existent_queue():
conn = setup_workflow()
@ -52,6 +52,7 @@ def test_count_pending_activity_tasks():
resp = conn.count_pending_activity_tasks("test-domain", "activity-task-list")
resp.should.equal({"count": 1, "truncated": False})
@mock_swf
def test_count_pending_decision_tasks_on_non_existent_task_list():
conn = setup_workflow()
@ -75,20 +76,9 @@ def test_respond_activity_task_completed():
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-2]["eventType"].should.equal("ActivityTaskCompleted")
resp["events"][-2]["activityTaskCompletedEventAttributes"].should.equal(
{ "result": "result of the task", "scheduledEventId": 5, "startedEventId": 6 }
{"result": "result of the task", "scheduledEventId": 5, "startedEventId": 6}
)
@mock_swf
def test_respond_activity_task_completed_with_wrong_token():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
conn.poll_for_activity_task("test-domain", "activity-task-list")
conn.respond_activity_task_completed.when.called_with(
"not-a-correct-token"
).should.throw(SWFResponseError, "Invalid token")
@mock_swf
def test_respond_activity_task_completed_on_closed_workflow_execution():
@ -108,6 +98,7 @@ def test_respond_activity_task_completed_on_closed_workflow_execution():
activity_token
).should.throw(SWFResponseError, "WorkflowExecution=")
@mock_swf
def test_respond_activity_task_completed_with_task_already_completed():
conn = setup_workflow()
@ -142,10 +133,11 @@ def test_respond_activity_task_failed():
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-2]["eventType"].should.equal("ActivityTaskFailed")
resp["events"][-2]["activityTaskFailedEventAttributes"].should.equal(
{ "reason": "short reason", "details": "long details",
"scheduledEventId": 5, "startedEventId": 6 }
{"reason": "short reason", "details": "long details",
"scheduledEventId": 5, "startedEventId": 6}
)
@mock_swf
def test_respond_activity_task_completed_with_wrong_token():
# NB: we just test ONE failure case for RespondActivityTaskFailed
@ -175,6 +167,7 @@ def test_record_activity_task_heartbeat():
resp = conn.record_activity_task_heartbeat(activity_token)
resp.should.equal({"cancelRequested": False})
@mock_swf
def test_record_activity_task_heartbeat_with_wrong_token():
conn = setup_workflow()
@ -188,6 +181,7 @@ def test_record_activity_task_heartbeat_with_wrong_token():
"bad-token", details="some progress details"
).should.throw(SWFResponseError)
@mock_swf
def test_record_activity_task_heartbeat_sets_details_in_case_of_timeout():
conn = setup_workflow()

View File

@ -1,6 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from sure import expect
from moto import mock_swf
@ -17,6 +16,7 @@ def test_register_activity_type():
actype["activityType"]["name"].should.equal("test-activity")
actype["activityType"]["version"].should.equal("v1.0")
@mock_swf
def test_register_already_existing_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -27,6 +27,7 @@ def test_register_already_existing_activity_type():
"test-domain", "test-activity", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_register_with_wrong_parameter_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -36,6 +37,7 @@ def test_register_with_wrong_parameter_type():
"test-domain", "test-activity", 12
).should.throw(SWFResponseError)
# ListActivityTypes endpoint
@mock_swf
def test_list_activity_types():
@ -49,6 +51,7 @@ def test_list_activity_types():
names = [activity_type["activityType"]["name"] for activity_type in all_activity_types["typeInfos"]]
names.should.equal(["a-test-activity", "b-test-activity", "c-test-activity"])
@mock_swf
def test_list_activity_types_reverse_order():
conn = boto.connect_swf("the_key", "the_secret")
@ -76,6 +79,7 @@ def test_deprecate_activity_type():
actype["activityType"]["name"].should.equal("test-activity")
actype["activityType"]["version"].should.equal("v1.0")
@mock_swf
def test_deprecate_already_deprecated_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -87,6 +91,7 @@ def test_deprecate_already_deprecated_activity_type():
"test-domain", "test-activity", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_deprecate_non_existent_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -96,6 +101,7 @@ def test_deprecate_non_existent_activity_type():
"test-domain", "non-existent", "v1.0"
).should.throw(SWFResponseError)
# DescribeActivityType endpoint
@mock_swf
def test_describe_activity_type():
@ -111,6 +117,7 @@ def test_describe_activity_type():
infos["activityType"]["version"].should.equal("v1.0")
infos["status"].should.equal("REGISTERED")
@mock_swf
def test_describe_non_existent_activity_type():
conn = boto.connect_swf("the_key", "the_secret")

View File

@ -1,7 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
from moto.swf import swf_backend
@ -24,6 +22,7 @@ def test_poll_for_decision_task_when_one():
resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal("srv01")
@mock_swf
def test_poll_for_decision_task_when_none():
conn = setup_workflow()
@ -34,12 +33,14 @@ def test_poll_for_decision_task_when_none():
# after waiting 60s when there's no decision to be taken
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
@mock_swf
def test_poll_for_decision_task_on_non_existent_queue():
conn = setup_workflow()
resp = conn.poll_for_decision_task("test-domain", "non-existent-queue")
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
@mock_swf
def test_poll_for_decision_task_with_reverse_order():
conn = setup_workflow()
@ -56,12 +57,14 @@ def test_count_pending_decision_tasks():
resp = conn.count_pending_decision_tasks("test-domain", "queue")
resp.should.equal({"count": 1, "truncated": False})
@mock_swf
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})
@mock_swf
def test_count_pending_decision_tasks_after_decision_completes():
conn = setup_workflow()
@ -104,14 +107,16 @@ def test_respond_decision_task_completed_with_no_decision():
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
resp["latestExecutionContext"].should.equal("free-form context")
@mock_swf
def test_respond_decision_task_completed_with_wrong_token():
conn = setup_workflow()
resp = conn.poll_for_decision_task("test-domain", "queue")
conn.poll_for_decision_task("test-domain", "queue")
conn.respond_decision_task_completed.when.called_with(
"not-a-correct-token"
).should.throw(SWFResponseError)
@mock_swf
def test_respond_decision_task_completed_on_close_workflow_execution():
conn = setup_workflow()
@ -127,6 +132,7 @@ def test_respond_decision_task_completed_on_close_workflow_execution():
task_token
).should.throw(SWFResponseError)
@mock_swf
def test_respond_decision_task_completed_with_task_already_completed():
conn = setup_workflow()
@ -138,6 +144,7 @@ def test_respond_decision_task_completed_with_task_already_completed():
task_token
).should.throw(SWFResponseError)
@mock_swf
def test_respond_decision_task_completed_with_complete_workflow_execution():
conn = setup_workflow()
@ -162,6 +169,7 @@ def test_respond_decision_task_completed_with_complete_workflow_execution():
])
resp["events"][-1]["workflowExecutionCompletedEventAttributes"]["result"].should.equal("foo bar")
@mock_swf
def test_respond_decision_task_completed_with_close_decision_not_last():
conn = setup_workflow()
@ -169,14 +177,15 @@ def test_respond_decision_task_completed_with_close_decision_not_last():
task_token = resp["taskToken"]
decisions = [
{ "decisionType": "CompleteWorkflowExecution" },
{ "decisionType": "WeDontCare" },
{"decisionType": "CompleteWorkflowExecution"},
{"decisionType": "WeDontCare"},
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(SWFResponseError, r"Close must be last decision in list")
@mock_swf
def test_respond_decision_task_completed_with_invalid_decision_type():
conn = setup_workflow()
@ -184,16 +193,16 @@ def test_respond_decision_task_completed_with_invalid_decision_type():
task_token = resp["taskToken"]
decisions = [
{ "decisionType": "BadDecisionType" },
{ "decisionType": "CompleteWorkflowExecution" },
{"decisionType": "BadDecisionType"},
{"decisionType": "CompleteWorkflowExecution"},
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
task_token, decisions=decisions).should.throw(
SWFResponseError,
r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'"
)
)
@mock_swf
def test_respond_decision_task_completed_with_missing_attributes():
@ -210,11 +219,12 @@ def test_respond_decision_task_completed_with_missing_attributes():
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' " \
r"failed to satisfy constraint: Member must not be null"
)
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
r"failed to satisfy constraint: Member must not be null"
)
@mock_swf
def test_respond_decision_task_completed_with_missing_attributes_totally():
@ -223,16 +233,17 @@ def test_respond_decision_task_completed_with_missing_attributes_totally():
task_token = resp["taskToken"]
decisions = [
{ "decisionType": "StartTimer" },
{"decisionType": "StartTimer"},
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' " \
r"failed to satisfy constraint: Member must not be null"
)
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
r"failed to satisfy constraint: Member must not be null"
)
@mock_swf
def test_respond_decision_task_completed_with_fail_workflow_execution():
@ -260,6 +271,7 @@ def test_respond_decision_task_completed_with_fail_workflow_execution():
attrs["reason"].should.equal("my rules")
attrs["details"].should.equal("foo")
@mock_swf
@freeze_time("2015-01-01 12:00:00")
def test_respond_decision_task_completed_with_schedule_activity_task():

View File

@ -1,6 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from sure import expect
from moto import mock_swf
@ -18,6 +17,7 @@ def test_register_domain():
domain["status"].should.equal("REGISTERED")
domain["description"].should.equal("A test domain")
@mock_swf
def test_register_already_existing_domain():
conn = boto.connect_swf("the_key", "the_secret")
@ -27,6 +27,7 @@ def test_register_already_existing_domain():
"test-domain", "60", description="A test domain"
).should.throw(SWFResponseError)
@mock_swf
def test_register_with_wrong_parameter_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -48,6 +49,7 @@ def test_list_domains_order():
names = [domain["name"] for domain in all_domains["domainInfos"]]
names.should.equal(["a-test-domain", "b-test-domain", "c-test-domain"])
@mock_swf
def test_list_domains_reverse_order():
conn = boto.connect_swf("the_key", "the_secret")
@ -72,6 +74,7 @@ def test_deprecate_domain():
domain["name"].should.equal("test-domain")
@mock_swf
def test_deprecate_already_deprecated_domain():
conn = boto.connect_swf("the_key", "the_secret")
@ -82,6 +85,7 @@ def test_deprecate_already_deprecated_domain():
"test-domain"
).should.throw(SWFResponseError)
@mock_swf
def test_deprecate_non_existent_domain():
conn = boto.connect_swf("the_key", "the_secret")
@ -103,6 +107,7 @@ def test_describe_domain():
domain["domainInfo"]["name"].should.equal("test-domain")
domain["domainInfo"]["status"].should.equal("REGISTERED")
@mock_swf
def test_describe_non_existent_domain():
conn = boto.connect_swf("the_key", "the_secret")

View File

@ -1,6 +1,4 @@
import boto
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
@ -35,6 +33,7 @@ def test_activity_task_heartbeat_timeout():
resp["events"][-1]["eventType"].should.equal("DecisionTaskScheduled")
# Decision Task Start to Close timeout
# Default value in workflow helpers: 5 mins
@mock_swf
@ -68,6 +67,7 @@ def test_decision_task_start_to_close_timeout():
# checks that event has been emitted at 12:05:00, not 12:05:30
resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0)
# Workflow Execution Start to Close timeout
# Default value in workflow helpers: 2 hours
@mock_swf

View File

@ -3,8 +3,6 @@ from boto.swf.exceptions import SWFResponseError
# Ensure 'assert_raises' context manager support for Python 2.6
import tests.backport_assert_raises # noqa
from nose.tools import assert_raises
from sure import expect
from moto import mock_swf
@ -32,6 +30,7 @@ def test_start_workflow_execution():
wf = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
wf.should.contain("runId")
@mock_swf
def test_start_already_started_workflow_execution():
conn = setup_swf_environment()
@ -41,6 +40,7 @@ def test_start_already_started_workflow_execution():
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_start_workflow_execution_on_deprecated_type():
conn = setup_swf_environment()
@ -62,6 +62,7 @@ def test_describe_workflow_execution():
wfe["executionInfo"]["execution"]["workflowId"].should.equal("uid-abcd1234")
wfe["executionInfo"]["executionStatus"].should.equal("OPEN")
@mock_swf
def test_describe_non_existent_workflow_execution():
conn = setup_swf_environment()
@ -82,6 +83,7 @@ def test_get_workflow_execution_history():
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
@mock_swf
def test_get_workflow_execution_history_with_reverse_order():
conn = setup_swf_environment()
@ -93,6 +95,7 @@ def test_get_workflow_execution_history_with_reverse_order():
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["DecisionTaskScheduled", "WorkflowExecutionStarted"])
@mock_swf
def test_get_workflow_execution_history_on_non_existent_workflow_execution():
conn = setup_swf_environment()
@ -124,6 +127,7 @@ def test_terminate_workflow_execution():
attrs["reason"].should.equal("a more complete reason")
attrs["cause"].should.equal("OPERATOR_INITIATED")
@mock_swf
def test_terminate_workflow_execution_with_wrong_workflow_or_run_id():
conn = setup_swf_environment()
@ -132,7 +136,7 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id():
)["runId"]
# terminate workflow execution
resp = conn.terminate_workflow_execution("test-domain", "uid-abcd1234")
conn.terminate_workflow_execution("test-domain", "uid-abcd1234")
# already closed, with run_id
conn.terminate_workflow_execution.when.called_with(

View File

@ -1,5 +1,4 @@
import boto
from sure import expect
from moto import mock_swf
from boto.swf.exceptions import SWFResponseError
@ -17,6 +16,7 @@ def test_register_workflow_type():
actype["workflowType"]["name"].should.equal("test-workflow")
actype["workflowType"]["version"].should.equal("v1.0")
@mock_swf
def test_register_already_existing_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -27,6 +27,7 @@ def test_register_already_existing_workflow_type():
"test-domain", "test-workflow", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_register_with_wrong_parameter_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -50,6 +51,7 @@ def test_list_workflow_types():
names = [activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"]]
names.should.equal(["a-test-workflow", "b-test-workflow", "c-test-workflow"])
@mock_swf
def test_list_workflow_types_reverse_order():
conn = boto.connect_swf("the_key", "the_secret")
@ -77,6 +79,7 @@ def test_deprecate_workflow_type():
actype["workflowType"]["name"].should.equal("test-workflow")
actype["workflowType"]["version"].should.equal("v1.0")
@mock_swf
def test_deprecate_already_deprecated_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -88,6 +91,7 @@ def test_deprecate_already_deprecated_workflow_type():
"test-domain", "test-workflow", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_deprecate_non_existent_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -115,6 +119,7 @@ def test_describe_workflow_type():
infos["workflowType"]["version"].should.equal("v1.0")
infos["status"].should.equal("REGISTERED")
@mock_swf
def test_describe_non_existent_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")

View File

@ -1,7 +1,6 @@
from __future__ import unicode_literals
import json
import sure
from moto.swf.exceptions import (
SWFClientError,
@ -20,6 +19,7 @@ from moto.swf.models import (
WorkflowType,
)
def test_swf_client_error():
ex = SWFClientError("ASpecificType", "error message")
@ -29,6 +29,7 @@ def test_swf_client_error():
"message": "error message"
})
def test_swf_unknown_resource_fault():
ex = SWFUnknownResourceFault("type", "detail")
@ -38,6 +39,7 @@ def test_swf_unknown_resource_fault():
"message": "Unknown type: detail"
})
def test_swf_unknown_resource_fault_with_only_one_parameter():
ex = SWFUnknownResourceFault("foo bar baz")
@ -47,6 +49,7 @@ def test_swf_unknown_resource_fault_with_only_one_parameter():
"message": "Unknown foo bar baz"
})
def test_swf_domain_already_exists_fault():
ex = SWFDomainAlreadyExistsFault("domain-name")
@ -56,6 +59,7 @@ def test_swf_domain_already_exists_fault():
"message": "domain-name"
})
def test_swf_domain_deprecated_fault():
ex = SWFDomainDeprecatedFault("domain-name")
@ -65,6 +69,7 @@ def test_swf_domain_deprecated_fault():
"message": "domain-name"
})
def test_swf_serialization_exception():
ex = SWFSerializationException("value")
@ -74,6 +79,7 @@ def test_swf_serialization_exception():
"message": "class java.lang.Foo can not be converted to an String (not a real SWF exception ; happened on: value)"
})
def test_swf_type_already_exists_fault():
wft = WorkflowType("wf-name", "wf-version")
ex = SWFTypeAlreadyExistsFault(wft)
@ -84,6 +90,7 @@ def test_swf_type_already_exists_fault():
"message": "WorkflowType=[name=wf-name, version=wf-version]"
})
def test_swf_type_deprecated_fault():
wft = WorkflowType("wf-name", "wf-version")
ex = SWFTypeDeprecatedFault(wft)
@ -94,6 +101,7 @@ def test_swf_type_deprecated_fault():
"message": "WorkflowType=[name=wf-name, version=wf-version]"
})
def test_swf_workflow_execution_already_started_fault():
ex = SWFWorkflowExecutionAlreadyStartedFault()
@ -103,6 +111,7 @@ def test_swf_workflow_execution_already_started_fault():
'message': 'Already Started',
})
def test_swf_default_undefined_fault():
ex = SWFDefaultUndefinedFault("execution_start_to_close_timeout")
@ -112,6 +121,7 @@ def test_swf_default_undefined_fault():
"message": "executionStartToCloseTimeout",
})
def test_swf_validation_exception():
ex = SWFValidationException("Invalid token")
@ -121,14 +131,15 @@ def test_swf_validation_exception():
"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"},
{"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.code.should.equal(400)
@ -137,10 +148,10 @@ def test_swf_decision_validation_error():
msg = ex.get_body()
msg.should.match(r"2 validation errors detected:")
msg.should.match(
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.startToFireTimeout' "\
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"Value 'FooBar' at 'decisions.1.member.decisionType' failed to satisfy constraint: "
r"Member must satisfy enum value set: \[Foo, Bar, Baz\]"
)

View File

@ -15,9 +15,9 @@ from moto.swf.models import (
# intuitive behaviour in moto/swf own tests...
ACTIVITY_TASK_TIMEOUTS = {
"heartbeatTimeout": "300", # 5 mins
"scheduleToStartTimeout": "1800", # 30 mins
"scheduleToStartTimeout": "1800", # 30 mins
"startToCloseTimeout": "1800", # 30 mins
"scheduleToCloseTimeout": "2700", # 45 mins
"scheduleToCloseTimeout": "2700", # 45 mins
}
# Some useful decisions
@ -25,13 +25,14 @@ SCHEDULE_ACTIVITY_TASK_DECISION = {
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity", "version": "v1.1" },
"taskList": { "name": "activity-task-list" },
"activityType": {"name": "test-activity", "version": "v1.1"},
"taskList": {"name": "activity-task-list"},
}
}
for key, value in ACTIVITY_TASK_TIMEOUTS.items():
SCHEDULE_ACTIVITY_TASK_DECISION["scheduleActivityTaskDecisionAttributes"][key] = value
# A test Domain
def get_basic_domain():
return Domain("test-domain", "90")
@ -48,10 +49,12 @@ def _generic_workflow_type_attributes():
"default_task_start_to_close_timeout": "300",
}
def get_basic_workflow_type():
args, kwargs = _generic_workflow_type_attributes()
return WorkflowType(*args, **kwargs)
def mock_basic_workflow_type(domain_name, conn):
args, kwargs = _generic_workflow_type_attributes()
conn.register_workflow_type(domain_name, *args, **kwargs)