Fix: Put Events API (#3145)

* Fix: Put Events API

* Update from code review.

Co-authored-by: Logan Asher Jones <logan@codescratch.com>
This commit is contained in:
Logan Jones 2020-07-19 05:00:24 -04:00 committed by GitHub
parent 09b764148c
commit 6fb7867767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -8,6 +8,8 @@ from moto.core import BaseBackend, BaseModel
from moto.sts.models import ACCOUNT_ID
from moto.utilities.tagging_service import TaggingService
from uuid import uuid4
class Rule(BaseModel):
def _generate_arn(self, name):
@ -344,7 +346,7 @@ class EventsBackend(BaseBackend):
raise JsonRESTError("ValidationError", "Can only submit 10 events at once")
# We dont really need to store the events yet
return []
return [{"EventId": str(uuid4())} for _ in events]
def remove_targets(self, name, ids):
rule = self.rules.get(name)

View File

@ -150,14 +150,15 @@ class EventsHandler(BaseResponse):
def put_events(self):
events = self._get_param("Entries")
failed_entries = self.events_backend.put_events(events)
entries = self.events_backend.put_events(events)
if failed_entries:
return json.dumps(
{"FailedEntryCount": len(failed_entries), "Entries": failed_entries}
)
failed_count = len([e for e in entries if "ErrorCode" in e])
response = {
"FailedEntryCount": failed_count,
"Entries": entries,
}
return "", self.response_headers
return json.dumps(response)
def put_rule(self):
name = self._get_param("Name")

View File

@ -312,8 +312,10 @@ def test_put_events():
"DetailType": "myDetailType",
}
client.put_events(Entries=[event])
response = client.put_events(Entries=[event])
# Boto3 would error if it didn't return 200 OK
response["FailedEntryCount"].should.equal(0)
response["Entries"].should.have.length_of(1)
with assert_raises(ClientError):
client.put_events(Entries=[event] * 20)