From c8b5470e25012477f817a619e88f9ad1bea08bbe Mon Sep 17 00:00:00 2001 From: kbalk <7536198+kbalk@users.noreply.github.com> Date: Sat, 12 Aug 2023 03:59:33 -0400 Subject: [PATCH] Techdebt: Replace sure with regular assertions in SWF (#6638) --- tests/test_swf/models/test_activity_task.py | 65 +-- tests/test_swf/models/test_decision_task.py | 49 +- tests/test_swf/models/test_domain.py | 224 ++++----- tests/test_swf/models/test_generic_type.py | 33 +- tests/test_swf/models/test_history_event.py | 27 +- tests/test_swf/models/test_timeout.py | 5 +- .../models/test_workflow_execution.py | 412 ++++++++--------- .../test_swf/responses/test_activity_tasks.py | 88 ++-- .../test_swf/responses/test_activity_types.py | 75 ++-- .../test_swf/responses/test_decision_tasks.py | 349 +++++++------- tests/test_swf/responses/test_domains.py | 424 +++++++++--------- tests/test_swf/responses/test_timeouts.py | 74 ++- .../responses/test_workflow_executions.py | 101 ++--- .../test_swf/responses/test_workflow_types.py | 75 ++-- tests/test_swf/test_exceptions.py | 151 +++---- tests/test_swf/test_utils.py | 16 +- 16 files changed, 1068 insertions(+), 1100 deletions(-) diff --git a/tests/test_swf/models/test_activity_task.py b/tests/test_swf/models/test_activity_task.py index eab813288..f295b6b87 100644 --- a/tests/test_swf/models/test_activity_task.py +++ b/tests/test_swf/models/test_activity_task.py @@ -1,5 +1,7 @@ +import re + from freezegun import freeze_time -import sure # noqa # pylint: disable=unused-import +import pytest from moto.swf.exceptions import SWFWorkflowExecutionClosedError from moto.swf.models import ActivityTask, ActivityType, Timeout @@ -21,23 +23,23 @@ def test_activity_task_creation(): workflow_execution=wfe, timeouts=ACTIVITY_TASK_TIMEOUTS, ) - task.workflow_execution.should.equal(wfe) - task.state.should.equal("SCHEDULED") - task.task_token.should.match("[-a-z0-9]+") - task.started_event_id.should.equal(None) + assert task.workflow_execution == wfe + assert task.state == "SCHEDULED" + assert re.match("[-a-z0-9]+", task.task_token) + assert task.started_event_id is None task.start(123) - task.state.should.equal("STARTED") - task.started_event_id.should.equal(123) + assert task.state == "STARTED" + assert task.started_event_id == 123 task.complete() - task.state.should.equal("COMPLETED") + assert task.state == "COMPLETED" # NB: this doesn't make any sense for SWF, a task shouldn't go from a # "COMPLETED" state to a "FAILED" one, but this is an internal state on our # side and we don't care about invalid state transitions for now. task.fail() - task.state.should.equal("FAILED") + assert task.state == "FAILED" def test_activity_task_full_dict_representation(): @@ -53,16 +55,16 @@ def test_activity_task_full_dict_representation(): at.start(1234) fd = at.to_full_dict() - fd["activityId"].should.equal("my-activity-123") - fd["activityType"]["version"].should.equal("v1.0") - fd["input"].should.equal("optional") - fd["startedEventId"].should.equal(1234) - fd.should.contain("taskToken") - fd["workflowExecution"].should.equal(wfe.to_short_dict()) + assert fd["activityId"] == "my-activity-123" + assert fd["activityType"]["version"] == "v1.0" + assert fd["input"] == "optional" + assert fd["startedEventId"] == 1234 + assert "taskToken" in fd + assert fd["workflowExecution"] == wfe.to_short_dict() at.start(1234) fd = at.to_full_dict() - fd["startedEventId"].should.equal(1234) + assert fd["startedEventId"] == 1234 def test_activity_task_reset_heartbeat_clock(): @@ -78,12 +80,12 @@ def test_activity_task_reset_heartbeat_clock(): workflow_execution=wfe, ) - task.last_heartbeat_timestamp.should.equal(1420113600.0) + assert task.last_heartbeat_timestamp == 1420113600.0 with freeze_time("2015-01-01 13:00:00"): task.reset_heartbeat_clock() - task.last_heartbeat_timestamp.should.equal(1420117200.0) + assert task.last_heartbeat_timestamp == 1420117200.0 def test_activity_task_first_timeout(): @@ -98,14 +100,14 @@ def test_activity_task_first_timeout(): timeouts=ACTIVITY_TASK_TIMEOUTS, workflow_execution=wfe, ) - task.first_timeout().should.be.none + assert task.first_timeout() is None # activity task timeout is 300s == 5mins with freeze_time("2015-01-01 12:06:00"): - task.first_timeout().should.be.a(Timeout) + assert isinstance(task.first_timeout(), Timeout) process_first_timeout(task) - task.state.should.equal("TIMED_OUT") - task.timeout_type.should.equal("HEARTBEAT") + assert task.state == "TIMED_OUT" + assert task.timeout_type == "HEARTBEAT" def test_activity_task_first_timeout_with_heartbeat_timeout_none(): @@ -123,7 +125,7 @@ def test_activity_task_first_timeout_with_heartbeat_timeout_none(): timeouts=activity_task_timeouts, workflow_execution=wfe, ) - task.first_timeout().should.be.none + assert task.first_timeout() is None def test_activity_task_cannot_timeout_on_closed_workflow_execution(): @@ -142,10 +144,10 @@ def test_activity_task_cannot_timeout_on_closed_workflow_execution(): ) with freeze_time("2015-01-01 14:10:00"): - task.first_timeout().should.be.a(Timeout) - wfe.first_timeout().should.be.a(Timeout) + assert isinstance(task.first_timeout(), Timeout) + assert isinstance(wfe.first_timeout(), Timeout) process_first_timeout(wfe) - task.first_timeout().should.be.none + assert task.first_timeout() is None def test_activity_task_cannot_change_state_on_closed_workflow_execution(): @@ -162,8 +164,9 @@ def test_activity_task_cannot_change_state_on_closed_workflow_execution(): ) wfe.complete(123) - task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw( - SWFWorkflowExecutionClosedError - ) - task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError) - task.fail.when.called_with().should.throw(SWFWorkflowExecutionClosedError) + with pytest.raises(SWFWorkflowExecutionClosedError): + task.timeout(Timeout(task, 0, "foo")) + with pytest.raises(SWFWorkflowExecutionClosedError): + task.complete() + with pytest.raises(SWFWorkflowExecutionClosedError): + task.fail() diff --git a/tests/test_swf/models/test_decision_task.py b/tests/test_swf/models/test_decision_task.py index 594fa8dbb..459669e0d 100644 --- a/tests/test_swf/models/test_decision_task.py +++ b/tests/test_swf/models/test_decision_task.py @@ -1,4 +1,7 @@ +import re + from freezegun import freeze_time +import pytest from moto.swf.models import DecisionTask, Timeout from moto.swf.exceptions import SWFWorkflowExecutionClosedError @@ -9,10 +12,10 @@ from ..utils import make_workflow_execution, process_first_timeout def test_decision_task_creation(): wfe = make_workflow_execution() dt = DecisionTask(wfe, 123) - dt.workflow_execution.should.equal(wfe) - dt.state.should.equal("SCHEDULED") - dt.task_token.should.match("[-a-z0-9]+") - dt.started_event_id.should.equal(None) + assert dt.workflow_execution == wfe + assert dt.state == "SCHEDULED" + assert re.match("[-a-z0-9]+", dt.task_token) + assert dt.started_event_id is None def test_decision_task_full_dict_representation(): @@ -21,34 +24,34 @@ def test_decision_task_full_dict_representation(): dt = DecisionTask(wfe, 123) fd = dt.to_full_dict() - fd["events"].should.be.a("list") - fd.should_not.contain("previousStartedEventId") - fd.should_not.contain("startedEventId") - fd.should.contain("taskToken") - fd["workflowExecution"].should.equal(wfe.to_short_dict()) - fd["workflowType"].should.equal(wft.to_short_dict()) + assert isinstance(fd["events"], list) + assert "previousStartedEventId" not in fd + assert "startedEventId" not in fd + assert "taskToken" in fd + assert fd["workflowExecution"] == wfe.to_short_dict() + assert fd["workflowType"] == wft.to_short_dict() dt.start(1234, 1230) fd = dt.to_full_dict() - fd["startedEventId"].should.equal(1234) - fd["previousStartedEventId"].should.equal(1230) + assert fd["startedEventId"] == 1234 + assert fd["previousStartedEventId"] == 1230 def test_decision_task_first_timeout(): wfe = make_workflow_execution() dt = DecisionTask(wfe, 123) - dt.first_timeout().should.be.none + assert dt.first_timeout() is None with freeze_time("2015-01-01 12:00:00"): dt.start(1234) - dt.first_timeout().should.be.none + assert dt.first_timeout() is None # activity task timeout is 300s == 5mins with freeze_time("2015-01-01 12:06:00"): - dt.first_timeout().should.be.a(Timeout) + assert isinstance(dt.first_timeout(), Timeout) dt.complete() - dt.first_timeout().should.be.none + assert dt.first_timeout() is None def test_decision_task_cannot_timeout_on_closed_workflow_execution(): @@ -61,10 +64,10 @@ def test_decision_task_cannot_timeout_on_closed_workflow_execution(): dt.start(1234) with freeze_time("2015-01-01 14:10:00"): - dt.first_timeout().should.be.a(Timeout) - wfe.first_timeout().should.be.a(Timeout) + assert isinstance(dt.first_timeout(), Timeout) + assert isinstance(wfe.first_timeout(), Timeout) process_first_timeout(wfe) - dt.first_timeout().should.be.none + assert dt.first_timeout() is None def test_decision_task_cannot_change_state_on_closed_workflow_execution(): @@ -74,7 +77,7 @@ def test_decision_task_cannot_change_state_on_closed_workflow_execution(): wfe.complete(123) - task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw( - SWFWorkflowExecutionClosedError - ) - task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError) + with pytest.raises(SWFWorkflowExecutionClosedError): + task.timeout(Timeout(task, 0, "foo")) + with pytest.raises(SWFWorkflowExecutionClosedError): + task.complete() diff --git a/tests/test_swf/models/test_domain.py b/tests/test_swf/models/test_domain.py index bd6a01b03..583f40d49 100644 --- a/tests/test_swf/models/test_domain.py +++ b/tests/test_swf/models/test_domain.py @@ -1,112 +1,112 @@ -from collections import namedtuple -import sure # noqa # pylint: disable=unused-import - -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID -from moto.swf.exceptions import SWFUnknownResourceFault -from moto.swf.models import Domain - -TEST_REGION = "us-east-1" -# Fake WorkflowExecution for tests purposes -WorkflowExecution = namedtuple( - "WorkflowExecution", ["workflow_id", "run_id", "execution_status", "open"] -) - - -def test_domain_short_dict_representation(): - domain = Domain("foo", "52", ACCOUNT_ID, TEST_REGION) - domain.to_short_dict().should.equal( - { - "name": "foo", - "status": "REGISTERED", - "arn": f"arn:aws:swf:{TEST_REGION}:{ACCOUNT_ID}:/domain/foo", - } - ) - - domain.description = "foo bar" - domain.to_short_dict()["description"].should.equal("foo bar") - - -def test_domain_full_dict_representation(): - domain = Domain("foo", "52", ACCOUNT_ID, TEST_REGION) - - domain.to_full_dict()["domainInfo"].should.equal(domain.to_short_dict()) - _config = domain.to_full_dict()["configuration"] - _config["workflowExecutionRetentionPeriodInDays"].should.equal("52") - - -def test_domain_string_representation(): - domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) - str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)") - - -def test_domain_add_to_activity_task_list(): - domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) - domain.add_to_activity_task_list("foo", "bar") - domain.activity_task_lists.should.equal({"foo": ["bar"]}) - - -def test_domain_activity_tasks(): - domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) - 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", ACCOUNT_ID, TEST_REGION) - domain.add_to_decision_task_list("foo", "bar") - domain.decision_task_lists.should.equal({"foo": ["bar"]}) - - -def test_domain_decision_tasks(): - domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) - 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", ACCOUNT_ID, TEST_REGION) - - wfe1 = WorkflowExecution( - workflow_id="wf-id-1", run_id="run-id-1", execution_status="OPEN", open=True - ) - wfe2 = WorkflowExecution( - workflow_id="wf-id-1", run_id="run-id-2", execution_status="CLOSED", open=False - ) - wfe3 = WorkflowExecution( - workflow_id="wf-id-2", run_id="run-id-3", execution_status="OPEN", open=True - ) - wfe4 = WorkflowExecution( - workflow_id="wf-id-3", run_id="run-id-4", execution_status="CLOSED", open=False - ) - domain.workflow_executions = [wfe1, wfe2, wfe3, wfe4] - - # get workflow execution through workflow_id and run_id - domain.get_workflow_execution("wf-id-1", run_id="run-id-1").should.equal(wfe1) - domain.get_workflow_execution("wf-id-1", run_id="run-id-2").should.equal(wfe2) - domain.get_workflow_execution("wf-id-3", run_id="run-id-4").should.equal(wfe4) - - domain.get_workflow_execution.when.called_with( - "wf-id-1", run_id="non-existent" - ).should.throw(SWFUnknownResourceFault) - - # get OPEN workflow execution by default if no run_id - domain.get_workflow_execution("wf-id-1").should.equal(wfe1) - domain.get_workflow_execution.when.called_with("wf-id-3").should.throw( - SWFUnknownResourceFault - ) - domain.get_workflow_execution.when.called_with("wf-id-non-existent").should.throw( - SWFUnknownResourceFault - ) - - # raise_if_closed attribute - domain.get_workflow_execution( - "wf-id-1", run_id="run-id-1", raise_if_closed=True - ).should.equal(wfe1) - domain.get_workflow_execution.when.called_with( - "wf-id-3", run_id="run-id-4", raise_if_closed=True - ).should.throw(SWFUnknownResourceFault) - - # raise_if_none attribute - domain.get_workflow_execution("foo", raise_if_none=False).should.be.none +from collections import namedtuple + +import pytest + +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto.swf.exceptions import SWFUnknownResourceFault +from moto.swf.models import Domain + +TEST_REGION = "us-east-1" +# Fake WorkflowExecution for tests purposes +WorkflowExecution = namedtuple( + "WorkflowExecution", ["workflow_id", "run_id", "execution_status", "open"] +) + + +def test_domain_short_dict_representation(): + domain = Domain("foo", "52", ACCOUNT_ID, TEST_REGION) + assert domain.to_short_dict() == { + "name": "foo", + "status": "REGISTERED", + "arn": f"arn:aws:swf:{TEST_REGION}:{ACCOUNT_ID}:/domain/foo", + } + + domain.description = "foo bar" + assert domain.to_short_dict()["description"] == "foo bar" + + +def test_domain_full_dict_representation(): + domain = Domain("foo", "52", ACCOUNT_ID, TEST_REGION) + + assert domain.to_full_dict()["domainInfo"] == domain.to_short_dict() + _config = domain.to_full_dict()["configuration"] + assert _config["workflowExecutionRetentionPeriodInDays"] == "52" + + +def test_domain_string_representation(): + domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) + assert str(domain) == "Domain(name: my-domain, status: REGISTERED)" + + +def test_domain_add_to_activity_task_list(): + domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) + domain.add_to_activity_task_list("foo", "bar") + assert domain.activity_task_lists == {"foo": ["bar"]} + + +def test_domain_activity_tasks(): + domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) + domain.add_to_activity_task_list("foo", "bar") + domain.add_to_activity_task_list("other", "baz") + assert sorted(domain.activity_tasks) == ["bar", "baz"] + + +def test_domain_add_to_decision_task_list(): + domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) + domain.add_to_decision_task_list("foo", "bar") + assert domain.decision_task_lists == {"foo": ["bar"]} + + +def test_domain_decision_tasks(): + domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) + domain.add_to_decision_task_list("foo", "bar") + domain.add_to_decision_task_list("other", "baz") + assert sorted(domain.decision_tasks) == ["bar", "baz"] + + +def test_domain_get_workflow_execution(): + domain = Domain("my-domain", "60", ACCOUNT_ID, TEST_REGION) + + wfe1 = WorkflowExecution( + workflow_id="wf-id-1", run_id="run-id-1", execution_status="OPEN", open=True + ) + wfe2 = WorkflowExecution( + workflow_id="wf-id-1", run_id="run-id-2", execution_status="CLOSED", open=False + ) + wfe3 = WorkflowExecution( + workflow_id="wf-id-2", run_id="run-id-3", execution_status="OPEN", open=True + ) + wfe4 = WorkflowExecution( + workflow_id="wf-id-3", run_id="run-id-4", execution_status="CLOSED", open=False + ) + domain.workflow_executions = [wfe1, wfe2, wfe3, wfe4] + + # get workflow execution through workflow_id and run_id + assert domain.get_workflow_execution("wf-id-1", run_id="run-id-1") == wfe1 + assert domain.get_workflow_execution("wf-id-1", run_id="run-id-2") == wfe2 + assert domain.get_workflow_execution("wf-id-3", run_id="run-id-4") == wfe4 + + with pytest.raises(SWFUnknownResourceFault): + domain.get_workflow_execution("wf-id-1", run_id="non-existent") + + # get OPEN workflow execution by default if no run_id + assert domain.get_workflow_execution("wf-id-1") == wfe1 + with pytest.raises(SWFUnknownResourceFault): + domain.get_workflow_execution("wf-id-3") + with pytest.raises(SWFUnknownResourceFault): + domain.get_workflow_execution("wf-id-non-existent") + + # raise_if_closed attribute + assert ( + domain.get_workflow_execution( + "wf-id-1", run_id="run-id-1", raise_if_closed=True + ) + == wfe1 + ) + with pytest.raises(SWFUnknownResourceFault): + domain.get_workflow_execution( + "wf-id-3", run_id="run-id-4", raise_if_closed=True + ) + + # raise_if_none attribute + assert domain.get_workflow_execution("foo", raise_if_none=False) is None diff --git a/tests/test_swf/models/test_generic_type.py b/tests/test_swf/models/test_generic_type.py index f719c9d44..57956e114 100644 --- a/tests/test_swf/models/test_generic_type.py +++ b/tests/test_swf/models/test_generic_type.py @@ -1,5 +1,4 @@ from moto.swf.models import GenericType -import sure # noqa # pylint: disable=unused-import # Tests for GenericType (ActivityType, WorkflowType) @@ -15,44 +14,40 @@ class FooType(GenericType): def test_type_short_dict_representation(): _type = FooType("test-foo", "v1.0") - _type.to_short_dict().should.equal({"name": "test-foo", "version": "v1.0"}) + assert _type.to_short_dict() == {"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()) - _type.to_medium_dict()["status"].should.equal("REGISTERED") - _type.to_medium_dict().should.contain("creationDate") - _type.to_medium_dict().should_not.contain("deprecationDate") - _type.to_medium_dict().should_not.contain("description") + assert _type.to_medium_dict()["fooType"] == _type.to_short_dict() + assert _type.to_medium_dict()["status"] == "REGISTERED" + assert "creationDate" in _type.to_medium_dict() + assert "deprecationDate" not in _type.to_medium_dict() + assert "description" not in _type.to_medium_dict() _type.description = "foo bar" - _type.to_medium_dict()["description"].should.equal("foo bar") + assert _type.to_medium_dict()["description"] == "foo bar" _type.status = "DEPRECATED" - _type.to_medium_dict().should.contain("deprecationDate") + assert "deprecationDate" in _type.to_medium_dict() 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({}) + assert _type.to_full_dict()["typeInfo"] == _type.to_medium_dict() + assert not _type.to_full_dict()["configuration"] _type.task_list = "foo" - _type.to_full_dict()["configuration"]["defaultTaskList"].should.equal( - {"name": "foo"} - ) + assert _type.to_full_dict()["configuration"]["defaultTaskList"] == {"name": "foo"} _type.just_an_example_timeout = "60" - _type.to_full_dict()["configuration"]["justAnExampleTimeout"].should.equal("60") + assert _type.to_full_dict()["configuration"]["justAnExampleTimeout"] == "60" _type.non_whitelisted_property = "34" keys = _type.to_full_dict()["configuration"].keys() - sorted(keys).should.equal(["defaultTaskList", "justAnExampleTimeout"]) + assert sorted(keys) == ["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)" - ) + assert str(_type) == "FooType(name: test-foo, version: v1.0, status: REGISTERED)" diff --git a/tests/test_swf/models/test_history_event.py b/tests/test_swf/models/test_history_event.py index 0313d6947..fdbbb9863 100644 --- a/tests/test_swf/models/test_history_event.py +++ b/tests/test_swf/models/test_history_event.py @@ -1,5 +1,5 @@ from freezegun import freeze_time -import sure # noqa # pylint: disable=unused-import +import pytest from moto.swf.models import HistoryEvent @@ -7,25 +7,22 @@ from moto.swf.models import 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(1420113600.0) + assert he.event_id == 123 + assert he.event_type == "DecisionTaskStarted" + assert he.event_timestamp == 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) - he.to_dict().should.equal( - { - "eventId": 123, - "eventType": "DecisionTaskStarted", - "eventTimestamp": 1420113600.0, - "decisionTaskStartedEventAttributes": {"scheduledEventId": 2}, - } - ) + assert he.to_dict() == { + "eventId": 123, + "eventType": "DecisionTaskStarted", + "eventTimestamp": 1420113600.0, + "decisionTaskStartedEventAttributes": {"scheduledEventId": 2}, + } def test_history_event_breaks_on_initialization_if_not_implemented(): - HistoryEvent.when.called_with(123, "UnknownHistoryEvent").should.throw( - NotImplementedError - ) + with pytest.raises(NotImplementedError): + HistoryEvent(123, "UnknownHistoryEvent") diff --git a/tests/test_swf/models/test_timeout.py b/tests/test_swf/models/test_timeout.py index 63498fbdf..a5c7ec943 100644 --- a/tests/test_swf/models/test_timeout.py +++ b/tests/test_swf/models/test_timeout.py @@ -1,5 +1,4 @@ from freezegun import freeze_time -import sure # noqa # pylint: disable=unused-import from moto.swf.models import Timeout @@ -13,7 +12,7 @@ def test_timeout_creation(): timeout = Timeout(wfe, 1420117200, "START_TO_CLOSE") with freeze_time("2015-01-01 12:00:00"): - timeout.reached.should.equal(False) + assert timeout.reached is False with freeze_time("2015-01-01 13:00:00"): - timeout.reached.should.equal(True) + assert timeout.reached is True diff --git a/tests/test_swf/models/test_workflow_execution.py b/tests/test_swf/models/test_workflow_execution.py index f5d7e6beb..3af31234f 100644 --- a/tests/test_swf/models/test_workflow_execution.py +++ b/tests/test_swf/models/test_workflow_execution.py @@ -1,10 +1,12 @@ +import re from threading import Timer as ThreadingTimer from time import sleep +from unittest.mock import Mock, patch from freezegun import freeze_time -from unittest.mock import Mock, patch -import sure # noqa # pylint: disable=unused-import +import pytest +from moto.swf.exceptions import SWFDefaultUndefinedFault from moto.swf.models import ( ActivityType, Timeout, @@ -12,7 +14,6 @@ from moto.swf.models import ( WorkflowType, WorkflowExecution, ) -from moto.swf.exceptions import SWFDefaultUndefinedFault from ..utils import ( auto_start_decision_tasks, get_basic_domain, @@ -37,48 +38,53 @@ def test_workflow_execution_creation(): wft = get_basic_workflow_type() wfe = WorkflowExecution(domain, wft, "ab1234", child_policy="TERMINATE") - wfe.domain.should.equal(domain) - wfe.workflow_type.should.equal(wft) - wfe.child_policy.should.equal("TERMINATE") + assert wfe.domain == domain + assert wfe.workflow_type == wft + assert wfe.child_policy == "TERMINATE" def test_workflow_execution_creation_child_policy_logic(): domain = get_basic_domain() - WorkflowExecution( - domain, - 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", - ), - "ab1234", - ).child_policy.should.equal("ABANDON") + assert ( + WorkflowExecution( + domain, + 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", + ), + "ab1234", + ).child_policy + == "ABANDON" + ) - WorkflowExecution( - domain, - WorkflowType( - "test-workflow", - "v1.0", - task_list="queue", - default_execution_start_to_close_timeout="300", - default_task_start_to_close_timeout="300", - ), - "ab1234", - child_policy="REQUEST_CANCEL", - ).child_policy.should.equal("REQUEST_CANCEL") + assert ( + WorkflowExecution( + domain, + WorkflowType( + "test-workflow", + "v1.0", + task_list="queue", + default_execution_start_to_close_timeout="300", + default_task_start_to_close_timeout="300", + ), + "ab1234", + child_policy="REQUEST_CANCEL", + ).child_policy + == "REQUEST_CANCEL" + ) - WorkflowExecution.when.called_with( - domain, WorkflowType("test-workflow", "v1.0"), "ab1234" - ).should.throw(SWFDefaultUndefinedFault) + with pytest.raises(SWFDefaultUndefinedFault): + WorkflowExecution(domain, WorkflowType("test-workflow", "v1.0"), "ab1234") def test_workflow_execution_string_representation(): wfe = make_workflow_execution(child_policy="TERMINATE") - str(wfe).should.match(r"^WorkflowExecution\(run_id: .*\)") + assert re.match(r"^WorkflowExecution\(run_id: .*\)", str(wfe)) def test_workflow_execution_generates_a_random_run_id(): @@ -86,7 +92,7 @@ def test_workflow_execution_generates_a_random_run_id(): wft = get_basic_workflow_type() wfe1 = WorkflowExecution(domain, wft, "ab1234", child_policy="TERMINATE") wfe2 = WorkflowExecution(domain, wft, "ab1235", child_policy="TERMINATE") - wfe1.run_id.should_not.equal(wfe2.run_id) + assert wfe1.run_id != wfe2.run_id def test_workflow_execution_short_dict_representation(): @@ -102,8 +108,8 @@ def test_workflow_execution_short_dict_representation(): wfe = WorkflowExecution(domain, wf_type, "ab1234") sd = wfe.to_short_dict() - sd["workflowId"].should.equal("ab1234") - sd.should.contain("runId") + assert sd["workflowId"] == "ab1234" + assert "runId" in sd def test_workflow_execution_medium_dict_representation(): @@ -119,16 +125,16 @@ def test_workflow_execution_medium_dict_representation(): wfe = WorkflowExecution(domain, wf_type, "ab1234") md = wfe.to_medium_dict() - md["execution"].should.equal(wfe.to_short_dict()) - md["workflowType"].should.equal(wf_type.to_short_dict()) - md["startTimestamp"].should.be.a("float") - md["executionStatus"].should.equal("OPEN") - md["cancelRequested"].should.equal(False) - md.should_not.contain("tagList") + assert md["execution"] == wfe.to_short_dict() + assert md["workflowType"] == wf_type.to_short_dict() + assert isinstance(md["startTimestamp"], float) + assert md["executionStatus"] == "OPEN" + assert md["cancelRequested"] is False + assert "tagList" not in md wfe.tag_list = ["foo", "bar", "baz"] md = wfe.to_medium_dict() - md["tagList"].should.equal(["foo", "bar", "baz"]) + assert md["tagList"] == ["foo", "bar", "baz"] def test_workflow_execution_full_dict_representation(): @@ -144,18 +150,16 @@ def test_workflow_execution_full_dict_representation(): wfe = WorkflowExecution(domain, wf_type, "ab1234") fd = wfe.to_full_dict() - fd["executionInfo"].should.equal(wfe.to_medium_dict()) - fd["openCounts"]["openTimers"].should.equal(0) - fd["openCounts"]["openDecisionTasks"].should.equal(0) - fd["openCounts"]["openActivityTasks"].should.equal(0) - fd["executionConfiguration"].should.equal( - { - "childPolicy": "ABANDON", - "executionStartToCloseTimeout": "300", - "taskList": {"name": "queue"}, - "taskStartToCloseTimeout": "300", - } - ) + assert fd["executionInfo"] == wfe.to_medium_dict() + assert fd["openCounts"]["openTimers"] == 0 + assert fd["openCounts"]["openDecisionTasks"] == 0 + assert fd["openCounts"]["openActivityTasks"] == 0 + assert fd["executionConfiguration"] == { + "childPolicy": "ABANDON", + "executionStartToCloseTimeout": "300", + "taskList": {"name": "queue"}, + "taskStartToCloseTimeout": "300", + } def test_closed_workflow_execution_full_dict_representation(): @@ -177,18 +181,16 @@ def test_closed_workflow_execution_full_dict_representation(): medium_dict = wfe.to_medium_dict() medium_dict["closeStatus"] = "CANCELED" medium_dict["closeTimestamp"] = 1420066801.123 - fd["executionInfo"].should.equal(medium_dict) - fd["openCounts"]["openTimers"].should.equal(0) - fd["openCounts"]["openDecisionTasks"].should.equal(0) - fd["openCounts"]["openActivityTasks"].should.equal(0) - fd["executionConfiguration"].should.equal( - { - "childPolicy": "ABANDON", - "executionStartToCloseTimeout": "300", - "taskList": {"name": "queue"}, - "taskStartToCloseTimeout": "300", - } - ) + assert fd["executionInfo"] == medium_dict + assert fd["openCounts"]["openTimers"] == 0 + assert fd["openCounts"]["openDecisionTasks"] == 0 + assert fd["openCounts"]["openActivityTasks"] == 0 + assert fd["executionConfiguration"] == { + "childPolicy": "ABANDON", + "executionStartToCloseTimeout": "300", + "taskList": {"name": "queue"}, + "taskStartToCloseTimeout": "300", + } def test_workflow_execution_list_dict_representation(): @@ -204,47 +206,47 @@ def test_workflow_execution_list_dict_representation(): 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.equal(False) - ld.should.contain("startTimestamp") + assert ld["workflowType"]["version"] == "v1.0" + assert ld["workflowType"]["name"] == "test-workflow" + assert ld["executionStatus"] == "OPEN" + assert ld["execution"]["workflowId"] == "ab1234" + assert "runId" in ld["execution"] + assert ld["cancelRequested"] is False + assert "startTimestamp" in ld def test_workflow_execution_schedule_decision_task(): wfe = make_workflow_execution() - wfe.open_counts["openDecisionTasks"].should.equal(0) + assert wfe.open_counts["openDecisionTasks"] == 0 wfe.schedule_decision_task() - wfe.open_counts["openDecisionTasks"].should.equal(1) + assert wfe.open_counts["openDecisionTasks"] == 1 def test_workflow_execution_dont_schedule_decision_if_existing_started_and_other_scheduled(): wfe = make_workflow_execution() - wfe.open_counts["openDecisionTasks"].should.equal(0) + assert wfe.open_counts["openDecisionTasks"] == 0 wfe.schedule_decision_task() - wfe.open_counts["openDecisionTasks"].should.equal(1) + assert wfe.open_counts["openDecisionTasks"] == 1 wfe.decision_tasks[0].start("evt_id") wfe.schedule_decision_task() wfe.schedule_decision_task() - wfe.open_counts["openDecisionTasks"].should.equal(2) + assert wfe.open_counts["openDecisionTasks"] == 2 def test_workflow_execution_schedule_decision_if_existing_started_and_no_other_scheduled(): wfe = make_workflow_execution() - wfe.open_counts["openDecisionTasks"].should.equal(0) + assert wfe.open_counts["openDecisionTasks"] == 0 wfe.schedule_decision_task() - wfe.open_counts["openDecisionTasks"].should.equal(1) + assert wfe.open_counts["openDecisionTasks"] == 1 wfe.decision_tasks[0].start("evt_id") wfe.schedule_decision_task() - wfe.open_counts["openDecisionTasks"].should.equal(2) + assert wfe.open_counts["openDecisionTasks"] == 2 def test_workflow_execution_start_decision_task(): @@ -253,9 +255,9 @@ def test_workflow_execution_start_decision_task(): dt = wfe.decision_tasks[0] wfe.start_decision_task(dt.task_token, identity="srv01") dt = wfe.decision_tasks[0] - dt.state.should.equal("STARTED") - wfe.events()[-1].event_type.should.equal("DecisionTaskStarted") - wfe.events()[-1].event_attributes["identity"].should.equal("srv01") + assert dt.state == "STARTED" + assert wfe.events()[-1].event_type == "DecisionTaskStarted" + assert wfe.events()[-1].event_attributes["identity"] == "srv01" def test_workflow_execution_history_events_ids(): @@ -264,19 +266,19 @@ def test_workflow_execution_history_events_ids(): wfe._add_event("DecisionTaskScheduled") wfe._add_event("DecisionTaskStarted") ids = [evt.event_id for evt in wfe.events()] - ids.should.equal([1, 2, 3]) + assert ids == [1, 2, 3] @freeze_time("2015-01-01 12:00:00") def test_workflow_execution_start(): wfe = make_workflow_execution() - wfe.events().should.equal([]) + assert wfe.events() == [] wfe.start() - wfe.start_timestamp.should.equal(1420113600.0) - wfe.events().should.have.length_of(2) - wfe.events()[0].event_type.should.equal("WorkflowExecutionStarted") - wfe.events()[1].event_type.should.equal("DecisionTaskScheduled") + assert wfe.start_timestamp == 1420113600.0 + assert len(wfe.events()) == 2 + assert wfe.events()[0].event_type == "WorkflowExecutionStarted" + assert wfe.events()[1].event_type == "DecisionTaskScheduled" @freeze_time("2015-01-02 12:00:00") @@ -284,12 +286,12 @@ def test_workflow_execution_complete(): wfe = make_workflow_execution() wfe.complete(123, result="foo") - wfe.execution_status.should.equal("CLOSED") - wfe.close_status.should.equal("COMPLETED") - wfe.close_timestamp.should.equal(1420200000.0) - wfe.events()[-1].event_type.should.equal("WorkflowExecutionCompleted") - wfe.events()[-1].event_attributes["decisionTaskCompletedEventId"].should.equal(123) - wfe.events()[-1].event_attributes["result"].should.equal("foo") + assert wfe.execution_status == "CLOSED" + assert wfe.close_status == "COMPLETED" + assert wfe.close_timestamp == 1420200000.0 + assert wfe.events()[-1].event_type == "WorkflowExecutionCompleted" + assert wfe.events()[-1].event_attributes["decisionTaskCompletedEventId"] == 123 + assert wfe.events()[-1].event_attributes["result"] == "foo" @freeze_time("2015-01-02 12:00:00") @@ -297,35 +299,35 @@ def test_workflow_execution_fail(): wfe = make_workflow_execution() wfe.fail(123, details="some details", reason="my rules") - wfe.execution_status.should.equal("CLOSED") - wfe.close_status.should.equal("FAILED") - wfe.close_timestamp.should.equal(1420200000.0) - wfe.events()[-1].event_type.should.equal("WorkflowExecutionFailed") - wfe.events()[-1].event_attributes["decisionTaskCompletedEventId"].should.equal(123) - wfe.events()[-1].event_attributes["details"].should.equal("some details") - wfe.events()[-1].event_attributes["reason"].should.equal("my rules") + assert wfe.execution_status == "CLOSED" + assert wfe.close_status == "FAILED" + assert wfe.close_timestamp == 1420200000.0 + assert wfe.events()[-1].event_type == "WorkflowExecutionFailed" + assert wfe.events()[-1].event_attributes["decisionTaskCompletedEventId"] == 123 + assert wfe.events()[-1].event_attributes["details"] == "some details" + assert wfe.events()[-1].event_attributes["reason"] == "my rules" @freeze_time("2015-01-01 12:00:00") def test_workflow_execution_schedule_activity_task(): wfe = make_workflow_execution() - wfe.latest_activity_task_timestamp.should.equal(None) + assert wfe.latest_activity_task_timestamp is None wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES) - wfe.latest_activity_task_timestamp.should.equal(1420113600.0) + assert wfe.latest_activity_task_timestamp == 1420113600.0 - wfe.open_counts["openActivityTasks"].should.equal(1) + assert wfe.open_counts["openActivityTasks"] == 1 last_event = wfe.events()[-1] - last_event.event_type.should.equal("ActivityTaskScheduled") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) - last_event.event_attributes["taskList"]["name"].should.equal("task-list-name") + assert last_event.event_type == "ActivityTaskScheduled" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 + assert last_event.event_attributes["taskList"]["name"] == "task-list-name" - wfe.activity_tasks.should.have.length_of(1) + assert len(wfe.activity_tasks) == 1 task = wfe.activity_tasks[0] - task.activity_id.should.equal("my-activity-001") - task.activity_type.name.should.equal("test-activity") - wfe.domain.activity_task_lists["task-list-name"].should.contain(task) + assert task.activity_id == "my-activity-001" + assert task.activity_type.name == "test-activity" + assert task in wfe.domain.activity_task_lists["task-list-name"] def test_workflow_execution_schedule_activity_task_without_task_list_should_take_default(): @@ -343,13 +345,13 @@ def test_workflow_execution_schedule_activity_task_without_task_list_should_take }, ) - wfe.open_counts["openActivityTasks"].should.equal(1) + assert wfe.open_counts["openActivityTasks"] == 1 last_event = wfe.events()[-1] - last_event.event_type.should.equal("ActivityTaskScheduled") - last_event.event_attributes["taskList"]["name"].should.equal("foobar") + assert last_event.event_type == "ActivityTaskScheduled" + assert last_event.event_attributes["taskList"]["name"] == "foobar" task = wfe.activity_tasks[0] - wfe.domain.activity_task_lists["foobar"].should.contain(task) + assert task in wfe.domain.activity_task_lists["foobar"] def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attributes(): @@ -366,66 +368,66 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal("ACTIVITY_TYPE_DOES_NOT_EXIST") + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == "ACTIVITY_TYPE_DOES_NOT_EXIST" hsh["activityType"]["name"] = "test-activity" wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal("ACTIVITY_TYPE_DEPRECATED") + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == "ACTIVITY_TYPE_DEPRECATED" hsh["activityType"]["version"] = "v1.2" wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal("DEFAULT_TASK_LIST_UNDEFINED") + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == "DEFAULT_TASK_LIST_UNDEFINED" hsh["taskList"] = {"name": "foobar"} wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal( + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == ( "DEFAULT_SCHEDULE_TO_START_TIMEOUT_UNDEFINED" ) hsh["scheduleToStartTimeout"] = "600" wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal( + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == ( "DEFAULT_SCHEDULE_TO_CLOSE_TIMEOUT_UNDEFINED" ) hsh["scheduleToCloseTimeout"] = "600" wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal( + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == ( "DEFAULT_START_TO_CLOSE_TIMEOUT_UNDEFINED" ) hsh["startToCloseTimeout"] = "600" wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal( + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == ( "DEFAULT_HEARTBEAT_TIMEOUT_UNDEFINED" ) - wfe.open_counts["openActivityTasks"].should.equal(0) - wfe.activity_tasks.should.have.length_of(0) - wfe.domain.activity_task_lists.should.have.length_of(0) + assert wfe.open_counts["openActivityTasks"] == 0 + assert len(wfe.activity_tasks) == 0 + assert len(wfe.domain.activity_task_lists) == 0 hsh["heartbeatTimeout"] = "300" wfe.schedule_activity_task(123, hsh) last_event = wfe.events()[-1] - last_event.event_type.should.equal("ActivityTaskScheduled") + assert last_event.event_type == "ActivityTaskScheduled" task = wfe.activity_tasks[0] - wfe.domain.activity_task_lists["foobar"].should.contain(task) - wfe.open_counts["openDecisionTasks"].should.equal(0) - wfe.open_counts["openActivityTasks"].should.equal(1) + assert task in wfe.domain.activity_task_lists["foobar"] + assert wfe.open_counts["openDecisionTasks"] == 0 + assert wfe.open_counts["openActivityTasks"] == 1 def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision(): @@ -460,28 +462,28 @@ def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision ], ) - wfe.latest_execution_context.should.equal("free-form execution context") - wfe.open_counts["openActivityTasks"].should.equal(0) - wfe.open_counts["openDecisionTasks"].should.equal(1) + assert wfe.latest_execution_context == "free-form execution context" + assert wfe.open_counts["openActivityTasks"] == 0 + assert wfe.open_counts["openDecisionTasks"] == 1 last_events = wfe.events()[-3:] - last_events[0].event_type.should.equal("ScheduleActivityTaskFailed") - last_events[1].event_type.should.equal("ScheduleActivityTaskFailed") - last_events[2].event_type.should.equal("DecisionTaskScheduled") + assert last_events[0].event_type == "ScheduleActivityTaskFailed" + assert last_events[1].event_type == "ScheduleActivityTaskFailed" + assert last_events[2].event_type == "DecisionTaskScheduled" def test_workflow_execution_schedule_activity_task_with_same_activity_id(): wfe = make_workflow_execution() wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES) - wfe.open_counts["openActivityTasks"].should.equal(1) + assert wfe.open_counts["openActivityTasks"] == 1 last_event = wfe.events()[-1] - last_event.event_type.should.equal("ActivityTaskScheduled") + assert last_event.event_type == "ActivityTaskScheduled" wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES) - wfe.open_counts["openActivityTasks"].should.equal(1) + assert wfe.open_counts["openActivityTasks"] == 1 last_event = wfe.events()[-1] - last_event.event_type.should.equal("ScheduleActivityTaskFailed") - last_event.event_attributes["cause"].should.equal("ACTIVITY_ID_ALREADY_IN_USE") + assert last_event.event_type == "ScheduleActivityTaskFailed" + assert last_event.event_attributes["cause"] == "ACTIVITY_ID_ALREADY_IN_USE" def test_workflow_execution_start_activity_task(): @@ -490,9 +492,9 @@ def test_workflow_execution_start_activity_task(): task_token = wfe.activity_tasks[-1].task_token wfe.start_activity_task(task_token, identity="worker01") task = wfe.activity_tasks[-1] - task.state.should.equal("STARTED") - wfe.events()[-1].event_type.should.equal("ActivityTaskStarted") - wfe.events()[-1].event_attributes["identity"].should.equal("worker01") + assert task.state == "STARTED" + assert wfe.events()[-1].event_type == "ActivityTaskStarted" + assert wfe.events()[-1].event_attributes["identity"] == "worker01" def test_complete_activity_task(): @@ -500,19 +502,19 @@ def test_complete_activity_task(): wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES) task_token = wfe.activity_tasks[-1].task_token - wfe.open_counts["openActivityTasks"].should.equal(1) - wfe.open_counts["openDecisionTasks"].should.equal(0) + assert wfe.open_counts["openActivityTasks"] == 1 + assert wfe.open_counts["openDecisionTasks"] == 0 wfe.start_activity_task(task_token, identity="worker01") wfe.complete_activity_task(task_token, result="a superb result") task = wfe.activity_tasks[-1] - task.state.should.equal("COMPLETED") - wfe.events()[-2].event_type.should.equal("ActivityTaskCompleted") - wfe.events()[-1].event_type.should.equal("DecisionTaskScheduled") + assert task.state == "COMPLETED" + assert wfe.events()[-2].event_type == "ActivityTaskCompleted" + assert wfe.events()[-1].event_type == "DecisionTaskScheduled" - wfe.open_counts["openActivityTasks"].should.equal(0) - wfe.open_counts["openDecisionTasks"].should.equal(1) + assert wfe.open_counts["openActivityTasks"] == 0 + assert wfe.open_counts["openDecisionTasks"] == 1 def test_terminate(): @@ -520,28 +522,28 @@ def test_terminate(): wfe.schedule_decision_task() wfe.terminate() - wfe.execution_status.should.equal("CLOSED") - wfe.close_status.should.equal("TERMINATED") - wfe.close_cause.should.equal("OPERATOR_INITIATED") - wfe.open_counts["openDecisionTasks"].should.equal(1) + assert wfe.execution_status == "CLOSED" + assert wfe.close_status == "TERMINATED" + assert wfe.close_cause == "OPERATOR_INITIATED" + assert wfe.open_counts["openDecisionTasks"] == 1 last_event = wfe.events()[-1] - last_event.event_type.should.equal("WorkflowExecutionTerminated") + assert last_event.event_type == "WorkflowExecutionTerminated" # take default child_policy if not provided (as here) - last_event.event_attributes["childPolicy"].should.equal("ABANDON") + assert last_event.event_attributes["childPolicy"] == "ABANDON" def test_first_timeout(): wfe = make_workflow_execution() - wfe.first_timeout().should.be.none + assert wfe.first_timeout() is None with freeze_time("2015-01-01 12:00:00"): wfe.start() - wfe.first_timeout().should.be.none + assert wfe.first_timeout() is None with freeze_time("2015-01-01 14:01"): # 2 hours timeout reached - wfe.first_timeout().should.be.a(Timeout) + assert isinstance(wfe.first_timeout(), Timeout) # See moto/swf/models/workflow_execution.py "_process_timeouts()" for more @@ -570,14 +572,12 @@ def test_timeouts_are_processed_in_order_and_reevaluated(): wfe._process_timeouts() event_types = [e.event_type for e in wfe.events()[event_idx:]] - event_types.should.equal( - [ - "DecisionTaskTimedOut", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "WorkflowExecutionTimedOut", - ] - ) + assert event_types == [ + "DecisionTaskTimedOut", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "WorkflowExecutionTimedOut", + ] def test_record_marker(): @@ -587,9 +587,9 @@ def test_record_marker(): wfe.record_marker(123, MARKER_EVENT_ATTRIBUTES) last_event = wfe.events()[-1] - last_event.event_type.should.equal("MarkerRecorded") - last_event.event_attributes["markerName"].should.equal("example_marker") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "MarkerRecorded" + assert last_event.event_attributes["markerName"] == "example_marker" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 def test_start_timer(): @@ -600,10 +600,10 @@ def test_start_timer(): wfe.start_timer(123, START_TIMER_EVENT_ATTRIBUTES) last_event = wfe.events()[-1] - last_event.event_type.should.equal("TimerStarted") - last_event.event_attributes["startToFireTimeout"].should.equal("10") - last_event.event_attributes["timerId"].should.equal("abc123") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "TimerStarted" + assert last_event.event_attributes["startToFireTimeout"] == "10" + assert last_event.event_attributes["timerId"] == "abc123" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 def test_start_timer_correctly_fires_timer_later(): @@ -618,10 +618,10 @@ def test_start_timer_correctly_fires_timer_later(): second_to_last_event = wfe.events()[-2] last_event = wfe.events()[-1] - second_to_last_event.event_type.should.equal("TimerFired") - second_to_last_event.event_attributes["timerId"].should.equal("abc123") - second_to_last_event.event_attributes["startedEventId"].should.equal(1) - last_event.event_type.should.equal("DecisionTaskScheduled") + assert second_to_last_event.event_type == "TimerFired" + assert second_to_last_event.event_attributes["timerId"] == "abc123" + assert second_to_last_event.event_attributes["startedEventId"] == 1 + assert last_event.event_type == "DecisionTaskScheduled" def test_start_timer_fails_if_timer_already_started(): @@ -634,10 +634,10 @@ def test_start_timer_fails_if_timer_already_started(): wfe.start_timer(123, START_TIMER_EVENT_ATTRIBUTES) last_event = wfe.events()[-1] - last_event.event_type.should.equal("StartTimerFailed") - last_event.event_attributes["cause"].should.equal("TIMER_ID_ALREADY_IN_USE") - last_event.event_attributes["timerId"].should.equal("abc123") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "StartTimerFailed" + assert last_event.event_attributes["cause"] == "TIMER_ID_ALREADY_IN_USE" + assert last_event.event_attributes["timerId"] == "abc123" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 def test_cancel_timer(): @@ -649,10 +649,10 @@ def test_cancel_timer(): wfe.cancel_timer(123, "abc123") last_event = wfe.events()[-1] - last_event.event_type.should.equal("TimerCancelled") - last_event.event_attributes["startedEventId"].should.equal(1) - last_event.event_attributes["timerId"].should.equal("abc123") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "TimerCancelled" + assert last_event.event_attributes["startedEventId"] == 1 + assert last_event.event_attributes["timerId"] == "abc123" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 existing_timer.cancel.assert_called_once() assert not wfe._timers.get("abc123") @@ -663,9 +663,9 @@ def test_cancel_timer_fails_if_timer_not_found(): wfe.cancel_timer(123, "abc123") last_event = wfe.events()[-1] - last_event.event_type.should.equal("CancelTimerFailed") - last_event.event_attributes["cause"].should.equal("TIMER_ID_UNKNOWN") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "CancelTimerFailed" + assert last_event.event_attributes["cause"] == "TIMER_ID_UNKNOWN" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 def test_cancel_workflow(): @@ -675,9 +675,9 @@ def test_cancel_workflow(): wfe.cancel(123, "I want to cancel") last_event = wfe.events()[-1] - last_event.event_type.should.equal("WorkflowExecutionCanceled") - last_event.event_attributes["details"].should.equal("I want to cancel") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "WorkflowExecutionCanceled" + assert last_event.event_attributes["details"] == "I want to cancel" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 def test_cancel_workflow_fails_if_open_decision(): @@ -687,6 +687,6 @@ def test_cancel_workflow_fails_if_open_decision(): wfe.cancel(123, "I want to cancel") last_event = wfe.events()[-1] - last_event.event_type.should.equal("CancelWorkflowExecutionFailed") - last_event.event_attributes["cause"].should.equal("UNHANDLED_DECISION") - last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123) + assert last_event.event_type == "CancelWorkflowExecutionFailed" + assert last_event.event_attributes["cause"] == "UNHANDLED_DECISION" + assert last_event.event_attributes["decisionTaskCompletedEventId"] == 123 diff --git a/tests/test_swf/responses/test_activity_tasks.py b/tests/test_swf/responses/test_activity_tasks.py index 57d4625e9..541876af2 100644 --- a/tests/test_swf/responses/test_activity_tasks.py +++ b/tests/test_swf/responses/test_activity_tasks.py @@ -1,7 +1,8 @@ +import re +from unittest import SkipTest + from botocore.exceptions import ClientError from freezegun import freeze_time -import sure # noqa # pylint: disable=unused-import -from unittest import SkipTest import pytest from moto import mock_swf @@ -28,17 +29,18 @@ def test_poll_for_activity_task_when_one_boto3(): taskList={"name": "activity-task-list"}, identity="surprise", ) - resp["activityId"].should.equal("my-activity-001") - resp["taskToken"].should.match("[-a-z0-9]+") + assert resp["activityId"] == "my-activity-001" + assert re.match("[-a-z0-9]+", resp["taskToken"]) resp = client.get_workflow_execution_history( domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted") - resp["events"][-1]["activityTaskStartedEventAttributes"].should.equal( - {"identity": "surprise", "scheduledEventId": 5} - ) + assert resp["events"][-1]["eventType"] == "ActivityTaskStarted" + assert resp["events"][-1]["activityTaskStartedEventAttributes"] == { + "identity": "surprise", + "scheduledEventId": 5, + } @pytest.mark.parametrize("task_name", ["activity-task-list", "non-existent-queue"]) @@ -48,9 +50,9 @@ def test_poll_for_activity_task_when_none_boto3(task_name): resp = client.poll_for_decision_task( domain="test-domain", taskList={"name": task_name} ) - resp.shouldnt.have.key("taskToken") - resp.should.have.key("startedEventId").equal(0) - resp.should.have.key("previousStartedEventId").equal(0) + assert "taskToken" not in resp + assert resp["startedEventId"] == 0 + assert resp["previousStartedEventId"] == 0 # CountPendingActivityTasks endpoint @@ -72,8 +74,8 @@ def test_count_pending_activity_tasks_boto3(task_name, cnt): resp = client.count_pending_activity_tasks( domain="test-domain", taskList={"name": task_name} ) - resp.should.have.key("count").equal(cnt) - resp.should.have.key("truncated").equal(False) + assert resp["count"] == cnt + assert resp["truncated"] is False # RespondActivityTaskCompleted endpoint @@ -100,10 +102,12 @@ def test_respond_activity_task_completed_boto3(): domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["events"][-2]["eventType"].should.equal("ActivityTaskCompleted") - resp["events"][-2]["activityTaskCompletedEventAttributes"].should.equal( - {"result": "result of the task", "scheduledEventId": 5, "startedEventId": 6} - ) + assert resp["events"][-2]["eventType"] == "ActivityTaskCompleted" + assert resp["events"][-2]["activityTaskCompletedEventAttributes"] == { + "result": "result of the task", + "scheduledEventId": 5, + "startedEventId": 6, + } @mock_swf @@ -123,11 +127,11 @@ def test_respond_activity_task_completed_on_closed_workflow_execution_boto3(): with pytest.raises(ClientError) as ex: client.respond_activity_task_completed(taskToken=activity_token) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( f"Unknown execution: WorkflowExecution=[workflowId=uid-abcd1234, runId={client.run_id}]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -147,11 +151,11 @@ def test_respond_activity_task_completed_with_task_already_completed_boto3(): with pytest.raises(ClientError) as ex: client.respond_activity_task_completed(taskToken=activity_token) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown activity, scheduledEventId = 5" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # RespondActivityTaskFailed endpoint @@ -178,15 +182,13 @@ def test_respond_activity_task_failed_boto3(): domain="test-domain", execution={"runId": client.run_id, "workflowId": "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, - } - ) + assert resp["events"][-2]["eventType"] == "ActivityTaskFailed" + assert resp["events"][-2]["activityTaskFailedEventAttributes"] == { + "reason": "short reason", + "details": "long details", + "scheduledEventId": 5, + "startedEventId": 6, + } @mock_swf @@ -201,15 +203,15 @@ def test_respond_activity_task_completed_with_wrong_token_boto3(): client.respond_decision_task_completed( taskToken=decision_token, decisions=[SCHEDULE_ACTIVITY_TASK_DECISION] ) - client.poll_for_activity_task( + _ = client.poll_for_activity_task( domain="test-domain", taskList={"name": "activity-task-list"} )["taskToken"] with pytest.raises(ClientError) as ex: client.respond_activity_task_failed(taskToken="not-a-correct-token") - ex.value.response["Error"]["Code"].should.equal("ValidationException") - ex.value.response["Error"]["Message"].should.equal("Invalid token") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["Error"]["Code"] == "ValidationException" + assert ex.value.response["Error"]["Message"] == "Invalid token" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # RecordActivityTaskHeartbeat endpoint @@ -229,7 +231,7 @@ def test_record_activity_task_heartbeat_boto3(): )["taskToken"] resp = client.record_activity_task_heartbeat(taskToken=activity_token) - resp.should.have.key("cancelRequested").equal(False) + assert resp["cancelRequested"] is False @mock_swf @@ -241,15 +243,15 @@ def test_record_activity_task_heartbeat_with_wrong_token_boto3(): client.respond_decision_task_completed( taskToken=decision_token, decisions=[SCHEDULE_ACTIVITY_TASK_DECISION] ) - client.poll_for_activity_task( + _ = client.poll_for_activity_task( domain="test-domain", taskList={"name": "activity-task-list"} )["taskToken"] with pytest.raises(ClientError) as ex: client.record_activity_task_heartbeat(taskToken="bad-token") - ex.value.response["Error"]["Code"].should.equal("ValidationException") - ex.value.response["Error"]["Message"].should.equal("Invalid token") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["Error"]["Code"] == "ValidationException" + assert ex.value.response["Error"]["Message"] == "Invalid token" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -278,6 +280,6 @@ def test_record_activity_task_heartbeat_sets_details_in_case_of_timeout_boto3(): domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut") + assert resp["events"][-2]["eventType"] == "ActivityTaskTimedOut" attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"] - attrs["details"].should.equal("some progress details") + assert attrs["details"] == "some progress details" diff --git a/tests/test_swf/responses/test_activity_types.py b/tests/test_swf/responses/test_activity_types.py index 55d7b85ef..6ba3ef65d 100644 --- a/tests/test_swf/responses/test_activity_types.py +++ b/tests/test_swf/responses/test_activity_types.py @@ -1,6 +1,5 @@ import boto3 from botocore.exceptions import ClientError -import sure # noqa # pylint: disable=unused-import import pytest from moto import mock_swf @@ -20,10 +19,10 @@ def test_register_activity_type_boto3(): types = client.list_activity_types( domain="test-domain", registrationStatus="REGISTERED" )["typeInfos"] - types.should.have.length_of(1) + assert len(types) == 1 actype = types[0] - actype["activityType"]["name"].should.equal("test-activity") - actype["activityType"]["version"].should.equal("v1.0") + assert actype["activityType"]["name"] == "test-activity" + assert actype["activityType"]["version"] == "v1.0" @mock_swf @@ -40,11 +39,11 @@ def test_register_already_existing_activity_type_boto3(): client.register_activity_type( domain="test-domain", name="test-activity", version="v1.0" ) - ex.value.response["Error"]["Code"].should.equal("TypeAlreadyExistsFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "TypeAlreadyExistsFault" + assert ex.value.response["Error"]["Message"] == ( "ActivityType=[name=test-activity, version=v1.0]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # ListActivityTypes endpoint @@ -73,7 +72,7 @@ def test_list_activity_types_boto3(): names = [ activity_type["activityType"]["name"] for activity_type in types["typeInfos"] ] - names.should.equal(["a-test-activity", "b-test-activity", "c-test-activity"]) + assert names == ["a-test-activity", "b-test-activity", "c-test-activity"] @mock_swf @@ -99,7 +98,7 @@ def test_list_activity_types_reverse_order_boto3(): names = [ activity_type["activityType"]["name"] for activity_type in types["typeInfos"] ] - names.should.equal(["c-test-activity", "b-test-activity", "a-test-activity"]) + assert names == ["c-test-activity", "b-test-activity", "a-test-activity"] # DeprecateActivityType endpoint @@ -119,10 +118,10 @@ def test_deprecate_activity_type_boto3(): types = client.list_activity_types( domain="test-domain", registrationStatus="DEPRECATED" ) - types.should.have.key("typeInfos").being.length_of(1) + assert len(types["typeInfos"]) == 1 actype = types["typeInfos"][0] - actype["activityType"]["name"].should.equal("test-activity") - actype["activityType"]["version"].should.equal("v1.0") + assert actype["activityType"]["name"] == "test-activity" + assert actype["activityType"]["version"] == "v1.0" @mock_swf @@ -143,11 +142,11 @@ def test_deprecate_already_deprecated_activity_type_boto3(): domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("TypeDeprecatedFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "TypeDeprecatedFault" + assert ex.value.response["Error"]["Message"] == ( "ActivityType=[name=test-activity, version=v1.0]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -162,11 +161,11 @@ def test_deprecate_non_existent_activity_type_boto3(): domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown type: ActivityType=[name=test-activity, version=v1.0]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # DeprecateActivityType endpoint @@ -189,7 +188,7 @@ def test_undeprecate_activity_type(): resp = client.describe_activity_type( domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"} ) - resp["typeInfo"]["status"].should.equal("REGISTERED") + assert resp["typeInfo"]["status"] == "REGISTERED" @mock_swf @@ -208,9 +207,11 @@ def test_undeprecate_already_undeprecated_activity_type(): domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"} ) - client.undeprecate_activity_type.when.called_with( - domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"} - ).should.throw(ClientError) + with pytest.raises(ClientError): + client.undeprecate_activity_type( + domain="test-domain", + activityType={"name": "test-activity", "version": "v1.0"}, + ) @mock_swf @@ -223,9 +224,11 @@ def test_undeprecate_never_deprecated_activity_type(): domain="test-domain", name="test-activity", version="v1.0" ) - client.undeprecate_activity_type.when.called_with( - domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"} - ).should.throw(ClientError) + with pytest.raises(ClientError): + client.undeprecate_activity_type( + domain="test-domain", + activityType={"name": "test-activity", "version": "v1.0"}, + ) @mock_swf @@ -235,9 +238,11 @@ def test_undeprecate_non_existent_activity_type(): name="test-domain", workflowExecutionRetentionPeriodInDays="60" ) - client.undeprecate_activity_type.when.called_with( - domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"} - ).should.throw(ClientError) + with pytest.raises(ClientError): + client.undeprecate_activity_type( + domain="test-domain", + activityType={"name": "test-activity", "version": "v1.0"}, + ) # DescribeActivityType endpoint @@ -258,11 +263,11 @@ def test_describe_activity_type_boto3(): actype = client.describe_activity_type( domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"} ) - actype["configuration"]["defaultTaskList"]["name"].should.equal("foo") + assert actype["configuration"]["defaultTaskList"]["name"] == "foo" infos = actype["typeInfo"] - infos["activityType"]["name"].should.equal("test-activity") - infos["activityType"]["version"].should.equal("v1.0") - infos["status"].should.equal("REGISTERED") + assert infos["activityType"]["name"] == "test-activity" + assert infos["activityType"]["version"] == "v1.0" + assert infos["status"] == "REGISTERED" @mock_swf @@ -277,8 +282,8 @@ def test_describe_non_existent_activity_type_boto3(): domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown type: ActivityType=[name=test-activity, version=v1.0]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 diff --git a/tests/test_swf/responses/test_decision_tasks.py b/tests/test_swf/responses/test_decision_tasks.py index d7b356427..052c2e372 100644 --- a/tests/test_swf/responses/test_decision_tasks.py +++ b/tests/test_swf/responses/test_decision_tasks.py @@ -1,9 +1,10 @@ -from botocore.exceptions import ClientError from datetime import datetime +import re +from time import sleep + +from botocore.exceptions import ClientError from dateutil.parser import parse as dtparse from freezegun import freeze_time -from time import sleep -import sure # noqa # pylint: disable=unused-import import pytest from moto import mock_swf, settings @@ -23,18 +24,20 @@ def test_poll_for_decision_task_when_one_boto3(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) + assert types == ["WorkflowExecutionStarted", "DecisionTaskScheduled"] resp = client.poll_for_decision_task( domain="test-domain", taskList={"name": "queue"}, identity="srv01" ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"] - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + ] - resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal( - "srv01" + assert ( + resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"] == "srv01" ) @@ -75,14 +78,16 @@ def test_poll_for_decision_task_ensure_single_started_task(): resp = client.poll_for_decision_task( domain="test-domain", taskList={"name": "queue"} ) - resp.should.have.key("taskToken") + assert "taskToken" in resp first_decision_task = resp["taskToken"] # History should have just the decision task triggered on workflow start types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"] - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + ] # Schedule another decision task, before first one is completed client.signal_workflow_execution( @@ -99,42 +104,38 @@ def test_poll_for_decision_task_ensure_single_started_task(): ) assert resp["previousStartedEventId"] == 0 assert resp["startedEventId"] == 0 - assert resp.should_not.have.key("taskToken") + assert "taskToken" not in resp resp = client.get_workflow_execution_history( domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "WorkflowExecutionSignaled", - "DecisionTaskScheduled", - ] - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "WorkflowExecutionSignaled", + "DecisionTaskScheduled", + ] client.respond_decision_task_completed(taskToken=first_decision_task) resp = client.poll_for_decision_task( domain="test-domain", taskList={"name": "queue"} ) - resp.should.have.key("taskToken") + assert "taskToken" in resp types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "WorkflowExecutionSignaled", - "DecisionTaskScheduled", - "DecisionTaskCompleted", - "DecisionTaskStarted", - ] - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "WorkflowExecutionSignaled", + "DecisionTaskScheduled", + "DecisionTaskCompleted", + "DecisionTaskStarted", + ] @mock_swf @@ -146,7 +147,7 @@ def test_poll_for_decision_task_exclude_completed_executions(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) + assert types == ["WorkflowExecutionStarted", "DecisionTaskScheduled"] client.terminate_workflow_execution( domain="test-domain", runId=client.run_id, workflowId="uid-abcd1234" @@ -154,7 +155,7 @@ def test_poll_for_decision_task_exclude_completed_executions(): resp = client.poll_for_decision_task( domain="test-domain", taskList={"name": "queue"} ) - resp.should_not.have.key("taskToken") + assert "taskToken" not in resp @mock_swf @@ -168,8 +169,8 @@ def test_poll_for_decision_task_when_none_boto3(): ) # this is the DecisionTask representation you get from the real SWF # after waiting 60s when there's no decision to be taken - resp.should.have.key("previousStartedEventId").equal(0) - resp.should.have.key("startedEventId").equal(0) + assert resp["previousStartedEventId"] == 0 + assert resp["startedEventId"] == 0 @mock_swf @@ -178,8 +179,8 @@ def test_poll_for_decision_task_on_non_existent_queue_boto3(): resp = client.poll_for_decision_task( domain="test-domain", taskList={"name": "non-existent-queue"} ) - resp.should.have.key("previousStartedEventId").equal(0) - resp.should.have.key("startedEventId").equal(0) + assert resp["previousStartedEventId"] == 0 + assert resp["startedEventId"] == 0 @mock_swf @@ -189,9 +190,11 @@ def test_poll_for_decision_task_with_reverse_order_boto3(): domain="test-domain", taskList={"name": "queue"}, reverseOrder=True ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - ["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"] - ) + assert types == [ + "DecisionTaskStarted", + "DecisionTaskScheduled", + "WorkflowExecutionStarted", + ] # CountPendingDecisionTasks endpoint @@ -204,8 +207,8 @@ def test_count_pending_decision_tasks_boto3(): resp = client.count_pending_decision_tasks( domain="test-domain", taskList={"name": "queue"} ) - resp.should.have.key("count").equal(1) - resp.should.have.key("truncated").equal(False) + assert resp["count"] == 1 + assert resp["truncated"] is False @mock_swf @@ -214,8 +217,8 @@ def test_count_pending_decision_tasks_on_non_existent_task_list_boto3(): resp = client.count_pending_decision_tasks( domain="test-domain", taskList={"name": "non-existent"} ) - resp.should.have.key("count").equal(0) - resp.should.have.key("truncated").equal(False) + assert resp["count"] == 0 + assert resp["truncated"] is False @mock_swf @@ -229,8 +232,8 @@ def test_count_pending_decision_tasks_after_decision_completes_boto3(): resp = client.count_pending_decision_tasks( domain="test-domain", taskList={"name": "queue"} ) - resp.should.have.key("count").equal(0) - resp.should.have.key("truncated").equal(False) + assert resp["count"] == 0 + assert resp["truncated"] is False # RespondDecisionTaskCompleted endpoint @@ -253,28 +256,24 @@ def test_respond_decision_task_completed_with_no_decision_boto3(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskCompleted", - ] - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + ] evt = resp["events"][-1] - evt["decisionTaskCompletedEventAttributes"].should.equal( - { - "executionContext": "free-form context", - "scheduledEventId": 2, - "startedEventId": 3, - } - ) + assert evt["decisionTaskCompletedEventAttributes"] == { + "executionContext": "free-form context", + "scheduledEventId": 2, + "startedEventId": 3, + } resp = client.describe_workflow_execution( domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["latestExecutionContext"].should.equal("free-form context") + assert resp["latestExecutionContext"] == "free-form context" @mock_swf @@ -283,9 +282,9 @@ def test_respond_decision_task_completed_with_wrong_token_boto3(): client.poll_for_decision_task(domain="test-domain", taskList={"name": "queue"}) with pytest.raises(ClientError) as ex: client.respond_decision_task_completed(taskToken="not-a-correct-token") - ex.value.response["Error"]["Code"].should.equal("ValidationException") - ex.value.response["Error"]["Message"].should.equal("Invalid token") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["Error"]["Code"] == "ValidationException" + assert ex.value.response["Error"]["Message"] == "Invalid token" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -300,11 +299,11 @@ def test_respond_decision_task_completed_on_close_workflow_execution_boto3(): with pytest.raises(ClientError) as ex: client.respond_decision_task_completed(taskToken=task_token) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( f"Unknown execution: WorkflowExecution=[workflowId=uid-abcd1234, runId={client.run_id}]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -318,11 +317,11 @@ def test_respond_decision_task_completed_with_task_already_completed_boto3(): with pytest.raises(ClientError) as ex: client.respond_decision_task_completed(taskToken=task_token) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown decision task, scheduledEventId = 2" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -346,18 +345,17 @@ def test_respond_decision_task_completed_with_complete_workflow_execution_boto3( execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskCompleted", - "WorkflowExecutionCompleted", - ] + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + "WorkflowExecutionCompleted", + ] + assert ( + resp["events"][-1]["workflowExecutionCompletedEventAttributes"]["result"] + == "foo bar" ) - resp["events"][-1]["workflowExecutionCompletedEventAttributes"][ - "result" - ].should.equal("foo bar") @mock_swf @@ -377,11 +375,11 @@ def test_respond_decision_task_completed_with_close_decision_not_last_boto3(): client.respond_decision_task_completed( taskToken=task_token, decisions=decisions ) - ex.value.response["Error"]["Code"].should.equal("ValidationException") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "ValidationException" + assert ex.value.response["Error"]["Message"] == ( "Close must be last decision in list" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -401,11 +399,12 @@ def test_respond_decision_task_completed_with_invalid_decision_type_boto3(): client.respond_decision_task_completed( taskToken=task_token, decisions=decisions ) - ex.value.response["Error"]["Code"].should.equal("ValidationException") - ex.value.response["Error"]["Message"].should.match( - "Value 'BadDecisionType' at 'decisions.1.member.decisionType'" + assert ex.value.response["Error"]["Code"] == "ValidationException" + assert re.search( + "Value 'BadDecisionType' at 'decisions.1.member.decisionType'", + ex.value.response["Error"]["Message"], ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -422,11 +421,16 @@ def test_respond_decision_task_completed_with_missing_attributes_totally_boto3() client.respond_decision_task_completed( taskToken=task_token, decisions=decisions ) - ex.value.response["Error"]["Code"].should.equal("ValidationException") - ex.value.response["Error"]["Message"].should.match( - "Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' failed to satisfy constraint" + assert ex.value.response["Error"]["Code"] == "ValidationException" + assert re.search( + ( + "Value null at " + "'decisions.1.member.startTimerDecisionAttributes.timerId' " + "failed to satisfy constraint" + ), + ex.value.response["Error"]["Message"], ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -453,18 +457,16 @@ def test_respond_decision_task_completed_with_fail_workflow_execution_boto3(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskCompleted", - "WorkflowExecutionFailed", - ] - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + "WorkflowExecutionFailed", + ] attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"] - attrs["reason"].should.equal("my rules") - attrs["details"].should.equal("foo") + assert attrs["reason"] == "my rules" + assert attrs["details"] == "foo" @mock_swf @@ -495,34 +497,30 @@ def test_respond_decision_task_completed_with_schedule_activity_task_boto3(): execution={"runId": client.run_id, "workflowId": "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"}, - } - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + "ActivityTaskScheduled", + ] + assert resp["events"][-1]["activityTaskScheduledEventAttributes"] == { + "decisionTaskCompletedEventId": 4, + "activityId": "my-activity-001", + "activityType": {"name": "test-activity", "version": "v1.1"}, + "heartbeatTimeout": "60", + "input": "123", + "taskList": {"name": "my-task-list"}, + } resp = client.describe_workflow_execution( domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["latestActivityTaskTimestamp"].should.be.a(datetime) + assert isinstance(resp["latestActivityTaskTimestamp"], datetime) if not settings.TEST_SERVER_MODE: ts = resp["latestActivityTaskTimestamp"] - ts.should.equal(dtparse("2015-01-01 12:00:00 UTC")) + assert ts == dtparse("2015-01-01 12:00:00 UTC") @mock_swf @@ -546,18 +544,17 @@ def test_record_marker_decision(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskCompleted", - "MarkerRecorded", - ] - ) - resp["events"][-1]["markerRecordedEventAttributes"].should.equal( - {"decisionTaskCompletedEventId": 4, "markerName": "TheMarker"} - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + "MarkerRecorded", + ] + assert resp["events"][-1]["markerRecordedEventAttributes"] == { + "decisionTaskCompletedEventId": 4, + "markerName": "TheMarker", + } @mock_swf @@ -585,27 +582,24 @@ def test_start_and_fire_timer_decision(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskCompleted", - "TimerStarted", - "TimerFired", - "DecisionTaskScheduled", - ] - ) - resp["events"][-3]["timerStartedEventAttributes"].should.equal( - { - "decisionTaskCompletedEventId": 4, - "startToFireTimeout": "1", - "timerId": "timer1", - } - ) - resp["events"][-2]["timerFiredEventAttributes"].should.equal( - {"startedEventId": 5, "timerId": "timer1"} - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + "TimerStarted", + "TimerFired", + "DecisionTaskScheduled", + ] + assert resp["events"][-3]["timerStartedEventAttributes"] == { + "decisionTaskCompletedEventId": 4, + "startToFireTimeout": "1", + "timerId": "timer1", + } + assert resp["events"][-2]["timerFiredEventAttributes"] == { + "startedEventId": 5, + "timerId": "timer1", + } @mock_swf @@ -631,23 +625,22 @@ def test_cancel_workflow_decision(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskCompleted", - "WorkflowExecutionCanceled", - ] - ) - resp["events"][-1]["workflowExecutionCanceledEventAttributes"].should.equal( - {"decisionTaskCompletedEventId": 4, "details": "decide to cancel"} - ) + assert types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskCompleted", + "WorkflowExecutionCanceled", + ] + assert resp["events"][-1]["workflowExecutionCanceledEventAttributes"] == { + "decisionTaskCompletedEventId": 4, + "details": "decide to cancel", + } workflow_result = client.describe_workflow_execution( domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, )["executionInfo"] - workflow_result.should.contain("closeTimestamp") - workflow_result["executionStatus"].should.equal("CLOSED") - workflow_result["closeStatus"].should.equal("CANCELED") - workflow_result["cancelRequested"].should.equal(True) + assert "closeTimestamp" in workflow_result + assert workflow_result["executionStatus"] == "CLOSED" + assert workflow_result["closeStatus"] == "CANCELED" + assert workflow_result["cancelRequested"] is True diff --git a/tests/test_swf/responses/test_domains.py b/tests/test_swf/responses/test_domains.py index fda8625c5..6e99d0e92 100644 --- a/tests/test_swf/responses/test_domains.py +++ b/tests/test_swf/responses/test_domains.py @@ -1,215 +1,209 @@ -import boto3 -from botocore.exceptions import ClientError -import sure # noqa # pylint: disable=unused-import -import pytest - -from moto import mock_swf -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - - -# RegisterDomain endpoint -@mock_swf -def test_register_domain_boto3(): - client = boto3.client("swf", region_name="us-west-1") - client.register_domain( - name="test-domain", - workflowExecutionRetentionPeriodInDays="60", - description="A test domain", - ) - - all_domains = client.list_domains(registrationStatus="REGISTERED") - all_domains.should.have.key("domainInfos").being.length_of(1) - domain = all_domains["domainInfos"][0] - - domain["name"].should.equal("test-domain") - domain["status"].should.equal("REGISTERED") - domain["description"].should.equal("A test domain") - domain["arn"].should.equal( - f"arn:aws:swf:us-west-1:{ACCOUNT_ID}:/domain/test-domain" - ) - - -@mock_swf -def test_register_already_existing_domain_boto3(): - client = boto3.client("swf", region_name="us-west-1") - client.register_domain( - name="test-domain", - workflowExecutionRetentionPeriodInDays="60", - description="A test domain", - ) - - with pytest.raises(ClientError) as ex: - client.register_domain( - name="test-domain", - workflowExecutionRetentionPeriodInDays="60", - description="A test domain", - ) - ex.value.response["Error"]["Code"].should.equal("DomainAlreadyExistsFault") - ex.value.response["Error"]["Message"].should.equal("test-domain") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - - -# ListDomains endpoint -@mock_swf -def test_list_domains_order_boto3(): - client = boto3.client("swf", region_name="us-west-1") - client.register_domain( - name="b-test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.register_domain( - name="a-test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.register_domain( - name="c-test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - - all_domains = client.list_domains(registrationStatus="REGISTERED") - all_domains.should.have.key("domainInfos").being.length_of(3) - - 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_boto3(): - client = boto3.client("swf", region_name="us-west-1") - client.register_domain( - name="b-test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.register_domain( - name="a-test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.register_domain( - name="c-test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - - all_domains = client.list_domains( - registrationStatus="REGISTERED", reverseOrder=True - ) - all_domains.should.have.key("domainInfos").being.length_of(3) - - 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_boto3(): - client = boto3.client("swf", region_name="us-west-1") - client.register_domain( - name="test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.deprecate_domain(name="test-domain") - - all_domains = client.list_domains(registrationStatus="REGISTERED") - all_domains.should.have.key("domainInfos").being.length_of(0) - - all_domains = client.list_domains(registrationStatus="DEPRECATED") - all_domains.should.have.key("domainInfos").being.length_of(1) - - domain = all_domains["domainInfos"][0] - domain["name"].should.equal("test-domain") - - -@mock_swf -def test_deprecate_already_deprecated_domain_boto3(): - client = boto3.client("swf", region_name="us-west-1") - client.register_domain( - name="test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.deprecate_domain(name="test-domain") - - with pytest.raises(ClientError) as ex: - client.deprecate_domain(name="test-domain") - ex.value.response["Error"]["Code"].should.equal("DomainDeprecatedFault") - ex.value.response["Error"]["Message"].should.equal("test-domain") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - - -@mock_swf -def test_deprecate_non_existent_domain_boto3(): - client = boto3.client("swf", region_name="us-west-1") - - with pytest.raises(ClientError) as ex: - client.deprecate_domain(name="non-existent") - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal("Unknown domain: non-existent") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - - -# UndeprecateDomain endpoint -@mock_swf -def test_undeprecate_domain(): - client = boto3.client("swf", region_name="us-east-1") - client.register_domain( - name="test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.deprecate_domain(name="test-domain") - client.undeprecate_domain(name="test-domain") - - resp = client.describe_domain(name="test-domain") - - resp["domainInfo"]["status"].should.equal("REGISTERED") - - -@mock_swf -def test_undeprecate_already_undeprecated_domain(): - client = boto3.client("swf", region_name="us-east-1") - client.register_domain( - name="test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - client.deprecate_domain(name="test-domain") - client.undeprecate_domain(name="test-domain") - - client.undeprecate_domain.when.called_with(name="test-domain").should.throw( - ClientError - ) - - -@mock_swf -def test_undeprecate_never_deprecated_domain(): - client = boto3.client("swf", region_name="us-east-1") - client.register_domain( - name="test-domain", workflowExecutionRetentionPeriodInDays="60" - ) - - client.undeprecate_domain.when.called_with(name="test-domain").should.throw( - ClientError - ) - - -@mock_swf -def test_undeprecate_non_existent_domain(): - client = boto3.client("swf", region_name="us-east-1") - - client.undeprecate_domain.when.called_with(name="non-existent").should.throw( - ClientError - ) - - -# DescribeDomain endpoint -@mock_swf -def test_describe_domain_boto3(): - client = boto3.client("swf", region_name="us-east-1") - client.register_domain( - name="test-domain", - workflowExecutionRetentionPeriodInDays="60", - description="A test domain", - ) - - domain = client.describe_domain(name="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_boto3(): - client = boto3.client("swf", region_name="us-west-1") - - with pytest.raises(ClientError) as ex: - client.describe_domain(name="non-existent") - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal("Unknown domain: non-existent") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) +import boto3 +from botocore.exceptions import ClientError +import pytest + +from moto import mock_swf +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + + +# RegisterDomain endpoint +@mock_swf +def test_register_domain_boto3(): + client = boto3.client("swf", region_name="us-west-1") + client.register_domain( + name="test-domain", + workflowExecutionRetentionPeriodInDays="60", + description="A test domain", + ) + + all_domains = client.list_domains(registrationStatus="REGISTERED") + assert len(all_domains["domainInfos"]) == 1 + domain = all_domains["domainInfos"][0] + + assert domain["name"] == "test-domain" + assert domain["status"] == "REGISTERED" + assert domain["description"] == "A test domain" + assert domain["arn"] == f"arn:aws:swf:us-west-1:{ACCOUNT_ID}:/domain/test-domain" + + +@mock_swf +def test_register_already_existing_domain_boto3(): + client = boto3.client("swf", region_name="us-west-1") + client.register_domain( + name="test-domain", + workflowExecutionRetentionPeriodInDays="60", + description="A test domain", + ) + + with pytest.raises(ClientError) as ex: + client.register_domain( + name="test-domain", + workflowExecutionRetentionPeriodInDays="60", + description="A test domain", + ) + assert ex.value.response["Error"]["Code"] == "DomainAlreadyExistsFault" + assert ex.value.response["Error"]["Message"] == "test-domain" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + + +# ListDomains endpoint +@mock_swf +def test_list_domains_order_boto3(): + client = boto3.client("swf", region_name="us-west-1") + client.register_domain( + name="b-test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.register_domain( + name="a-test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.register_domain( + name="c-test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + + all_domains = client.list_domains(registrationStatus="REGISTERED") + assert len(all_domains["domainInfos"]) == 3 + + names = [domain["name"] for domain in all_domains["domainInfos"]] + assert names == ["a-test-domain", "b-test-domain", "c-test-domain"] + + +@mock_swf +def test_list_domains_reverse_order_boto3(): + client = boto3.client("swf", region_name="us-west-1") + client.register_domain( + name="b-test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.register_domain( + name="a-test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.register_domain( + name="c-test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + + all_domains = client.list_domains( + registrationStatus="REGISTERED", reverseOrder=True + ) + assert len(all_domains["domainInfos"]) == 3 + + names = [domain["name"] for domain in all_domains["domainInfos"]] + assert names == ["c-test-domain", "b-test-domain", "a-test-domain"] + + +# DeprecateDomain endpoint +@mock_swf +def test_deprecate_domain_boto3(): + client = boto3.client("swf", region_name="us-west-1") + client.register_domain( + name="test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.deprecate_domain(name="test-domain") + + all_domains = client.list_domains(registrationStatus="REGISTERED") + assert len(all_domains["domainInfos"]) == 0 + + all_domains = client.list_domains(registrationStatus="DEPRECATED") + assert len(all_domains["domainInfos"]) == 1 + + domain = all_domains["domainInfos"][0] + assert domain["name"] == "test-domain" + + +@mock_swf +def test_deprecate_already_deprecated_domain_boto3(): + client = boto3.client("swf", region_name="us-west-1") + client.register_domain( + name="test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.deprecate_domain(name="test-domain") + + with pytest.raises(ClientError) as ex: + client.deprecate_domain(name="test-domain") + assert ex.value.response["Error"]["Code"] == "DomainDeprecatedFault" + assert ex.value.response["Error"]["Message"] == "test-domain" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + + +@mock_swf +def test_deprecate_non_existent_domain_boto3(): + client = boto3.client("swf", region_name="us-west-1") + + with pytest.raises(ClientError) as ex: + client.deprecate_domain(name="non-existent") + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == "Unknown domain: non-existent" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + + +# UndeprecateDomain endpoint +@mock_swf +def test_undeprecate_domain(): + client = boto3.client("swf", region_name="us-east-1") + client.register_domain( + name="test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.deprecate_domain(name="test-domain") + client.undeprecate_domain(name="test-domain") + + resp = client.describe_domain(name="test-domain") + + assert resp["domainInfo"]["status"] == "REGISTERED" + + +@mock_swf +def test_undeprecate_already_undeprecated_domain(): + client = boto3.client("swf", region_name="us-east-1") + client.register_domain( + name="test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + client.deprecate_domain(name="test-domain") + client.undeprecate_domain(name="test-domain") + + with pytest.raises(ClientError): + client.undeprecate_domain(name="test-domain") + + +@mock_swf +def test_undeprecate_never_deprecated_domain(): + client = boto3.client("swf", region_name="us-east-1") + client.register_domain( + name="test-domain", workflowExecutionRetentionPeriodInDays="60" + ) + + with pytest.raises(ClientError): + client.undeprecate_domain(name="test-domain") + + +@mock_swf +def test_undeprecate_non_existent_domain(): + client = boto3.client("swf", region_name="us-east-1") + + with pytest.raises(ClientError): + client.undeprecate_domain(name="non-existent") + + +# DescribeDomain endpoint +@mock_swf +def test_describe_domain_boto3(): + client = boto3.client("swf", region_name="us-east-1") + client.register_domain( + name="test-domain", + workflowExecutionRetentionPeriodInDays="60", + description="A test domain", + ) + + domain = client.describe_domain(name="test-domain") + assert domain["configuration"]["workflowExecutionRetentionPeriodInDays"] == "60" + assert domain["domainInfo"]["description"] == "A test domain" + assert domain["domainInfo"]["name"] == "test-domain" + assert domain["domainInfo"]["status"] == "REGISTERED" + + +@mock_swf +def test_describe_non_existent_domain_boto3(): + client = boto3.client("swf", region_name="us-west-1") + + with pytest.raises(ClientError) as ex: + client.describe_domain(name="non-existent") + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == "Unknown domain: non-existent" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 diff --git a/tests/test_swf/responses/test_timeouts.py b/tests/test_swf/responses/test_timeouts.py index 94ad5d4f8..91f530992 100644 --- a/tests/test_swf/responses/test_timeouts.py +++ b/tests/test_swf/responses/test_timeouts.py @@ -1,8 +1,8 @@ from datetime import datetime +from unittest import SkipTest + from dateutil.parser import parse as dtparse from freezegun import freeze_time -import sure # noqa # pylint: disable=unused-import -from unittest import SkipTest from moto import mock_swf, settings @@ -35,7 +35,7 @@ def test_activity_task_heartbeat_timeout_boto3(): domain="test-domain", execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted") + assert resp["events"][-1]["eventType"] == "ActivityTaskStarted" with freeze_time("2015-01-01 12:05:30 UTC"): # => Activity Task Heartbeat timeout reached!! @@ -44,13 +44,13 @@ def test_activity_task_heartbeat_timeout_boto3(): execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, ) - resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut") + assert resp["events"][-2]["eventType"] == "ActivityTaskTimedOut" attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"] - attrs["timeoutType"].should.equal("HEARTBEAT") + assert attrs["timeoutType"] == "HEARTBEAT" # checks that event has been emitted at 12:05:00, not 12:05:30 - resp["events"][-2]["eventTimestamp"].should.be.a(datetime) + assert isinstance(resp["events"][-2]["eventTimestamp"], datetime) ts = resp["events"][-2]["eventTimestamp"] - ts.should.equal(dtparse("2015-01-01 12:05:00 UTC")) + assert ts == dtparse("2015-01-01 12:05:00 UTC") # Decision Task Start to Close timeout @@ -71,9 +71,11 @@ def test_decision_task_start_to_close_timeout_boto3(): ) event_types = [evt["eventType"] for evt in resp["events"]] - event_types.should.equal( - ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"] - ) + assert event_types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + ] with freeze_time("2015-01-01 12:05:30 UTC"): # => Decision Task Start to Close timeout reached!! @@ -83,27 +85,23 @@ def test_decision_task_start_to_close_timeout_boto3(): ) event_types = [evt["eventType"] for evt in resp["events"]] - event_types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "DecisionTaskStarted", - "DecisionTaskTimedOut", - "DecisionTaskScheduled", - ] - ) + assert event_types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "DecisionTaskStarted", + "DecisionTaskTimedOut", + "DecisionTaskScheduled", + ] attrs = resp["events"][-2]["decisionTaskTimedOutEventAttributes"] - attrs.should.equal( - { - "scheduledEventId": 2, - "startedEventId": 3, - "timeoutType": "START_TO_CLOSE", - } - ) + assert attrs == { + "scheduledEventId": 2, + "startedEventId": 3, + "timeoutType": "START_TO_CLOSE", + } # checks that event has been emitted at 12:05:00, not 12:05:30 - resp["events"][-2]["eventTimestamp"].should.be.a(datetime) + assert isinstance(resp["events"][-2]["eventTimestamp"], datetime) ts = resp["events"][-2]["eventTimestamp"] - ts.should.equal(dtparse("2015-01-01 12:05:00 UTC")) + assert ts == dtparse("2015-01-01 12:05:00 UTC") # Workflow Execution Start to Close timeout @@ -122,7 +120,7 @@ def test_workflow_execution_start_to_close_timeout_boto3(): ) event_types = [evt["eventType"] for evt in resp["events"]] - event_types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) + assert event_types == ["WorkflowExecutionStarted", "DecisionTaskScheduled"] with freeze_time("2015-01-01 14:00:30 UTC"): # => Workflow Execution Start to Close timeout reached!! @@ -132,16 +130,14 @@ def test_workflow_execution_start_to_close_timeout_boto3(): ) event_types = [evt["eventType"] for evt in resp["events"]] - event_types.should.equal( - [ - "WorkflowExecutionStarted", - "DecisionTaskScheduled", - "WorkflowExecutionTimedOut", - ] - ) + assert event_types == [ + "WorkflowExecutionStarted", + "DecisionTaskScheduled", + "WorkflowExecutionTimedOut", + ] attrs = resp["events"][-1]["workflowExecutionTimedOutEventAttributes"] - attrs.should.equal({"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"}) + assert attrs == {"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"} # checks that event has been emitted at 14:00:00, not 14:00:30 - resp["events"][-1]["eventTimestamp"].should.be.a(datetime) + assert isinstance(resp["events"][-1]["eventTimestamp"], datetime) ts = resp["events"][-1]["eventTimestamp"] - ts.should.equal(dtparse("2015-01-01 14:00:00 UTC")) + assert ts == dtparse("2015-01-01 14:00:00 UTC") diff --git a/tests/test_swf/responses/test_workflow_executions.py b/tests/test_swf/responses/test_workflow_executions.py index bf5f38301..21c0fbaca 100644 --- a/tests/test_swf/responses/test_workflow_executions.py +++ b/tests/test_swf/responses/test_workflow_executions.py @@ -1,8 +1,7 @@ -import boto3 -from botocore.exceptions import ClientError from datetime import datetime, timedelta -import sure # noqa # pylint: disable=unused-import +import boto3 +from botocore.exceptions import ClientError import pytest from moto import mock_swf @@ -41,7 +40,7 @@ def test_start_workflow_execution_boto3(): workflowId="uid-abcd1234", workflowType={"name": "test-workflow", "version": "v1.0"}, ) - wf.should.have.key("runId") + assert "runId" in wf @mock_swf @@ -66,7 +65,7 @@ def test_signal_workflow_execution_boto3(): domain="test-domain", execution={"runId": run_id, "workflowId": "uid-abcd1234"} ) - wfe["openCounts"]["openDecisionTasks"].should.equal(2) + assert wfe["openCounts"]["openDecisionTasks"] == 2 @mock_swf @@ -91,7 +90,7 @@ def test_signal_workflow_execution_without_runId(): ) types = [evt["eventType"] for evt in resp["events"]] - types.should.contain("WorkflowExecutionSignaled") + assert "WorkflowExecutionSignaled" in types @mock_swf @@ -109,11 +108,9 @@ def test_start_already_started_workflow_execution_boto3(): workflowId="uid-abcd1234", workflowType={"name": "test-workflow", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal( - "WorkflowExecutionAlreadyStartedFault" - ) - ex.value.response["Error"]["Message"].should.equal("Already Started") - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["Error"]["Code"] == "WorkflowExecutionAlreadyStartedFault" + assert ex.value.response["Error"]["Message"] == "Already Started" + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 @mock_swf @@ -129,11 +126,11 @@ def test_start_workflow_execution_on_deprecated_type_boto3(): workflowId="uid-abcd1234", workflowType={"name": "test-workflow", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("TypeDeprecatedFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "TypeDeprecatedFault" + assert ex.value.response["Error"]["Message"] == ( "WorkflowType=[name=test-workflow, version=v1.0]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # DescribeWorkflowExecution endpoint @@ -150,8 +147,8 @@ def test_describe_workflow_execution_boto3(): wfe = client.describe_workflow_execution( domain="test-domain", execution={"runId": run_id, "workflowId": "uid-abcd1234"} ) - wfe["executionInfo"]["execution"]["workflowId"].should.equal("uid-abcd1234") - wfe["executionInfo"]["executionStatus"].should.equal("OPEN") + assert wfe["executionInfo"]["execution"]["workflowId"] == "uid-abcd1234" + assert wfe["executionInfo"]["executionStatus"] == "OPEN" @mock_swf @@ -163,11 +160,11 @@ def test_describe_non_existent_workflow_execution_boto3(): domain="test-domain", execution={"runId": "wrong-run-id", "workflowId": "uid-abcd1234"}, ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown execution: WorkflowExecution=[workflowId=uid-abcd1234, runId=wrong-run-id]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # GetWorkflowExecutionHistory endpoint @@ -185,7 +182,7 @@ def test_get_workflow_execution_history_boto3(): domain="test-domain", execution={"runId": run_id, "workflowId": "uid-abcd1234"} ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) + assert types == ["WorkflowExecutionStarted", "DecisionTaskScheduled"] @mock_swf @@ -204,7 +201,7 @@ def test_get_workflow_execution_history_with_reverse_order_boto3(): reverseOrder=True, ) types = [evt["eventType"] for evt in resp["events"]] - types.should.equal(["DecisionTaskScheduled", "WorkflowExecutionStarted"]) + assert types == ["DecisionTaskScheduled", "WorkflowExecutionStarted"] @mock_swf @@ -216,11 +213,11 @@ def test_get_workflow_execution_history_on_non_existent_workflow_execution_boto3 domain="test-domain", execution={"runId": "wrong-run-id", "workflowId": "wrong-workflow-id"}, ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown execution: WorkflowExecution=[workflowId=wrong-workflow-id, runId=wrong-run-id]" ) - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) + assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400 # ListOpenWorkflowExecutions endpoint @@ -255,16 +252,14 @@ def test_list_open_workflow_executions_boto3(): executionFilter={"workflowId": "test-workflow"}, ) execution_infos = response["executionInfos"] - len(execution_infos).should.equal(1) + assert len(execution_infos) == 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") + assert open_workflow["workflowType"] == {"version": "v1.0", "name": "test-workflow"} + assert "startTimestamp" in open_workflow + assert open_workflow["execution"]["workflowId"] == "uid-abcd1234" + assert "runId" in open_workflow["execution"] + assert open_workflow["cancelRequested"] is False + assert open_workflow["executionStatus"] == "OPEN" # ListClosedWorkflowExecutions endpoint @@ -299,16 +294,14 @@ def test_list_closed_workflow_executions_boto3(): executionFilter={"workflowId": "test-workflow"}, ) execution_infos = response["executionInfos"] - len(execution_infos).should.equal(1) + assert len(execution_infos) == 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-abcd12345") - open_workflow["execution"].should.contain("runId") - open_workflow["cancelRequested"].should.be(False) - open_workflow["executionStatus"].should.equal("CLOSED") + assert open_workflow["workflowType"] == {"version": "v1.0", "name": "test-workflow"} + assert "startTimestamp" in open_workflow + assert open_workflow["execution"]["workflowId"] == "uid-abcd12345" + assert "runId" in open_workflow["execution"] + assert open_workflow["cancelRequested"] is False + assert open_workflow["executionStatus"] == "CLOSED" # TerminateWorkflowExecution endpoint @@ -333,11 +326,11 @@ def test_terminate_workflow_execution_boto3(): domain="test-domain", execution={"runId": run_id, "workflowId": "uid-abcd1234"} ) evt = resp["events"][-1] - evt["eventType"].should.equal("WorkflowExecutionTerminated") + assert evt["eventType"] == "WorkflowExecutionTerminated" attrs = evt["workflowExecutionTerminatedEventAttributes"] - attrs["details"].should.equal("some details") - attrs["reason"].should.equal("a more complete reason") - attrs["cause"].should.equal("OPERATOR_INITIATED") + assert attrs["details"] == "some details" + assert attrs["reason"] == "a more complete reason" + assert attrs["cause"] == "OPERATOR_INITIATED" @mock_swf @@ -357,8 +350,8 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id_boto3(): client.terminate_workflow_execution( domain="test-domain", workflowId="uid-abcd1234", runId=run_id ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( f"Unknown execution: WorkflowExecution=[workflowId=uid-abcd1234, runId={run_id}]" ) @@ -367,8 +360,8 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id_boto3(): client.terminate_workflow_execution( domain="test-domain", workflowId="uid-abcd1234" ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown execution, workflowId = uid-abcd1234" ) @@ -377,8 +370,8 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id_boto3(): client.terminate_workflow_execution( domain="test-domain", workflowId="uid-non-existent" ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown execution, workflowId = uid-non-existent" ) @@ -387,7 +380,7 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id_boto3(): client.terminate_workflow_execution( domain="test-domain", workflowId="uid-abcd1234", runId="foo" ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown execution: WorkflowExecution=[workflowId=uid-abcd1234, runId=foo]" ) diff --git a/tests/test_swf/responses/test_workflow_types.py b/tests/test_swf/responses/test_workflow_types.py index db42fd6b9..ae7553e2a 100644 --- a/tests/test_swf/responses/test_workflow_types.py +++ b/tests/test_swf/responses/test_workflow_types.py @@ -1,4 +1,3 @@ -import sure # noqa # pylint: disable=unused-import import boto3 import pytest @@ -21,8 +20,8 @@ def test_register_workflow_type_boto3(): domain="test-domain", registrationStatus="REGISTERED" ) actype = types["typeInfos"][0] - actype["workflowType"]["name"].should.equal("test-workflow") - actype["workflowType"]["version"].should.equal("v1.0") + assert actype["workflowType"]["name"] == "test-workflow" + assert actype["workflowType"]["version"] == "v1.0" @mock_swf @@ -39,8 +38,8 @@ def test_register_already_existing_workflow_type_boto3(): client.register_workflow_type( domain="test-domain", name="test-workflow", version="v1.0" ) - ex.value.response["Error"]["Code"].should.equal("TypeAlreadyExistsFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "TypeAlreadyExistsFault" + assert ex.value.response["Error"]["Message"] == ( "WorkflowType=[name=test-workflow, version=v1.0]" ) @@ -69,7 +68,7 @@ def test_list_workflow_types_boto3(): activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"] ] - names.should.equal(["a-test-workflow", "b-test-workflow", "c-test-workflow"]) + assert names == ["a-test-workflow", "b-test-workflow", "c-test-workflow"] # ListWorkflowTypes endpoint @@ -96,7 +95,7 @@ def test_list_workflow_types_reverse_order_boto3(): activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"] ] - names.should.equal(["c-test-workflow", "b-test-workflow", "a-test-workflow"]) + assert names == ["c-test-workflow", "b-test-workflow", "a-test-workflow"] # DeprecateWorkflowType endpoint @@ -117,8 +116,8 @@ def test_deprecate_workflow_type_boto3(): domain="test-domain", registrationStatus="DEPRECATED" ) actype = actypes["typeInfos"][0] - actype["workflowType"]["name"].should.equal("test-workflow") - actype["workflowType"]["version"].should.equal("v1.0") + assert actype["workflowType"]["name"] == "test-workflow" + assert actype["workflowType"]["version"] == "v1.0" @mock_swf @@ -139,8 +138,8 @@ def test_deprecate_already_deprecated_workflow_type_boto3(): domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("TypeDeprecatedFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "TypeDeprecatedFault" + assert ex.value.response["Error"]["Message"] == ( "WorkflowType=[name=test-workflow, version=v1.0]" ) @@ -157,8 +156,8 @@ def test_deprecate_non_existent_workflow_type_boto3(): domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown type: WorkflowType=[name=test-workflow, version=v1.0]" ) @@ -183,7 +182,7 @@ def test_undeprecate_workflow_type(): resp = client.describe_workflow_type( domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"} ) - resp["typeInfo"]["status"].should.equal("REGISTERED") + assert resp["typeInfo"]["status"] == "REGISTERED" @mock_swf @@ -202,9 +201,11 @@ def test_undeprecate_already_undeprecated_workflow_type(): domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"} ) - client.undeprecate_workflow_type.when.called_with( - domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"} - ).should.throw(ClientError) + with pytest.raises(ClientError): + client.undeprecate_workflow_type( + domain="test-domain", + workflowType={"name": "test-workflow", "version": "v1.0"}, + ) @mock_swf @@ -217,9 +218,11 @@ def test_undeprecate_never_deprecated_workflow_type(): domain="test-domain", name="test-workflow", version="v1.0" ) - client.undeprecate_workflow_type.when.called_with( - domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"} - ).should.throw(ClientError) + with pytest.raises(ClientError): + client.undeprecate_workflow_type( + domain="test-domain", + workflowType={"name": "test-workflow", "version": "v1.0"}, + ) @mock_swf @@ -229,9 +232,11 @@ def test_undeprecate_non_existent_workflow_type(): name="test-domain", workflowExecutionRetentionPeriodInDays="60" ) - client.undeprecate_workflow_type.when.called_with( - domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"} - ).should.throw(ClientError) + with pytest.raises(ClientError): + client.undeprecate_workflow_type( + domain="test-domain", + workflowType={"name": "test-workflow", "version": "v1.0"}, + ) # DescribeWorkflowType endpoint @@ -258,16 +263,16 @@ def test_describe_workflow_type_full_boto3(): resp = client.describe_workflow_type( domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"} ) - resp["typeInfo"]["workflowType"]["name"].should.equal("test-workflow") - resp["typeInfo"]["workflowType"]["version"].should.equal("v1.0") - resp["typeInfo"]["status"].should.equal("REGISTERED") - resp["typeInfo"]["description"].should.equal("Test workflow.") - resp["configuration"]["defaultTaskStartToCloseTimeout"].should.equal("20") - resp["configuration"]["defaultExecutionStartToCloseTimeout"].should.equal("60") - resp["configuration"]["defaultTaskList"]["name"].should.equal("foo") - resp["configuration"]["defaultTaskPriority"].should.equal("-2") - resp["configuration"]["defaultChildPolicy"].should.equal("ABANDON") - resp["configuration"]["defaultLambdaRole"].should.equal("arn:bar") + assert resp["typeInfo"]["workflowType"]["name"] == "test-workflow" + assert resp["typeInfo"]["workflowType"]["version"] == "v1.0" + assert resp["typeInfo"]["status"] == "REGISTERED" + assert resp["typeInfo"]["description"] == "Test workflow." + assert resp["configuration"]["defaultTaskStartToCloseTimeout"] == "20" + assert resp["configuration"]["defaultExecutionStartToCloseTimeout"] == "60" + assert resp["configuration"]["defaultTaskList"]["name"] == "foo" + assert resp["configuration"]["defaultTaskPriority"] == "-2" + assert resp["configuration"]["defaultChildPolicy"] == "ABANDON" + assert resp["configuration"]["defaultLambdaRole"] == "arn:bar" @mock_swf @@ -282,7 +287,7 @@ def test_describe_non_existent_workflow_type_boto3(): domain="test-domain", workflowType={"name": "non-existent", "version": "v1.0"}, ) - ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault") - ex.value.response["Error"]["Message"].should.equal( + assert ex.value.response["Error"]["Code"] == "UnknownResourceFault" + assert ex.value.response["Error"]["Message"] == ( "Unknown type: WorkflowType=[name=non-existent, version=v1.0]" ) diff --git a/tests/test_swf/test_exceptions.py b/tests/test_swf/test_exceptions.py index fc7f32c23..d85ce1f0e 100644 --- a/tests/test_swf/test_exceptions.py +++ b/tests/test_swf/test_exceptions.py @@ -1,6 +1,5 @@ -import sure # noqa # pylint: disable=unused-import - import json +import re from moto.swf.exceptions import ( SWFClientError, @@ -21,132 +20,116 @@ from moto.swf.models import WorkflowType def test_swf_client_error(): ex = SWFClientError("ASpecificType", "error message") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - {"__type": "ASpecificType", "message": "error message"} - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "ASpecificType", + "message": "error message", + } def test_swf_unknown_resource_fault(): ex = SWFUnknownResourceFault("type", "detail") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#UnknownResourceFault", - "message": "Unknown type: detail", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#UnknownResourceFault", + "message": "Unknown type: detail", + } def test_swf_unknown_resource_fault_with_only_one_parameter(): ex = SWFUnknownResourceFault("foo bar baz") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#UnknownResourceFault", - "message": "Unknown foo bar baz", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#UnknownResourceFault", + "message": "Unknown foo bar baz", + } def test_swf_domain_already_exists_fault(): ex = SWFDomainAlreadyExistsFault("domain-name") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#DomainAlreadyExistsFault", - "message": "domain-name", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#DomainAlreadyExistsFault", + "message": "domain-name", + } def test_swf_domain_deprecated_fault(): ex = SWFDomainDeprecatedFault("domain-name") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#DomainDeprecatedFault", - "message": "domain-name", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#DomainDeprecatedFault", + "message": "domain-name", + } def test_swf_serialization_exception(): ex = SWFSerializationException("value") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#SerializationException", - "message": "class java.lang.Foo can not be converted to an String (not a real SWF exception ; happened on: value)", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#SerializationException", + "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) - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#TypeAlreadyExistsFault", - "message": "WorkflowType=[name=wf-name, version=wf-version]", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#TypeAlreadyExistsFault", + "message": "WorkflowType=[name=wf-name, version=wf-version]", + } def test_swf_type_deprecated_fault(): wft = WorkflowType("wf-name", "wf-version") ex = SWFTypeDeprecatedFault(wft) - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#TypeDeprecatedFault", - "message": "WorkflowType=[name=wf-name, version=wf-version]", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#TypeDeprecatedFault", + "message": "WorkflowType=[name=wf-name, version=wf-version]", + } def test_swf_workflow_execution_already_started_fault(): ex = SWFWorkflowExecutionAlreadyStartedFault() - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#WorkflowExecutionAlreadyStartedFault", - "message": "Already Started", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#WorkflowExecutionAlreadyStartedFault", + "message": "Already Started", + } def test_swf_default_undefined_fault(): ex = SWFDefaultUndefinedFault("execution_start_to_close_timeout") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazonaws.swf.base.model#DefaultUndefinedFault", - "message": "executionStartToCloseTimeout", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazonaws.swf.base.model#DefaultUndefinedFault", + "message": "executionStartToCloseTimeout", + } def test_swf_validation_exception(): ex = SWFValidationException("Invalid token") - ex.code.should.equal(400) - json.loads(ex.get_body()).should.equal( - { - "__type": "com.amazon.coral.validate#ValidationException", - "message": "Invalid token", - } - ) + assert ex.code == 400 + assert json.loads(ex.get_body()) == { + "__type": "com.amazon.coral.validate#ValidationException", + "message": "Invalid token", + } def test_swf_decision_validation_error(): @@ -165,16 +148,18 @@ def test_swf_decision_validation_error(): ] ) - ex.code.should.equal(400) - ex.error_type.should.equal("com.amazon.coral.validate#ValidationException") + assert ex.code == 400 + assert ex.error_type == "com.amazon.coral.validate#ValidationException" msg = ex.get_body() - msg.should.match(r"2 validation errors detected:") - msg.should.match( + assert re.search(r"2 validation errors detected:", msg) + assert re.search( r"Value null at 'decisions.1.member.startTimerDecisionAttributes.startToFireTimeout' " - r"failed to satisfy constraint: Member must not be null;" + r"failed to satisfy constraint: Member must not be null;", + msg, ) - msg.should.match( + assert re.search( r"Value 'FooBar' at 'decisions.1.member.decisionType' failed to satisfy constraint: " - r"Member must satisfy enum value set: \[Foo, Bar, Baz\]" + r"Member must satisfy enum value set: \[Foo, Bar, Baz\]", + msg, ) diff --git a/tests/test_swf/test_utils.py b/tests/test_swf/test_utils.py index f0b9152e1..57ba8ec3e 100644 --- a/tests/test_swf/test_utils.py +++ b/tests/test_swf/test_utils.py @@ -1,9 +1,7 @@ -import sure # noqa # pylint: disable=unused-import - -from moto.swf.utils import decapitalize - - -def test_decapitalize(): - cases = {"fooBar": "fooBar", "FooBar": "fooBar", "FOO BAR": "fOO BAR"} - for before, after in cases.items(): - decapitalize(before).should.equal(after) +from moto.swf.utils import decapitalize + + +def test_decapitalize(): + cases = {"fooBar": "fooBar", "FooBar": "fooBar", "FOO BAR": "fOO BAR"} + for before, after in cases.items(): + assert decapitalize(before) == after