Add list_open_workflow_executions endpoint

This commit is contained in:
Ian Fillion-de Kiewit 2016-02-04 17:14:33 -05:00
commit 93120927f7
5 changed files with 158 additions and 1 deletions

View file

@ -1,4 +1,5 @@
from freezegun import freeze_time
import sure # noqa
from moto.swf.models import (
ActivityType,
@ -141,6 +142,26 @@ def test_workflow_execution_full_dict_representation():
})
def test_workflow_execution_list_dict_representation():
domain = get_basic_domain()
wf_type = 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',
)
wfe = WorkflowExecution(domain, wf_type, 'ab1234')
ld = wfe.to_list_dict()
ld['workflowType']['version'].should.equal('v1.0')
ld['workflowType']['name'].should.equal('test-workflow')
ld['executionStatus'].should.equal('OPEN')
ld['execution']['workflowId'].should.equal('ab1234')
ld['execution'].should.contain('runId')
ld['cancelRequested'].should.be.false
ld.should.contain('startTimestamp')
def test_workflow_execution_schedule_decision_task():
wfe = make_workflow_execution()
wfe.open_counts["openDecisionTasks"].should.equal(0)

View file

@ -1,10 +1,13 @@
import boto
from boto.swf.exceptions import SWFResponseError
from datetime import datetime, timedelta
import sure # noqa
# Ensure 'assert_raises' context manager support for Python 2.6
import tests.backport_assert_raises # noqa
from moto import mock_swf
from moto.core.utils import iso_8601_datetime_with_milliseconds
# Utils
@ -105,6 +108,50 @@ def test_get_workflow_execution_history_on_non_existent_workflow_execution():
).should.throw(SWFResponseError)
# ListOpenWorkflowExecutions endpoint
@mock_swf
def test_list_open_workflow_executions():
conn = setup_swf_environment()
conn.start_workflow_execution(
'test-domain', 'uid-abcd1234', 'test-workflow', 'v1.0'
)
yesterday = datetime.now() - timedelta(days=1)
oldest_date = iso_8601_datetime_with_milliseconds(yesterday)
response = conn.list_open_workflow_executions('test-domain',
oldest_date,
workflow_id='test-workflow')
execution_infos = response['executionInfos']
len(execution_infos).should.equal(1)
open_workflow = execution_infos[0]
open_workflow['workflowType'].should.equal({'version': 'v1.0',
'name': 'test-workflow'})
open_workflow.should.contain('startTimestamp')
open_workflow['execution']['workflowId'].should.equal('uid-abcd1234')
open_workflow['execution'].should.contain('runId')
open_workflow['cancelRequested'].should.be(False)
open_workflow['executionStatus'].should.equal('OPEN')
@mock_swf
def test_list_open_workflow_executions_does_not_show_closed():
conn = setup_swf_environment()
run_id = conn.start_workflow_execution(
'test-domain', 'uid-abcd1234', 'test-workflow', 'v1.0'
)['runId']
conn.terminate_workflow_execution('test-domain', 'uid-abcd1234',
details='some details',
reason='a more complete reason',
run_id=run_id)
yesterday = datetime.now() - timedelta(days=1)
oldest_date = iso_8601_datetime_with_milliseconds(yesterday)
response = conn.list_open_workflow_executions('test-domain',
oldest_date,
workflow_id='test-workflow')
response['executionInfos'].should.be.empty
# TerminateWorkflowExecution endpoint
@mock_swf
def test_terminate_workflow_execution():