Add SWF endpoint GetWorkflowExecutionHistory and associated HistoryEvent model
This commit is contained in:
parent
3ce5b29356
commit
464aef293c
8 changed files with 173 additions and 11 deletions
0
tests/test_swf/__init__.py
Normal file
0
tests/test_swf/__init__.py
Normal file
|
|
@ -1,9 +1,11 @@
|
|||
from sure import expect
|
||||
from nose.tools import assert_raises
|
||||
from freezegun import freeze_time
|
||||
|
||||
from moto.swf.models import (
|
||||
Domain,
|
||||
GenericType,
|
||||
HistoryEvent,
|
||||
WorkflowType,
|
||||
WorkflowExecution,
|
||||
)
|
||||
|
|
@ -11,15 +13,8 @@ from moto.swf.exceptions import (
|
|||
SWFDefaultUndefinedFault,
|
||||
)
|
||||
|
||||
from .utils import get_basic_workflow_type
|
||||
|
||||
# utils
|
||||
def test_workflow_type():
|
||||
return WorkflowType(
|
||||
"test-workflow", "v1.0",
|
||||
task_list="queue", default_child_policy="ABANDON",
|
||||
default_execution_start_to_close_timeout="300",
|
||||
default_task_start_to_close_timeout="300",
|
||||
)
|
||||
|
||||
# Domain
|
||||
def test_domain_short_dict_representation():
|
||||
|
|
@ -91,7 +86,7 @@ def test_type_string_representation():
|
|||
|
||||
# WorkflowExecution
|
||||
def test_workflow_execution_creation():
|
||||
wft = test_workflow_type()
|
||||
wft = get_basic_workflow_type()
|
||||
wfe = WorkflowExecution(wft, "ab1234", child_policy="TERMINATE")
|
||||
wfe.workflow_type.should.equal(wft)
|
||||
wfe.child_policy.should.equal("TERMINATE")
|
||||
|
|
@ -130,12 +125,12 @@ def test_workflow_execution_creation_child_policy_logic():
|
|||
|
||||
|
||||
def test_workflow_execution_string_representation():
|
||||
wft = test_workflow_type()
|
||||
wft = get_basic_workflow_type()
|
||||
wfe = WorkflowExecution(wft, "ab1234", child_policy="TERMINATE")
|
||||
str(wfe).should.match(r"^WorkflowExecution\(run_id: .*\)")
|
||||
|
||||
def test_workflow_execution_generates_a_random_run_id():
|
||||
wft = test_workflow_type()
|
||||
wft = get_basic_workflow_type()
|
||||
wfe1 = WorkflowExecution(wft, "ab1234", child_policy="TERMINATE")
|
||||
wfe2 = WorkflowExecution(wft, "ab1235", child_policy="TERMINATE")
|
||||
wfe1.run_id.should_not.equal(wfe2.run_id)
|
||||
|
|
@ -194,3 +189,29 @@ def test_workflow_execution_full_dict_representation():
|
|||
"taskList": {"name": "queue"},
|
||||
"taskStartToCloseTimeout": "300",
|
||||
})
|
||||
|
||||
|
||||
# HistoryEvent
|
||||
@freeze_time("2015-01-01 12:00:00")
|
||||
def test_history_event_creation():
|
||||
he = HistoryEvent(123, "DecisionTaskStarted", scheduled_event_id=2)
|
||||
he.event_id.should.equal(123)
|
||||
he.event_type.should.equal("DecisionTaskStarted")
|
||||
he.event_timestamp.should.equal(1420110000.0)
|
||||
|
||||
@freeze_time("2015-01-01 12:00:00")
|
||||
def test_history_event_to_dict_representation():
|
||||
he = HistoryEvent(123, "DecisionTaskStarted", scheduled_event_id=2)
|
||||
he.to_dict().should.equal({
|
||||
"eventId": 123,
|
||||
"eventType": "DecisionTaskStarted",
|
||||
"eventTimestamp": 1420110000.0,
|
||||
"decisionTaskStartedEventAttributes": {
|
||||
"scheduledEventId": 2
|
||||
}
|
||||
})
|
||||
|
||||
def test_history_event_breaks_on_initialization_if_not_implemented():
|
||||
HistoryEvent.when.called_with(
|
||||
123, "UnknownHistoryEvent"
|
||||
).should.throw(NotImplementedError)
|
||||
|
|
|
|||
|
|
@ -90,3 +90,26 @@ def test_describe_non_existent_workflow_execution():
|
|||
"__type": "com.amazonaws.swf.base.model#UnknownResourceFault",
|
||||
"message": "Unknown execution: WorkflowExecution=[workflowId=wrong-workflow-id, runId=wrong-run-id]"
|
||||
})
|
||||
|
||||
|
||||
# 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")
|
||||
resp["events"].should.be.a("list")
|
||||
evt = resp["events"][0]
|
||||
evt["eventType"].should.equal("WorkflowExecutionStarted")
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_get_workflow_execution_history_on_non_existent_workflow_execution():
|
||||
conn = setup_swf_environment()
|
||||
|
||||
with assert_raises(SWFUnknownResourceFault) as err:
|
||||
conn.get_workflow_execution_history("test-domain", "wrong-run-id", "wrong-workflow-id")
|
||||
|
||||
# (the rest is already tested above)
|
||||
|
|
|
|||
24
tests/test_swf/utils.py
Normal file
24
tests/test_swf/utils.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from moto.swf.models import (
|
||||
WorkflowType,
|
||||
)
|
||||
|
||||
|
||||
# A generic test WorkflowType
|
||||
def _generic_workflow_type_attributes():
|
||||
return [
|
||||
"test-workflow", "v1.0"
|
||||
], {
|
||||
"task_list": "queue",
|
||||
"default_child_policy": "ABANDON",
|
||||
"default_execution_start_to_close_timeout": "300",
|
||||
"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)
|
||||
return conn
|
||||
Loading…
Add table
Add a link
Reference in a new issue