Merge branch 'master' into bugfix/#2567
This commit is contained in:
commit
fbb449aa48
21 changed files with 432 additions and 34 deletions
|
|
@ -274,9 +274,7 @@ def test_access_denied_with_not_allowing_policy():
|
|||
user_name = "test-user"
|
||||
inline_policy_document = {
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{"Effect": "Allow", "Action": ["ec2:Describe*"], "Resource": "*"}
|
||||
],
|
||||
"Statement": [{"Effect": "Allow", "Action": ["ec2:Run*"], "Resource": "*"}],
|
||||
}
|
||||
access_key = create_user_with_access_key_and_inline_policy(
|
||||
user_name, inline_policy_document
|
||||
|
|
@ -288,12 +286,14 @@ def test_access_denied_with_not_allowing_policy():
|
|||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
client.run_instances(MaxCount=1, MinCount=1)
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
|
||||
account_id=ACCOUNT_ID, user_name=user_name, operation="ec2:RunInstances"
|
||||
account_id=ACCOUNT_ID,
|
||||
user_name=user_name,
|
||||
operation="ec2:DescribeInstances",
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3634,6 +3634,31 @@ def test_update_supports_list_append_with_nested_if_not_exists_operation():
|
|||
)
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_supports_list_append_with_nested_if_not_exists_operation_and_property_already_exists():
|
||||
dynamo = boto3.resource("dynamodb", region_name="us-west-1")
|
||||
table_name = "test"
|
||||
|
||||
dynamo.create_table(
|
||||
TableName=table_name,
|
||||
AttributeDefinitions=[{"AttributeName": "Id", "AttributeType": "S"}],
|
||||
KeySchema=[{"AttributeName": "Id", "KeyType": "HASH"}],
|
||||
ProvisionedThroughput={"ReadCapacityUnits": 20, "WriteCapacityUnits": 20},
|
||||
)
|
||||
|
||||
table = dynamo.Table(table_name)
|
||||
|
||||
table.put_item(Item={"Id": "item-id", "event_history": ["other_value"]})
|
||||
table.update_item(
|
||||
Key={"Id": "item-id"},
|
||||
UpdateExpression="SET event_history = list_append(if_not_exists(event_history, :empty_list), :new_value)",
|
||||
ExpressionAttributeValues={":empty_list": [], ":new_value": ["some_value"]},
|
||||
)
|
||||
table.get_item(Key={"Id": "item-id"})["Item"].should.equal(
|
||||
{"Id": "item-id", "event_history": ["other_value", "some_value"]}
|
||||
)
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_catches_invalid_list_append_operation():
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
|
|
|||
|
|
@ -753,6 +753,79 @@ def test_change_weighted_resource_record_sets():
|
|||
record["Weight"].should.equal(10)
|
||||
|
||||
|
||||
@mock_route53
|
||||
def test_failover_record_sets():
|
||||
conn = boto3.client("route53", region_name="us-east-2")
|
||||
conn.create_hosted_zone(Name="test.zone.", CallerReference=str(hash("test")))
|
||||
zones = conn.list_hosted_zones_by_name(DNSName="test.zone.")
|
||||
hosted_zone_id = zones["HostedZones"][0]["Id"]
|
||||
|
||||
# Create geolocation record
|
||||
conn.change_resource_record_sets(
|
||||
HostedZoneId=hosted_zone_id,
|
||||
ChangeBatch={
|
||||
"Changes": [
|
||||
{
|
||||
"Action": "CREATE",
|
||||
"ResourceRecordSet": {
|
||||
"Name": "failover.test.zone.",
|
||||
"Type": "A",
|
||||
"TTL": 10,
|
||||
"ResourceRecords": [{"Value": "127.0.0.1"}],
|
||||
"Failover": "PRIMARY",
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
|
||||
record = response["ResourceRecordSets"][0]
|
||||
record["Failover"].should.equal("PRIMARY")
|
||||
|
||||
|
||||
@mock_route53
|
||||
def test_geolocation_record_sets():
|
||||
conn = boto3.client("route53", region_name="us-east-2")
|
||||
conn.create_hosted_zone(Name="test.zone.", CallerReference=str(hash("test")))
|
||||
zones = conn.list_hosted_zones_by_name(DNSName="test.zone.")
|
||||
hosted_zone_id = zones["HostedZones"][0]["Id"]
|
||||
|
||||
# Create geolocation record
|
||||
conn.change_resource_record_sets(
|
||||
HostedZoneId=hosted_zone_id,
|
||||
ChangeBatch={
|
||||
"Changes": [
|
||||
{
|
||||
"Action": "CREATE",
|
||||
"ResourceRecordSet": {
|
||||
"Name": "georecord1.test.zone.",
|
||||
"Type": "A",
|
||||
"TTL": 10,
|
||||
"ResourceRecords": [{"Value": "127.0.0.1"}],
|
||||
"GeoLocation": {"ContinentCode": "EU"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"Action": "CREATE",
|
||||
"ResourceRecordSet": {
|
||||
"Name": "georecord2.test.zone.",
|
||||
"Type": "A",
|
||||
"TTL": 10,
|
||||
"ResourceRecords": [{"Value": "127.0.0.2"}],
|
||||
"GeoLocation": {"CountryCode": "US", "SubdivisionCode": "NY"},
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
|
||||
rrs = response["ResourceRecordSets"]
|
||||
rrs[0]["GeoLocation"].should.equal({"ContinentCode": "EU"})
|
||||
rrs[1]["GeoLocation"].should.equal({"CountryCode": "US", "SubdivisionCode": "NY"})
|
||||
|
||||
|
||||
@mock_route53
|
||||
def test_change_resource_record_invalid():
|
||||
conn = boto3.client("route53", region_name="us-east-1")
|
||||
|
|
|
|||
|
|
@ -30,6 +30,18 @@ def test_delete_parameter():
|
|||
len(response["Parameters"]).should.equal(0)
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_delete_nonexistent_parameter():
|
||||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
client.delete_parameter(Name="test_noexist")
|
||||
ex.exception.response["Error"]["Code"].should.equal("ParameterNotFound")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Parameter test_noexist not found."
|
||||
)
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_delete_parameters():
|
||||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
|
|
|||
|
|
@ -24,15 +24,16 @@ def test_decision_task_full_dict_representation():
|
|||
|
||||
fd = dt.to_full_dict()
|
||||
fd["events"].should.be.a("list")
|
||||
fd["previousStartedEventId"].should.equal(0)
|
||||
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())
|
||||
|
||||
dt.start(1234)
|
||||
dt.start(1234, 1230)
|
||||
fd = dt.to_full_dict()
|
||||
fd["startedEventId"].should.equal(1234)
|
||||
fd["previousStartedEventId"].should.equal(1230)
|
||||
|
||||
|
||||
def test_decision_task_first_timeout():
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@ def test_poll_for_activity_task_when_one():
|
|||
def test_poll_for_activity_task_when_none():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_activity_task("test-domain", "activity-task-list")
|
||||
resp.should.equal({"startedEventId": 0})
|
||||
resp.should.equal({"startedEventId": 0, "taskToken": ""})
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_poll_for_activity_task_on_non_existent_queue():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_activity_task("test-domain", "non-existent-queue")
|
||||
resp.should.equal({"startedEventId": 0})
|
||||
resp.should.equal({"startedEventId": 0, "taskToken": ""})
|
||||
|
||||
|
||||
# CountPendingActivityTasks endpoint
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import boto
|
||||
from boto.swf.exceptions import SWFResponseError
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_swf_deprecated
|
||||
from moto import mock_swf
|
||||
|
||||
|
||||
# RegisterActivityType endpoint
|
||||
|
|
@ -110,6 +113,77 @@ def test_deprecate_non_existent_activity_type():
|
|||
).should.throw(SWFResponseError)
|
||||
|
||||
|
||||
# DeprecateActivityType endpoint
|
||||
@mock_swf
|
||||
def test_undeprecate_activity_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
name="test-domain", workflowExecutionRetentionPeriodInDays="60"
|
||||
)
|
||||
client.register_activity_type(
|
||||
domain="test-domain", name="test-activity", version="v1.0"
|
||||
)
|
||||
client.deprecate_activity_type(
|
||||
domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}
|
||||
)
|
||||
client.undeprecate_activity_type(
|
||||
domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}
|
||||
)
|
||||
|
||||
resp = client.describe_activity_type(
|
||||
domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}
|
||||
)
|
||||
resp["typeInfo"]["status"].should.equal("REGISTERED")
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_undeprecate_already_undeprecated_activity_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
name="test-domain", workflowExecutionRetentionPeriodInDays="60"
|
||||
)
|
||||
client.register_activity_type(
|
||||
domain="test-domain", name="test-activity", version="v1.0"
|
||||
)
|
||||
client.deprecate_activity_type(
|
||||
domain="test-domain", activityType={"name": "test-activity", "version": "v1.0"}
|
||||
)
|
||||
client.undeprecate_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)
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_undeprecate_never_deprecated_activity_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
name="test-domain", workflowExecutionRetentionPeriodInDays="60"
|
||||
)
|
||||
client.register_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)
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_undeprecate_non_existent_activity_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
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)
|
||||
|
||||
|
||||
# DescribeActivityType endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_describe_activity_type():
|
||||
|
|
|
|||
|
|
@ -30,6 +30,30 @@ def test_poll_for_decision_task_when_one():
|
|||
)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_poll_for_decision_task_previous_started_event_id():
|
||||
conn = setup_workflow()
|
||||
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue")
|
||||
assert resp["workflowExecution"]["runId"] == conn.run_id
|
||||
assert "previousStartedEventId" not in resp
|
||||
|
||||
# Require a failing decision, in this case a non-existant activity type
|
||||
attrs = {
|
||||
"activityId": "spam",
|
||||
"activityType": {"name": "test-activity", "version": "v1.42"},
|
||||
"taskList": "eggs",
|
||||
}
|
||||
decision = {
|
||||
"decisionType": "ScheduleActivityTask",
|
||||
"scheduleActivityTaskDecisionAttributes": attrs,
|
||||
}
|
||||
conn.respond_decision_task_completed(resp["taskToken"], decisions=[decision])
|
||||
resp = conn.poll_for_decision_task("test-domain", "queue")
|
||||
assert resp["workflowExecution"]["runId"] == conn.run_id
|
||||
assert resp["previousStartedEventId"] == 3
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_poll_for_decision_task_when_none():
|
||||
conn = setup_workflow()
|
||||
|
|
@ -38,14 +62,18 @@ def test_poll_for_decision_task_when_none():
|
|||
resp = conn.poll_for_decision_task("test-domain", "queue")
|
||||
# this is the DecisionTask representation you get from the real SWF
|
||||
# after waiting 60s when there's no decision to be taken
|
||||
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
|
||||
resp.should.equal(
|
||||
{"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""}
|
||||
)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
def test_poll_for_decision_task_on_non_existent_queue():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_decision_task("test-domain", "non-existent-queue")
|
||||
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
|
||||
resp.should.equal(
|
||||
{"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""}
|
||||
)
|
||||
|
||||
|
||||
@mock_swf_deprecated
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import boto
|
||||
from boto.swf.exceptions import SWFResponseError
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_swf_deprecated
|
||||
from moto import mock_swf
|
||||
|
||||
|
||||
# RegisterDomain endpoint
|
||||
|
|
@ -94,6 +97,56 @@ def test_deprecate_non_existent_domain():
|
|||
)
|
||||
|
||||
|
||||
# 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_deprecated
|
||||
def test_describe_domain():
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import boto3
|
|||
from moto import mock_swf_deprecated
|
||||
from moto import mock_swf
|
||||
from boto.swf.exceptions import SWFResponseError
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
|
||||
# RegisterWorkflowType endpoint
|
||||
|
|
@ -112,6 +113,77 @@ def test_deprecate_non_existent_workflow_type():
|
|||
).should.throw(SWFResponseError)
|
||||
|
||||
|
||||
# UndeprecateWorkflowType endpoint
|
||||
@mock_swf
|
||||
def test_undeprecate_workflow_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
name="test-domain", workflowExecutionRetentionPeriodInDays="60"
|
||||
)
|
||||
client.register_workflow_type(
|
||||
domain="test-domain", name="test-workflow", version="v1.0"
|
||||
)
|
||||
client.deprecate_workflow_type(
|
||||
domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"}
|
||||
)
|
||||
client.undeprecate_workflow_type(
|
||||
domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"}
|
||||
)
|
||||
|
||||
resp = client.describe_workflow_type(
|
||||
domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"}
|
||||
)
|
||||
resp["typeInfo"]["status"].should.equal("REGISTERED")
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_undeprecate_already_undeprecated_workflow_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
name="test-domain", workflowExecutionRetentionPeriodInDays="60"
|
||||
)
|
||||
client.register_workflow_type(
|
||||
domain="test-domain", name="test-workflow", version="v1.0"
|
||||
)
|
||||
client.deprecate_workflow_type(
|
||||
domain="test-domain", workflowType={"name": "test-workflow", "version": "v1.0"}
|
||||
)
|
||||
client.undeprecate_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)
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_undeprecate_never_deprecated_workflow_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
name="test-domain", workflowExecutionRetentionPeriodInDays="60"
|
||||
)
|
||||
client.register_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)
|
||||
|
||||
|
||||
@mock_swf
|
||||
def test_undeprecate_non_existent_workflow_type():
|
||||
client = boto3.client("swf", region_name="us-east-1")
|
||||
client.register_domain(
|
||||
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)
|
||||
|
||||
|
||||
# DescribeWorkflowType endpoint
|
||||
@mock_swf_deprecated
|
||||
def test_describe_workflow_type():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue