Skip to content

Commit

Permalink
fix: changes count_by_app_name in counts api to return apps with zero… (
Browse files Browse the repository at this point in the history
openedx#32629)

* 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
  • Loading branch information
ayesha-waris committed Jul 10, 2023
1 parent 027c6a1 commit c5c52a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions openedx/core/djangoapps/notifications/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion openedx/core/djangoapps/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit c5c52a8

Please sign in to comment.