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:
parent
09b764148c
commit
6fb7867767
@ -8,6 +8,8 @@ from moto.core import BaseBackend, BaseModel
|
|||||||
from moto.sts.models import ACCOUNT_ID
|
from moto.sts.models import ACCOUNT_ID
|
||||||
from moto.utilities.tagging_service import TaggingService
|
from moto.utilities.tagging_service import TaggingService
|
||||||
|
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
|
||||||
class Rule(BaseModel):
|
class Rule(BaseModel):
|
||||||
def _generate_arn(self, name):
|
def _generate_arn(self, name):
|
||||||
@ -344,7 +346,7 @@ class EventsBackend(BaseBackend):
|
|||||||
raise JsonRESTError("ValidationError", "Can only submit 10 events at once")
|
raise JsonRESTError("ValidationError", "Can only submit 10 events at once")
|
||||||
|
|
||||||
# We dont really need to store the events yet
|
# We dont really need to store the events yet
|
||||||
return []
|
return [{"EventId": str(uuid4())} for _ in events]
|
||||||
|
|
||||||
def remove_targets(self, name, ids):
|
def remove_targets(self, name, ids):
|
||||||
rule = self.rules.get(name)
|
rule = self.rules.get(name)
|
||||||
|
@ -150,14 +150,15 @@ class EventsHandler(BaseResponse):
|
|||||||
def put_events(self):
|
def put_events(self):
|
||||||
events = self._get_param("Entries")
|
events = self._get_param("Entries")
|
||||||
|
|
||||||
failed_entries = self.events_backend.put_events(events)
|
entries = self.events_backend.put_events(events)
|
||||||
|
|
||||||
if failed_entries:
|
failed_count = len([e for e in entries if "ErrorCode" in e])
|
||||||
return json.dumps(
|
response = {
|
||||||
{"FailedEntryCount": len(failed_entries), "Entries": failed_entries}
|
"FailedEntryCount": failed_count,
|
||||||
)
|
"Entries": entries,
|
||||||
|
}
|
||||||
|
|
||||||
return "", self.response_headers
|
return json.dumps(response)
|
||||||
|
|
||||||
def put_rule(self):
|
def put_rule(self):
|
||||||
name = self._get_param("Name")
|
name = self._get_param("Name")
|
||||||
|
@ -312,8 +312,10 @@ def test_put_events():
|
|||||||
"DetailType": "myDetailType",
|
"DetailType": "myDetailType",
|
||||||
}
|
}
|
||||||
|
|
||||||
client.put_events(Entries=[event])
|
response = client.put_events(Entries=[event])
|
||||||
# Boto3 would error if it didn't return 200 OK
|
# 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):
|
with assert_raises(ClientError):
|
||||||
client.put_events(Entries=[event] * 20)
|
client.put_events(Entries=[event] * 20)
|
||||||
|
Loading…
Reference in New Issue
Block a user