From c5c52a8f9e353a4968b9d2c3fbfa67a0b9ffe300 Mon Sep 17 00:00:00 2001 From: ayesha waris <73840786+ayesha-waris@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:14:02 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20changes=20count=5Fby=5Fapp=5Fname=20in?= =?UTF-8?q?=20counts=20api=20to=20return=20apps=20with=20zero=E2=80=A6=20(?= =?UTF-8?q?#32629)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: changes count_by_app_name in counts api to return apps with zero unseen count * refactor: initialised count_by_app_name_dict with zeros --- openedx/core/djangoapps/notifications/tests/test_views.py | 5 +++-- openedx/core/djangoapps/notifications/views.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/openedx/core/djangoapps/notifications/tests/test_views.py b/openedx/core/djangoapps/notifications/tests/test_views.py index 3a977ea6ce27..ec3dbe4dcb9b 100644 --- a/openedx/core/djangoapps/notifications/tests/test_views.py +++ b/openedx/core/djangoapps/notifications/tests/test_views.py @@ -496,7 +496,8 @@ def test_get_unseen_notifications_count_with_show_notifications_tray(self, show_ self.assertEqual(response.status_code, 200) self.assertEqual(response.data['count'], 4) - self.assertEqual(response.data['count_by_app_name'], {'App Name 1': 2, 'App Name 2': 1, 'App Name 3': 1}) + self.assertEqual(response.data['count_by_app_name'], { + 'App Name 1': 2, 'App Name 2': 1, 'App Name 3': 1, 'discussion': 0}) self.assertEqual(response.data['show_notifications_tray'], show_notifications_tray_enabled) def test_get_unseen_notifications_count_for_unauthenticated_user(self): @@ -517,7 +518,7 @@ def test_get_unseen_notifications_count_for_user_with_no_notifications(self): self.assertEqual(response.status_code, 200) self.assertEqual(response.data['count'], 0) - self.assertEqual(response.data['count_by_app_name'], {}) + self.assertEqual(response.data['count_by_app_name'], {'discussion': 0}) class MarkNotificationsSeenAPIViewTestCase(APITestCase): diff --git a/openedx/core/djangoapps/notifications/views.py b/openedx/core/djangoapps/notifications/views.py index 2ea38d5e8a27..83838bd6c422 100644 --- a/openedx/core/djangoapps/notifications/views.py +++ b/openedx/core/djangoapps/notifications/views.py @@ -289,8 +289,11 @@ def get(self, request): .annotate(count=Count('*')) ) count_total = 0 - count_by_app_name_dict = {} show_notifications_tray_enabled = False + count_by_app_name_dict = { + app_name: 0 + for app_name in COURSE_NOTIFICATION_APPS + } for item in count_by_app_name: app_name = item['app_name']