From 8a72f666a3958827cd35f44e21791ccddbb6c85e Mon Sep 17 00:00:00 2001 From: Mardone Date: Wed, 4 Dec 2024 14:26:11 -0300 Subject: [PATCH] Fix 404 on message_history --- nexus/logs/api/tests.py | 15 +++++++++++++++ nexus/logs/api/views.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/nexus/logs/api/tests.py b/nexus/logs/api/tests.py index eb8c3869..3466d9c8 100644 --- a/nexus/logs/api/tests.py +++ b/nexus/logs/api/tests.py @@ -316,6 +316,21 @@ def test_null_reflection_data(self): self.assertEqual(response.status_code, 200) self.assertEquals(len(content.get("results")), 0) + def test_empty_logs_data(self): + MessageLog.objects.all().delete() + + request = self.factory.get(f"/api/{self.project.uuid}/message_history/?page_size=100&started_day={self.started_day}&ended_day={self.ended_day}") + force_authenticate(request, user=self.user) + response = MessageHistoryViewset.as_view({'get': 'list'})( + request, + project_uuid=str(self.project.uuid), + ) + response.render() + content = json.loads(response.content) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content.get("results")), 0) + class TagPercentageViewSetTestCase(APITestCase): diff --git a/nexus/logs/api/views.py b/nexus/logs/api/views.py index 2f7e37ee..59ede3fd 100644 --- a/nexus/logs/api/views.py +++ b/nexus/logs/api/views.py @@ -177,6 +177,9 @@ def get_queryset(self): } logs = [log for log in logs if log.message.response_status == status.get(tag_param) and log.reflection_data.get("tag") != "action_started"] + if not logs.exists(): + return MessageLog.objects.none() + return logs