Add events.delete_event_bus

This commit is contained in:
gruebel 2019-11-04 21:31:04 +01:00
parent 831577350d
commit 1d615e25b6
4 changed files with 52 additions and 3 deletions

View File

@ -2713,12 +2713,12 @@
- [ ] upgrade_elasticsearch_domain - [ ] upgrade_elasticsearch_domain
## events ## events
54% implemented 58% implemented
- [ ] activate_event_source - [ ] activate_event_source
- [X] create_event_bus - [X] create_event_bus
- [ ] create_partner_event_source - [ ] create_partner_event_source
- [ ] deactivate_event_source - [ ] deactivate_event_source
- [ ] delete_event_bus - [X] delete_event_bus
- [ ] delete_partner_event_source - [ ] delete_partner_event_source
- [X] delete_rule - [X] delete_rule
- [X] describe_event_bus - [X] describe_event_bus

View File

@ -354,6 +354,14 @@ class EventsBackend(BaseBackend):
return list(self.event_buses.values()) return list(self.event_buses.values())
def delete_event_bus(self, name):
if name == "default":
raise JsonRESTError(
"ValidationException", "Cannot delete event bus default."
)
self.event_buses.pop(name, None)
available_regions = boto3.session.Session().get_available_regions("events") available_regions = boto3.session.Session().get_available_regions("events")
events_backends = {region: EventsBackend(region) for region in available_regions} events_backends = {region: EventsBackend(region) for region in available_regions}

View File

@ -296,3 +296,10 @@ class EventsHandler(BaseResponse):
response.append(event_bus_response) response.append(event_bus_response)
return json.dumps({"EventBuses": response}), self.response_headers return json.dumps({"EventBuses": response}), self.response_headers
def delete_event_bus(self):
name = self._get_param("Name")
self.events_backend.delete_event_bus(name)
return "", self.response_headers

View File

@ -283,7 +283,7 @@ def test_create_event_bus():
@mock_events @mock_events
def test_create_event_bus_errors(): def test_create_event_bus_errors():
client = boto3.client("events", "us-east-1") client = boto3.client("events", "us-east-1")
response = client.create_event_bus(Name="test-bus") client.create_event_bus(Name="test-bus")
client.create_event_bus.when.called_with(Name="test-bus").should.throw( client.create_event_bus.when.called_with(Name="test-bus").should.throw(
ClientError, "Event bus test-bus already exists." ClientError, "Event bus test-bus already exists."
@ -415,3 +415,37 @@ def test_list_event_buses():
}, },
] ]
) )
@mock_events
def test_delete_event_bus():
client = boto3.client("events", "us-east-1")
client.create_event_bus(Name="test-bus")
response = client.list_event_buses()
response["EventBuses"].should.have.length_of(2)
client.delete_event_bus(Name="test-bus")
response = client.list_event_buses()
response["EventBuses"].should.have.length_of(1)
response["EventBuses"].should.equal(
[
{
"Name": "default",
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/default",
}
]
)
# deleting non existing event bus should be successful
client.delete_event_bus(Name="non-existing")
@mock_events
def test_delete_event_bus_errors():
client = boto3.client("events", "us-east-1")
client.delete_event_bus.when.called_with(Name="default").should.throw(
ClientError, "Cannot delete event bus default."
)