Merge pull request #2173 from sthuber90/master
Extending IoT Policy and Jobs functionality
This commit is contained in:
commit
b252ab6675
34 changed files with 3848 additions and 2720 deletions
|
|
@ -1,107 +1,107 @@
|
|||
from collections import namedtuple
|
||||
import sure # noqa
|
||||
|
||||
from moto.swf.exceptions import SWFUnknownResourceFault
|
||||
from moto.swf.models import Domain
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
|
||||
# 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")
|
||||
domain.to_short_dict().should.equal({"name": "foo", "status": "REGISTERED"})
|
||||
|
||||
domain.description = "foo bar"
|
||||
domain.to_short_dict()["description"].should.equal("foo bar")
|
||||
|
||||
|
||||
def test_domain_full_dict_representation():
|
||||
domain = Domain("foo", "52")
|
||||
|
||||
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")
|
||||
str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)")
|
||||
|
||||
|
||||
def test_domain_add_to_activity_task_list():
|
||||
domain = Domain("my-domain", "60")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
|
||||
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 sure # noqa
|
||||
|
||||
from moto.swf.exceptions import SWFUnknownResourceFault
|
||||
from moto.swf.models import Domain
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
|
||||
# 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")
|
||||
domain.to_short_dict().should.equal({"name": "foo", "status": "REGISTERED"})
|
||||
|
||||
domain.description = "foo bar"
|
||||
domain.to_short_dict()["description"].should.equal("foo bar")
|
||||
|
||||
|
||||
def test_domain_full_dict_representation():
|
||||
domain = Domain("foo", "52")
|
||||
|
||||
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")
|
||||
str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)")
|
||||
|
||||
|
||||
def test_domain_add_to_activity_task_list():
|
||||
domain = Domain("my-domain", "60")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
from freezegun import freeze_time
|
||||
import sure # noqa
|
||||
|
||||
from moto.swf.models import Timeout
|
||||
|
||||
from ..utils import make_workflow_execution
|
||||
|
||||
|
||||
def test_timeout_creation():
|
||||
wfe = make_workflow_execution()
|
||||
|
||||
# epoch 1420113600 == "2015-01-01 13:00:00"
|
||||
timeout = Timeout(wfe, 1420117200, "START_TO_CLOSE")
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
timeout.reached.should.be.falsy
|
||||
|
||||
with freeze_time("2015-01-01 13:00:00"):
|
||||
timeout.reached.should.be.truthy
|
||||
from freezegun import freeze_time
|
||||
import sure # noqa
|
||||
|
||||
from moto.swf.models import Timeout
|
||||
|
||||
from ..utils import make_workflow_execution
|
||||
|
||||
|
||||
def test_timeout_creation():
|
||||
wfe = make_workflow_execution()
|
||||
|
||||
# epoch 1420113600 == "2015-01-01 13:00:00"
|
||||
timeout = Timeout(wfe, 1420117200, "START_TO_CLOSE")
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
timeout.reached.should.be.falsy
|
||||
|
||||
with freeze_time("2015-01-01 13:00:00"):
|
||||
timeout.reached.should.be.truthy
|
||||
|
|
|
|||
|
|
@ -1,114 +1,114 @@
|
|||
import boto
|
||||
from boto.swf.exceptions import SWFResponseError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_swf_deprecated
|
||||
|
||||
|
||||
# RegisterDomain endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_register_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
domain = all_domains["domainInfos"][0]
|
||||
|
||||
domain["name"].should.equal("test-domain")
|
||||
domain["status"].should.equal("REGISTERED")
|
||||
domain["description"].should.equal("A test domain")
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_register_already_existing_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
conn.register_domain.when.called_with(
|
||||
"test-domain", "60", description="A test domain"
|
||||
).should.throw(SWFResponseError)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_register_with_wrong_parameter_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.register_domain.when.called_with(
|
||||
"test-domain", 60, description="A test domain"
|
||||
).should.throw(SWFResponseError)
|
||||
|
||||
|
||||
# ListDomains endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_list_domains_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
names = [domain["name"] for domain in all_domains["domainInfos"]]
|
||||
names.should.equal(["a-test-domain", "b-test-domain", "c-test-domain"])
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_list_domains_reverse_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED", reverse_order=True)
|
||||
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_deprecated
|
||||
def test_deprecate_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.deprecate_domain("test-domain")
|
||||
|
||||
all_domains = conn.list_domains("DEPRECATED")
|
||||
domain = all_domains["domainInfos"][0]
|
||||
|
||||
domain["name"].should.equal("test-domain")
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_deprecate_already_deprecated_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.deprecate_domain("test-domain")
|
||||
|
||||
conn.deprecate_domain.when.called_with("test-domain").should.throw(SWFResponseError)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_deprecate_non_existent_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.deprecate_domain.when.called_with("non-existent").should.throw(
|
||||
SWFResponseError
|
||||
)
|
||||
|
||||
|
||||
# DescribeDomain endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_describe_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
domain = conn.describe_domain("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_deprecated
|
||||
def test_describe_non_existent_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.describe_domain.when.called_with("non-existent").should.throw(SWFResponseError)
|
||||
import boto
|
||||
from boto.swf.exceptions import SWFResponseError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_swf_deprecated
|
||||
|
||||
|
||||
# RegisterDomain endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_register_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
domain = all_domains["domainInfos"][0]
|
||||
|
||||
domain["name"].should.equal("test-domain")
|
||||
domain["status"].should.equal("REGISTERED")
|
||||
domain["description"].should.equal("A test domain")
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_register_already_existing_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
conn.register_domain.when.called_with(
|
||||
"test-domain", "60", description="A test domain"
|
||||
).should.throw(SWFResponseError)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_register_with_wrong_parameter_type():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.register_domain.when.called_with(
|
||||
"test-domain", 60, description="A test domain"
|
||||
).should.throw(SWFResponseError)
|
||||
|
||||
|
||||
# ListDomains endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_list_domains_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
names = [domain["name"] for domain in all_domains["domainInfos"]]
|
||||
names.should.equal(["a-test-domain", "b-test-domain", "c-test-domain"])
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_list_domains_reverse_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED", reverse_order=True)
|
||||
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_deprecated
|
||||
def test_deprecate_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.deprecate_domain("test-domain")
|
||||
|
||||
all_domains = conn.list_domains("DEPRECATED")
|
||||
domain = all_domains["domainInfos"][0]
|
||||
|
||||
domain["name"].should.equal("test-domain")
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_deprecate_already_deprecated_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
conn.deprecate_domain("test-domain")
|
||||
|
||||
conn.deprecate_domain.when.called_with("test-domain").should.throw(SWFResponseError)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_deprecate_non_existent_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.deprecate_domain.when.called_with("non-existent").should.throw(
|
||||
SWFResponseError
|
||||
)
|
||||
|
||||
|
||||
# DescribeDomain endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_describe_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("test-domain", "60", description="A test domain")
|
||||
|
||||
domain = conn.describe_domain("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_deprecated
|
||||
def test_describe_non_existent_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
|
||||
conn.describe_domain.when.called_with("non-existent").should.throw(SWFResponseError)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import sure # noqa
|
||||
|
||||
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)
|
||||
import sure # noqa
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue