Reorganize SWF tests so they're shorter and easier to use
This commit is contained in:
parent
a713005882
commit
eadc07bf61
14 changed files with 180 additions and 168 deletions
0
tests/test_swf/responses/__init__.py
Normal file
0
tests/test_swf/responses/__init__.py
Normal file
126
tests/test_swf/responses/test_activity_types.py
Normal file
126
tests/test_swf/responses/test_activity_types.py
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
import boto
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_swf
|
||||
from moto.swf.exceptions import (
|
||||
SWFUnknownResourceFault,
|
||||
SWFTypeAlreadyExistsFault,
|
||||
SWFTypeDeprecatedFault,
|
||||
SWFSerializationException,
|
||||
)
|
||||
|
||||
|
||||
# RegisterActivityType endpoint
|
||||
@mock_swf
|
||||
def test_register_activity_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "test-activity", "v1.0")
|
||||
|
||||
types = conn.list_activity_types("test-domain", "REGISTERED")
|
||||
actype = types["typeInfos"][0]
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "test-activity", "v1.0")
|
||||
|
||||
conn.register_activity_type.when.called_with(
|
||||
"test-domain", "test-activity", "v1.0"
|
||||
).should.throw(SWFTypeAlreadyExistsFault)
|
||||
|
||||
@mock_swf
|
||||
def test_register_with_wrong_parameter_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
|
||||
conn.register_activity_type.when.called_with(
|
||||
"test-domain", "test-activity", 12
|
||||
).should.throw(SWFSerializationException)
|
||||
|
||||
# ListActivityTypes endpoint
|
||||
@mock_swf
|
||||
def test_list_activity_types():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "b-test-activity", "v1.0")
|
||||
conn.register_activity_type("test-domain", "a-test-activity", "v1.0")
|
||||
conn.register_activity_type("test-domain", "c-test-activity", "v1.0")
|
||||
|
||||
all_activity_types = conn.list_activity_types("test-domain", "REGISTERED")
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "b-test-activity", "v1.0")
|
||||
conn.register_activity_type("test-domain", "a-test-activity", "v1.0")
|
||||
conn.register_activity_type("test-domain", "c-test-activity", "v1.0")
|
||||
|
||||
all_activity_types = conn.list_activity_types("test-domain", "REGISTERED",
|
||||
reverse_order=True)
|
||||
names = [activity_type["activityType"]["name"] for activity_type in all_activity_types["typeInfos"]]
|
||||
names.should.equal(["c-test-activity", "b-test-activity", "a-test-activity"])
|
||||
|
||||
|
||||
# DeprecateActivityType endpoint
|
||||
@mock_swf
|
||||
def test_deprecate_activity_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "test-activity", "v1.0")
|
||||
conn.deprecate_activity_type("test-domain", "test-activity", "v1.0")
|
||||
|
||||
actypes = conn.list_activity_types("test-domain", "DEPRECATED")
|
||||
actype = actypes["typeInfos"][0]
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "test-activity", "v1.0")
|
||||
conn.deprecate_activity_type("test-domain", "test-activity", "v1.0")
|
||||
|
||||
conn.deprecate_activity_type.when.called_with(
|
||||
"test-domain", "test-activity", "v1.0"
|
||||
).should.throw(SWFTypeDeprecatedFault)
|
||||
|
||||
@mock_swf
|
||||
def test_deprecate_non_existent_activity_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
|
||||
conn.deprecate_activity_type.when.called_with(
|
||||
"test-domain", "non-existent", "v1.0"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
|
||||
# DescribeActivityType endpoint
|
||||
@mock_swf
|
||||
def test_describe_activity_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_activity_type("test-domain", "test-activity", "v1.0",
|
||||
task_list="foo", default_task_heartbeat_timeout="32")
|
||||
|
||||
actype = conn.describe_activity_type("test-domain", "test-activity", "v1.0")
|
||||
actype["configuration"]["defaultTaskList"]["name"].should.equal("foo")
|
||||
infos = actype["typeInfo"]
|
||||
infos["activityType"]["name"].should.equal("test-activity")
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
|
||||
conn.describe_activity_type.when.called_with(
|
||||
"test-domain", "non-existent", "v1.0"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
321
tests/test_swf/responses/test_decision_tasks.py
Normal file
321
tests/test_swf/responses/test_decision_tasks.py
Normal file
|
|
@ -0,0 +1,321 @@
|
|||
import boto
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_swf
|
||||
from moto.swf import swf_backend
|
||||
from moto.swf.exceptions import (
|
||||
SWFUnknownResourceFault,
|
||||
SWFValidationException,
|
||||
SWFDecisionValidationException,
|
||||
)
|
||||
|
||||
from ..utils import mock_basic_workflow_type
|
||||
|
||||
|
||||
@mock_swf
|
||||
def setup_workflow():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn = mock_basic_workflow_type("test-domain", conn)
|
||||
conn.register_activity_type(
|
||||
"test-domain", "test-activity", "v1.1",
|
||||
default_task_heartbeat_timeout="600",
|
||||
default_task_schedule_to_close_timeout="600",
|
||||
default_task_schedule_to_start_timeout="600",
|
||||
default_task_start_to_close_timeout="600",
|
||||
)
|
||||
wfe = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
|
||||
conn.run_id = wfe["runId"]
|
||||
return conn
|
||||
|
||||
|
||||
# PollForDecisionTask endpoint
|
||||
@mock_swf
|
||||
def test_poll_for_decision_task_when_one():
|
||||
conn = setup_workflow()
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
|
||||
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue", identity="srv01")
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"])
|
||||
|
||||
resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal("srv01")
|
||||
|
||||
@mock_swf
|
||||
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
|
||||
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()
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True)
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
types.should.equal(["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"])
|
||||
|
||||
|
||||
# CountPendingDecisionTasks endpoint
|
||||
@mock_swf
|
||||
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})
|
||||
|
||||
@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()
|
||||
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})
|
||||
|
||||
|
||||
# RespondDecisionTaskCompleted endpoint
|
||||
@mock_swf
|
||||
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"]
|
||||
|
||||
resp = conn.respond_decision_task_completed(task_token)
|
||||
resp.should.be.none
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
types.should.equal([
|
||||
"WorkflowExecutionStarted",
|
||||
"DecisionTaskScheduled",
|
||||
"DecisionTaskStarted",
|
||||
"DecisionTaskCompleted",
|
||||
])
|
||||
evt = resp["events"][-1]
|
||||
evt["decisionTaskCompletedEventAttributes"].should.equal({
|
||||
"scheduledEventId": 2,
|
||||
"startedEventId": 3,
|
||||
})
|
||||
|
||||
@mock_swf
|
||||
def test_respond_decision_task_completed_with_wrong_token():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue")
|
||||
conn.respond_decision_task_completed.when.called_with(
|
||||
"not-a-correct-token"
|
||||
).should.throw(SWFValidationException)
|
||||
|
||||
@mock_swf
|
||||
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"]
|
||||
|
||||
# bad: we're closing workflow execution manually, but endpoints are not coded for now..
|
||||
wfe = swf_backend.domains[0].workflow_executions.values()[0]
|
||||
wfe.execution_status = "CLOSED"
|
||||
# /bad
|
||||
|
||||
conn.respond_decision_task_completed.when.called_with(
|
||||
task_token
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
|
||||
@mock_swf
|
||||
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)
|
||||
|
||||
conn.respond_decision_task_completed.when.called_with(
|
||||
task_token
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
|
||||
@mock_swf
|
||||
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"]
|
||||
|
||||
decisions = [{
|
||||
"decisionType": "CompleteWorkflowExecution",
|
||||
"completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"}
|
||||
}]
|
||||
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
|
||||
resp.should.be.none
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
types.should.equal([
|
||||
"WorkflowExecutionStarted",
|
||||
"DecisionTaskScheduled",
|
||||
"DecisionTaskStarted",
|
||||
"DecisionTaskCompleted",
|
||||
"WorkflowExecutionCompleted",
|
||||
])
|
||||
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()
|
||||
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'"
|
||||
)
|
||||
|
||||
@mock_swf
|
||||
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",
|
||||
"startTimerDecisionAttributes": {}
|
||||
},
|
||||
]
|
||||
|
||||
conn.respond_decision_task_completed.when.called_with(
|
||||
task_token, decisions=decisions
|
||||
).should.throw(
|
||||
SWFDecisionValidationException,
|
||||
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():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue")
|
||||
task_token = resp["taskToken"]
|
||||
|
||||
decisions = [
|
||||
{ "decisionType": "StartTimer" },
|
||||
]
|
||||
|
||||
conn.respond_decision_task_completed.when.called_with(
|
||||
task_token, decisions=decisions
|
||||
).should.throw(
|
||||
SWFDecisionValidationException,
|
||||
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():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue")
|
||||
task_token = resp["taskToken"]
|
||||
|
||||
decisions = [{
|
||||
"decisionType": "FailWorkflowExecution",
|
||||
"failWorkflowExecutionDecisionAttributes": {"reason": "my rules", "details": "foo"}
|
||||
}]
|
||||
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
|
||||
resp.should.be.none
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
types.should.equal([
|
||||
"WorkflowExecutionStarted",
|
||||
"DecisionTaskScheduled",
|
||||
"DecisionTaskStarted",
|
||||
"DecisionTaskCompleted",
|
||||
"WorkflowExecutionFailed",
|
||||
])
|
||||
attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"]
|
||||
attrs["reason"].should.equal("my rules")
|
||||
attrs["details"].should.equal("foo")
|
||||
|
||||
@mock_swf
|
||||
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"]
|
||||
|
||||
decisions = [{
|
||||
"decisionType": "ScheduleActivityTask",
|
||||
"scheduleActivityTaskDecisionAttributes": {
|
||||
"activityId": "my-activity-001",
|
||||
"activityType": {
|
||||
"name": "test-activity",
|
||||
"version": "v1.1"
|
||||
},
|
||||
"heartbeatTimeout": "60",
|
||||
"input": "123",
|
||||
"taskList": {
|
||||
"name": "my-task-list"
|
||||
},
|
||||
}
|
||||
}]
|
||||
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
|
||||
resp.should.be.none
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
|
||||
types = [evt["eventType"] for evt in resp["events"]]
|
||||
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"
|
||||
},
|
||||
})
|
||||
117
tests/test_swf/responses/test_domains.py
Normal file
117
tests/test_swf/responses/test_domains.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
import boto
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_swf
|
||||
from moto.swf.exceptions import (
|
||||
SWFUnknownResourceFault,
|
||||
SWFDomainAlreadyExistsFault,
|
||||
SWFDomainDeprecatedFault,
|
||||
SWFSerializationException,
|
||||
)
|
||||
|
||||
|
||||
# RegisterDomain endpoint
|
||||
@mock_swf
|
||||
def test_register_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
domain = all_domains["domainInfos"][0]
|
||||
|
||||
domain["name"].should.equal("test-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")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
conn.register_domain.when.called_with(
|
||||
"test-domain", "60", description="A test domain"
|
||||
).should.throw(SWFDomainAlreadyExistsFault)
|
||||
|
||||
@mock_swf
|
||||
def test_register_with_wrong_parameter_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.register_domain.when.called_with(
|
||||
"test-domain", 60, description="A test domain"
|
||||
).should.throw(SWFSerializationException)
|
||||
|
||||
|
||||
# ListDomains endpoint
|
||||
@mock_swf
|
||||
def test_list_domains_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
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")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED", reverse_order=True)
|
||||
names = [domain["name"] for domain in all_domains["domainInfos"]]
|
||||
names.should.equal(["c-test-domain", "b-test-domain", "a-test-domain"])
|
||||
|
||||
|
||||
# DeprecateDomain endpoint
|
||||
@mock_swf
|
||||
def test_deprecate_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.deprecate_domain("test-domain")
|
||||
|
||||
all_domains = conn.list_domains("DEPRECATED")
|
||||
domain = all_domains["domainInfos"][0]
|
||||
|
||||
domain["name"].should.equal("test-domain")
|
||||
|
||||
@mock_swf
|
||||
def test_deprecate_already_deprecated_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.deprecate_domain("test-domain")
|
||||
|
||||
conn.deprecate_domain.when.called_with(
|
||||
"test-domain"
|
||||
).should.throw(SWFDomainDeprecatedFault)
|
||||
|
||||
@mock_swf
|
||||
def test_deprecate_non_existent_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.deprecate_domain.when.called_with(
|
||||
"non-existent"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
|
||||
|
||||
# DescribeDomain endpoint
|
||||
@mock_swf
|
||||
def test_describe_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
domain = conn.describe_domain("test-domain")
|
||||
domain["configuration"]["workflowExecutionRetentionPeriodInDays"].should.equal("60")
|
||||
domain["domainInfo"]["description"].should.equal("A test 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")
|
||||
|
||||
conn.describe_domain.when.called_with(
|
||||
"non-existent"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
102
tests/test_swf/responses/test_workflow_executions.py
Normal file
102
tests/test_swf/responses/test_workflow_executions.py
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
import boto
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_swf
|
||||
from moto.swf.exceptions import (
|
||||
SWFWorkflowExecutionAlreadyStartedFault,
|
||||
SWFTypeDeprecatedFault,
|
||||
SWFUnknownResourceFault,
|
||||
)
|
||||
|
||||
|
||||
# Utils
|
||||
@mock_swf
|
||||
def setup_swf_environment():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.register_workflow_type(
|
||||
"test-domain", "test-workflow", "v1.0",
|
||||
task_list="queue", default_child_policy="TERMINATE",
|
||||
default_execution_start_to_close_timeout="300",
|
||||
default_task_start_to_close_timeout="300",
|
||||
)
|
||||
conn.register_activity_type("test-domain", "test-activity", "v1.1")
|
||||
return conn
|
||||
|
||||
|
||||
# StartWorkflowExecution endpoint
|
||||
@mock_swf
|
||||
def test_start_workflow_execution():
|
||||
conn = setup_swf_environment()
|
||||
|
||||
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()
|
||||
conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
|
||||
|
||||
conn.start_workflow_execution.when.called_with(
|
||||
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
|
||||
).should.throw(SWFWorkflowExecutionAlreadyStartedFault)
|
||||
|
||||
@mock_swf
|
||||
def test_start_workflow_execution_on_deprecated_type():
|
||||
conn = setup_swf_environment()
|
||||
conn.deprecate_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
|
||||
conn.start_workflow_execution.when.called_with(
|
||||
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
|
||||
).should.throw(SWFTypeDeprecatedFault)
|
||||
|
||||
|
||||
# DescribeWorkflowExecution endpoint
|
||||
@mock_swf
|
||||
def test_describe_workflow_execution():
|
||||
conn = setup_swf_environment()
|
||||
hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
|
||||
run_id = hsh["runId"]
|
||||
|
||||
wfe = conn.describe_workflow_execution("test-domain", run_id, "uid-abcd1234")
|
||||
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()
|
||||
|
||||
conn.describe_workflow_execution.when.called_with(
|
||||
"test-domain", "wrong-run-id", "wrong-workflow-id"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
|
||||
|
||||
# GetWorkflowExecutionHistory endpoint
|
||||
@mock_swf
|
||||
def test_get_workflow_execution_history():
|
||||
conn = setup_swf_environment()
|
||||
hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
|
||||
run_id = hsh["runId"]
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", run_id, "uid-abcd1234")
|
||||
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()
|
||||
hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
|
||||
run_id = hsh["runId"]
|
||||
|
||||
resp = conn.get_workflow_execution_history("test-domain", run_id, "uid-abcd1234",
|
||||
reverse_order=True)
|
||||
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()
|
||||
|
||||
conn.get_workflow_execution_history.when.called_with(
|
||||
"test-domain", "wrong-run-id", "wrong-workflow-id"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
130
tests/test_swf/responses/test_workflow_types.py
Normal file
130
tests/test_swf/responses/test_workflow_types.py
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
import boto
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_swf
|
||||
from moto.swf.exceptions import (
|
||||
SWFUnknownResourceFault,
|
||||
SWFTypeAlreadyExistsFault,
|
||||
SWFTypeDeprecatedFault,
|
||||
SWFSerializationException,
|
||||
)
|
||||
|
||||
|
||||
# RegisterWorkflowType endpoint
|
||||
@mock_swf
|
||||
def test_register_workflow_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
|
||||
types = conn.list_workflow_types("test-domain", "REGISTERED")
|
||||
actype = types["typeInfos"][0]
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
|
||||
conn.register_workflow_type.when.called_with(
|
||||
"test-domain", "test-workflow", "v1.0"
|
||||
).should.throw(SWFTypeAlreadyExistsFault)
|
||||
|
||||
@mock_swf
|
||||
def test_register_with_wrong_parameter_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
|
||||
conn.register_workflow_type.when.called_with(
|
||||
"test-domain", "test-workflow", 12
|
||||
).should.throw(SWFSerializationException)
|
||||
|
||||
|
||||
# ListWorkflowTypes endpoint
|
||||
@mock_swf
|
||||
def test_list_workflow_types():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "b-test-workflow", "v1.0")
|
||||
conn.register_workflow_type("test-domain", "a-test-workflow", "v1.0")
|
||||
conn.register_workflow_type("test-domain", "c-test-workflow", "v1.0")
|
||||
|
||||
all_workflow_types = conn.list_workflow_types("test-domain", "REGISTERED")
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "b-test-workflow", "v1.0")
|
||||
conn.register_workflow_type("test-domain", "a-test-workflow", "v1.0")
|
||||
conn.register_workflow_type("test-domain", "c-test-workflow", "v1.0")
|
||||
|
||||
all_workflow_types = conn.list_workflow_types("test-domain", "REGISTERED",
|
||||
reverse_order=True)
|
||||
names = [activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"]]
|
||||
names.should.equal(["c-test-workflow", "b-test-workflow", "a-test-workflow"])
|
||||
|
||||
|
||||
# DeprecateWorkflowType endpoint
|
||||
@mock_swf
|
||||
def test_deprecate_workflow_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
conn.deprecate_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
|
||||
actypes = conn.list_workflow_types("test-domain", "DEPRECATED")
|
||||
actype = actypes["typeInfos"][0]
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
conn.deprecate_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
|
||||
conn.deprecate_workflow_type.when.called_with(
|
||||
"test-domain", "test-workflow", "v1.0"
|
||||
).should.throw(SWFTypeDeprecatedFault)
|
||||
|
||||
@mock_swf
|
||||
def test_deprecate_non_existent_workflow_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
|
||||
conn.deprecate_workflow_type.when.called_with(
|
||||
"test-domain", "non-existent", "v1.0"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
|
||||
|
||||
# DescribeWorkflowType endpoint
|
||||
@mock_swf
|
||||
def test_describe_workflow_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60")
|
||||
conn.register_workflow_type("test-domain", "test-workflow", "v1.0",
|
||||
task_list="foo", default_child_policy="TERMINATE")
|
||||
|
||||
actype = conn.describe_workflow_type("test-domain", "test-workflow", "v1.0")
|
||||
actype["configuration"]["defaultTaskList"]["name"].should.equal("foo")
|
||||
actype["configuration"]["defaultChildPolicy"].should.equal("TERMINATE")
|
||||
actype["configuration"].keys().should_not.contain("defaultTaskStartToCloseTimeout")
|
||||
infos = actype["typeInfo"]
|
||||
infos["workflowType"]["name"].should.equal("test-workflow")
|
||||
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")
|
||||
conn.register_domain("test-domain", "60")
|
||||
|
||||
conn.describe_workflow_type.when.called_with(
|
||||
"test-domain", "non-existent", "v1.0"
|
||||
).should.throw(SWFUnknownResourceFault)
|
||||
Loading…
Add table
Add a link
Reference in a new issue