refactor: updated api reference from unseen to seen (#32501)

This commit is contained in:
Ahtisham Shahid
2023-06-21 13:02:28 +05:00
committed by GitHub
parent c2c0e67a5d
commit bf4b3c628b
3 changed files with 16 additions and 16 deletions

View File

@@ -489,7 +489,7 @@ class NotificationCountViewSetTestCase(ModuleStoreTestCase):
self.assertEqual(response.data['count_by_app_name'], {})
class MarkNotificationsUnseenAPIViewTestCase(APITestCase):
class MarkNotificationsSeenAPIViewTestCase(APITestCase):
"""
Tests for the MarkNotificationsUnseenAPIView.
"""
@@ -503,20 +503,20 @@ class MarkNotificationsUnseenAPIViewTestCase(APITestCase):
Notification.objects.create(user=self.user, app_name='App Name 2', notification_type='Type A')
Notification.objects.create(user=self.user, app_name='App Name 3', notification_type='Type C')
def test_mark_notifications_unseen(self):
# Create a POST request to mark notifications as unseen for 'App Name 1'
def test_mark_notifications_seen(self):
# Create a POST request to mark notifications as seen for 'App Name 1'
app_name = 'App Name 1'
url = reverse('mark-notifications-unseen', kwargs={'app_name': app_name})
url = reverse('mark-notifications-seen', kwargs={'app_name': app_name})
self.client.login(username=self.user.username, password='test')
response = self.client.put(url)
# Assert the response status code is 200 (OK)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Assert the response data contains the expected message
expected_data = {'message': 'Notifications marked unseen.'}
expected_data = {'message': 'Notifications marked as seen.'}
self.assertEqual(response.data, expected_data)
# Assert the notifications for 'App Name 1' are marked as unseen for the user
# Assert the notifications for 'App Name 1' are marked as seen for the user
notifications = Notification.objects.filter(user=self.user, app_name=app_name, last_seen__isnull=False)
self.assertEqual(notifications.count(), 2)

View File

@@ -7,7 +7,7 @@ from rest_framework import routers
from .views import (
CourseEnrollmentListView,
MarkNotificationsUnseenAPIView,
MarkNotificationsSeenAPIView,
NotificationCountView,
NotificationListAPIView,
NotificationReadAPIView,
@@ -27,9 +27,9 @@ urlpatterns = [
path('', NotificationListAPIView.as_view(), name='notifications-list'),
path('count/', NotificationCountView.as_view(), name='notifications-count'),
path(
'mark-notifications-unseen/<app_name>/',
MarkNotificationsUnseenAPIView.as_view(),
name='mark-notifications-unseen'
'mark-seen/<app_name>/',
MarkNotificationsSeenAPIView.as_view(),
name='mark-notifications-seen'
),
path('read/', NotificationReadAPIView.as_view(), name='notifications-read'),

View File

@@ -301,21 +301,21 @@ class NotificationCountView(APIView):
})
class MarkNotificationsUnseenAPIView(UpdateAPIView):
class MarkNotificationsSeenAPIView(UpdateAPIView):
"""
API view for marking user's all notifications unseen for a provided app_name.
API view for marking user's all notifications seen for a provided app_name.
"""
permission_classes = (permissions.IsAuthenticated,)
def update(self, request, *args, **kwargs):
"""
Marks all notifications for the given app name unseen for the authenticated user.
Marks all notifications for the given app name seen for the authenticated user.
**Args:**
app_name: The name of the app to mark notifications unseen for.
app_name: The name of the app to mark notifications seen for.
**Response Format:**
A `Response` object with a 200 OK status code if the notifications were successfully marked unseen.
A `Response` object with a 200 OK status code if the notifications were successfully marked seen.
**Response Error Codes**:
- 400: Bad Request status code if the app name is invalid.
"""
@@ -332,7 +332,7 @@ class MarkNotificationsUnseenAPIView(UpdateAPIView):
notifications.update(last_seen=datetime.now())
return Response({'message': _('Notifications marked unseen.')}, status=200)
return Response({'message': _('Notifications marked as seen.')}, status=200)
class NotificationReadAPIView(APIView):