2018-12-21 11:28:56 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
import sure # noqa
|
|
|
|
|
2021-04-23 14:20:36 +00:00
|
|
|
from moto.core import ACCOUNT_ID
|
2018-12-21 11:28:56 +00:00
|
|
|
from moto.swf.exceptions import SWFUnknownResourceFault
|
|
|
|
from moto.swf.models import Domain
|
|
|
|
|
2021-04-23 14:20:36 +00:00
|
|
|
TEST_REGION = "us-east-1"
|
2018-12-21 11:28:56 +00:00
|
|
|
# Fake WorkflowExecution for tests purposes
|
|
|
|
WorkflowExecution = namedtuple(
|
2019-12-23 07:38:53 +00:00
|
|
|
"WorkflowExecution", ["workflow_id", "run_id", "execution_status", "open"]
|
2018-12-21 11:28:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_domain_short_dict_representation():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("foo", "52", TEST_REGION)
|
|
|
|
domain.to_short_dict().should.equal(
|
|
|
|
{
|
|
|
|
"name": "foo",
|
|
|
|
"status": "REGISTERED",
|
|
|
|
"arn": "arn:aws:swf:{0}:{1}:/domain/foo".format(TEST_REGION, ACCOUNT_ID),
|
|
|
|
}
|
|
|
|
)
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
domain.description = "foo bar"
|
|
|
|
domain.to_short_dict()["description"].should.equal("foo bar")
|
|
|
|
|
|
|
|
|
|
|
|
def test_domain_full_dict_representation():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("foo", "52", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
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():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("my-domain", "60", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_domain_add_to_activity_task_list():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("my-domain", "60", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
domain.add_to_activity_task_list("foo", "bar")
|
2019-12-23 07:38:53 +00:00
|
|
|
domain.activity_task_lists.should.equal({"foo": ["bar"]})
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_domain_activity_tasks():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("my-domain", "60", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
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():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("my-domain", "60", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
domain.add_to_decision_task_list("foo", "bar")
|
2019-12-23 07:38:53 +00:00
|
|
|
domain.decision_task_lists.should.equal({"foo": ["bar"]})
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_domain_decision_tasks():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("my-domain", "60", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
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():
|
2021-04-23 14:20:36 +00:00
|
|
|
domain = Domain("my-domain", "60", TEST_REGION)
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
wfe1 = WorkflowExecution(
|
2019-12-23 07:38:53 +00:00
|
|
|
workflow_id="wf-id-1", run_id="run-id-1", execution_status="OPEN", open=True
|
|
|
|
)
|
2018-12-21 11:28:56 +00:00
|
|
|
wfe2 = WorkflowExecution(
|
2019-12-23 07:38:53 +00:00
|
|
|
workflow_id="wf-id-1", run_id="run-id-2", execution_status="CLOSED", open=False
|
|
|
|
)
|
2018-12-21 11:28:56 +00:00
|
|
|
wfe3 = WorkflowExecution(
|
2019-12-23 07:38:53 +00:00
|
|
|
workflow_id="wf-id-2", run_id="run-id-3", execution_status="OPEN", open=True
|
|
|
|
)
|
2018-12-21 11:28:56 +00:00
|
|
|
wfe4 = WorkflowExecution(
|
2019-12-23 07:38:53 +00:00
|
|
|
workflow_id="wf-id-3", run_id="run-id-4", execution_status="CLOSED", open=False
|
|
|
|
)
|
2018-12-21 11:28:56 +00:00
|
|
|
domain.workflow_executions = [wfe1, wfe2, wfe3, wfe4]
|
|
|
|
|
|
|
|
# get workflow execution through workflow_id and run_id
|
2019-12-23 07:38:53 +00:00
|
|
|
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)
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
domain.get_workflow_execution.when.called_with(
|
|
|
|
"wf-id-1", run_id="non-existent"
|
2019-12-23 07:38:53 +00:00
|
|
|
).should.throw(SWFUnknownResourceFault)
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
# get OPEN workflow execution by default if no run_id
|
|
|
|
domain.get_workflow_execution("wf-id-1").should.equal(wfe1)
|
2019-12-23 07:38:53 +00:00
|
|
|
domain.get_workflow_execution.when.called_with("wf-id-3").should.throw(
|
2018-12-21 11:28:56 +00:00
|
|
|
SWFUnknownResourceFault
|
|
|
|
)
|
2019-12-23 07:38:53 +00:00
|
|
|
domain.get_workflow_execution.when.called_with("wf-id-non-existent").should.throw(
|
2018-12-21 11:28:56 +00:00
|
|
|
SWFUnknownResourceFault
|
|
|
|
)
|
|
|
|
|
|
|
|
# raise_if_closed attribute
|
|
|
|
domain.get_workflow_execution(
|
2019-12-23 07:38:53 +00:00
|
|
|
"wf-id-1", run_id="run-id-1", raise_if_closed=True
|
|
|
|
).should.equal(wfe1)
|
2018-12-21 11:28:56 +00:00
|
|
|
domain.get_workflow_execution.when.called_with(
|
|
|
|
"wf-id-3", run_id="run-id-4", raise_if_closed=True
|
2019-12-23 07:38:53 +00:00
|
|
|
).should.throw(SWFUnknownResourceFault)
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
# raise_if_none attribute
|
|
|
|
domain.get_workflow_execution("foo", raise_if_none=False).should.be.none
|