Fix style issues

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

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")