From 77ffbe8070c91048cff4b932927930d24ef8fdd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Fri, 5 Jan 2024 14:14:17 +0100 Subject: [PATCH] [ORG-70] Get all events endpoint is not showing deleted events (#74) * add check to not show deleted events in getallevents * add test * black --- .../app/events/infrastructure/http/views.py | 3 ++- .../tests/events/infrastructure/http/test_views.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/organizator_api/app/events/infrastructure/http/views.py b/organizator_api/app/events/infrastructure/http/views.py index 04601cdd..51aeca02 100644 --- a/organizator_api/app/events/infrastructure/http/views.py +++ b/organizator_api/app/events/infrastructure/http/views.py @@ -71,7 +71,8 @@ def get_all_events(request: HttpRequest) -> HttpResponse: events_response = [] for event in all_events: - events_response.append(EventResponse.from_event(event).to_dict()) + if event.deleted_at is None: + events_response.append(EventResponse.from_event(event).to_dict()) return HttpResponse( status=200, content=json.dumps(events_response), content_type="application/json" diff --git a/organizator_api/tests/events/infrastructure/http/test_views.py b/organizator_api/tests/events/infrastructure/http/test_views.py index dc79944a..ab361083 100644 --- a/organizator_api/tests/events/infrastructure/http/test_views.py +++ b/organizator_api/tests/events/infrastructure/http/test_views.py @@ -186,6 +186,20 @@ def test__given_events_in_db__when_get_all_events__then_returns_the_events_list( b'[{"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "name": "HackUPC 2023", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false}, {"id": "be0f4c18-4a7c-4c1e-8a62-fc50916b6c88", "name": "HackUPC 2022", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false}]', ) + def test__given_event_deleted_in_db__when_get_all_events__then_it_returns_empty_list( + self, + ) -> None: + # Given + event = EventFactory().create(deleted_at=datetime.now()) + self.event_repository.create(event) + + # When + response = self.client.get("/organizator-api/events/") + + # Then + self.assertEqual(response.status_code, 200) + self.assertEqual(response.content, b"[]") + def test__given_events_in_db__when_get_all_upcoming_events__then_returns_the_events_list( self, ) -> None: