From 1d615e25b651937f236fc4366f9bfe90063cd349 Mon Sep 17 00:00:00 2001 From: gruebel Date: Mon, 4 Nov 2019 21:31:04 +0100 Subject: [PATCH] Add events.delete_event_bus --- IMPLEMENTATION_COVERAGE.md | 4 ++-- moto/events/models.py | 8 +++++++ moto/events/responses.py | 7 +++++++ tests/test_events/test_events.py | 36 +++++++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 6c1cb503b..66c269f8d 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -2713,12 +2713,12 @@ - [ ] upgrade_elasticsearch_domain ## events -54% implemented +58% implemented - [ ] activate_event_source - [X] create_event_bus - [ ] create_partner_event_source - [ ] deactivate_event_source -- [ ] delete_event_bus +- [X] delete_event_bus - [ ] delete_partner_event_source - [X] delete_rule - [X] describe_event_bus diff --git a/moto/events/models.py b/moto/events/models.py index 4e9ba0da2..be4153b9f 100644 --- a/moto/events/models.py +++ b/moto/events/models.py @@ -354,6 +354,14 @@ class EventsBackend(BaseBackend): 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") events_backends = {region: EventsBackend(region) for region in available_regions} diff --git a/moto/events/responses.py b/moto/events/responses.py index dc1615b3c..98a33218a 100644 --- a/moto/events/responses.py +++ b/moto/events/responses.py @@ -296,3 +296,10 @@ class EventsHandler(BaseResponse): response.append(event_bus_response) 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 diff --git a/tests/test_events/test_events.py b/tests/test_events/test_events.py index 5a2cb4f5d..506d66c07 100644 --- a/tests/test_events/test_events.py +++ b/tests/test_events/test_events.py @@ -283,7 +283,7 @@ def test_create_event_bus(): @mock_events def test_create_event_bus_errors(): 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( 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." + )