Fix incorrect response for put-targets action (#3037)

This commit is contained in:
Victor Le Fichant 2020-06-02 17:31:42 +02:00 committed by GitHub
parent 2433d64fe2
commit cb600377b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -217,7 +217,10 @@ class EventsHandler(BaseResponse):
"ResourceNotFoundException", "Rule " + rule_name + " does not exist."
)
return "", self.response_headers
return (
json.dumps({"FailedEntryCount": 0, "FailedEntries": []}),
self.response_headers,
)
def remove_targets(self):
rule_name = self._get_param("Rule")

View File

@ -4,6 +4,7 @@ import unittest
import boto3
import sure # noqa
from botocore.exceptions import ClientError
from nose.tools import assert_raises
@ -201,6 +202,35 @@ def test_remove_targets():
assert targets_before - 1 == targets_after
@mock_events
def test_put_targets():
client = boto3.client("events", "us-west-2")
rule_name = "my-event"
rule_data = {
"Name": rule_name,
"ScheduleExpression": "rate(5 minutes)",
"EventPattern": '{"source": ["test-source"]}',
}
client.put_rule(**rule_data)
targets = client.list_targets_by_rule(Rule=rule_name)["Targets"]
targets_before = len(targets)
assert targets_before == 0
targets_data = [{"Arn": "test_arn", "Id": "test_id"}]
resp = client.put_targets(Rule=rule_name, Targets=targets_data)
assert resp["FailedEntryCount"] == 0
assert len(resp["FailedEntries"]) == 0
targets = client.list_targets_by_rule(Rule=rule_name)["Targets"]
targets_after = len(targets)
assert targets_before + 1 == targets_after
assert targets[0]["Arn"] == "test_arn"
assert targets[0]["Id"] == "test_id"
@mock_events
def test_permissions():
client = boto3.client("events", "eu-central-1")