From 8a72f666a3958827cd35f44e21791ccddbb6c85e Mon Sep 17 00:00:00 2001 From: Mardone Date: Wed, 4 Dec 2024 14:26:11 -0300 Subject: [PATCH 1/4] 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 From 4b5b93616c771308cc8d4ecb086ae630e0f2541d Mon Sep 17 00:00:00 2001 From: Mardone Date: Wed, 4 Dec 2024 17:12:51 -0300 Subject: [PATCH 2/4] fix ci --- nexus/logs/api/tests.py | 1 - nexus/logs/api/views.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/nexus/logs/api/tests.py b/nexus/logs/api/tests.py index 3466d9c8..bfc1ae6e 100644 --- a/nexus/logs/api/tests.py +++ b/nexus/logs/api/tests.py @@ -298,7 +298,6 @@ def test_tag_filter(self): ) response.render() content = json.loads(response.content) - self.assertEqual(response.status_code, 200) self.assertEquals(len(content.get("results")), 10) diff --git a/nexus/logs/api/views.py b/nexus/logs/api/views.py index 59ede3fd..fff04226 100644 --- a/nexus/logs/api/views.py +++ b/nexus/logs/api/views.py @@ -177,7 +177,7 @@ 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(): + if not logs: return MessageLog.objects.none() return logs From 578ae32a0a0e390747d6de00b39461bbf22b3f1e Mon Sep 17 00:00:00 2001 From: Alisson Date: Thu, 12 Dec 2024 18:43:28 -0300 Subject: [PATCH 3/4] return empty list in tag percentage view --- nexus/logs/api/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nexus/logs/api/views.py b/nexus/logs/api/views.py index fff04226..ddceeacf 100644 --- a/nexus/logs/api/views.py +++ b/nexus/logs/api/views.py @@ -84,7 +84,7 @@ def count_status(logs, tag): message_logs = message_logs.exclude(message__status="F") if not message_logs.exists(): - return Response({"error": "No logs found for the given date range"}, status=404) + return Response([], status=200) tag_counts = message_logs.aggregate(action_count=Count(Case(When(reflection_data__tag='action_started', then=1), output_field=IntegerField()))) @@ -97,7 +97,7 @@ def count_status(logs, tag): total_logs = sum(tag_counts.values()) if total_logs == 0: - return Response({"error": "No logs found for the given date range"}, status=404) + return Response([], status=200) action_percentage = (tag_counts['action_count'] / total_logs) * 100 succeed_percentage = (tag_counts['succeed_count'] / total_logs) * 100 From f09a9b76d84e7a786a2f811985c10227862265b4 Mon Sep 17 00:00:00 2001 From: Alisson Date: Fri, 13 Dec 2024 11:40:23 -0300 Subject: [PATCH 4/4] fix tests --- nexus/logs/api/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nexus/logs/api/tests.py b/nexus/logs/api/tests.py index bfc1ae6e..2e9b7cc9 100644 --- a/nexus/logs/api/tests.py +++ b/nexus/logs/api/tests.py @@ -365,8 +365,8 @@ def test_get_tag_percentages_no_logs(self): response = self.view(request, project_uuid=str(self.project.uuid)) response.render() - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['error'], "No logs found for the given date range") + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data, []) def test_get_tag_percentages_invalid_date(self): request = self.factory.get(self.url, {'started_day': 'invalid-date', 'ended_day': self.ended_day})