Ejemplo n.º 1
0
    def test_mark_all_as_read(self):
        """
        Verify proper behavior when marking user notifications as read/unread
        """
        for __ in range(10):
            msg = NotificationMessage(namespace="test-runner", msg_type=self.msg_type, payload={"foo": "bar"})
            publish_notification_to_user(self.test_user_id, msg)

        # make sure we have 10 unreads before we do anything else
        self.assertEquals(
            get_notifications_count_for_user(self.test_user_id, filters={"read": False, "unread": True}), 10
        )

        # now mark msg as read by this user
        mark_all_user_notification_as_read(self.test_user_id)

        # shouldn't be counted in unread counts
        self.assertEquals(
            get_notifications_count_for_user(self.test_user_id, filters={"read": False, "unread": True}), 0
        )

        # Should be counted in read counts
        self.assertEquals(
            get_notifications_count_for_user(self.test_user_id, filters={"read": True, "unread": False}), 10
        )
Ejemplo n.º 2
0
    def test_mark_all_as_read(self):
        """
        Verify proper behavior when marking user notifications as read/unread
        """
        for __ in range(10):
            msg = NotificationMessage(
                namespace='test-runner',
                msg_type=self.msg_type,
                payload={
                    'foo': 'bar'
                }
            )
            publish_notification_to_user(self.test_user_id, msg)

        # make sure we have 10 unreads before we do anything else
        self.assertEqual(
            get_notifications_count_for_user(
                self.test_user_id,
                filters={
                    'read': False,
                    'unread': True,
                },
            ),
            10
        )

        # now mark msg as read by this user
        mark_all_user_notification_as_read(self.test_user_id)

        # shouldn't be counted in unread counts
        self.assertEqual(
            get_notifications_count_for_user(
                self.test_user_id,
                filters={
                    'read': False,
                    'unread': True,
                },
            ),
            0
        )

        # Should be counted in read counts
        self.assertEqual(
            get_notifications_count_for_user(
                self.test_user_id,
                filters={
                    'read': True,
                    'unread': False,
                },
            ),
            10
        )
Ejemplo n.º 3
0
    def post(self, request):
        """
        HTTP POST Handler which is used for such use-cases as 'mark as read'
        """

        filters = None

        # get the namespace from the POST parameters
        if 'namespace' in request.POST:
            filters = {'namespace': request.POST['namespace']}

        mark_all_user_notification_as_read(int(request.user.id),
                                           filters=filters)

        return Response([], status.HTTP_200_OK)
Ejemplo n.º 4
0
    def post(self, request):
        """
        HTTP POST Handler which is used for such use-cases as 'mark as read'
        """

        filters = None

        # get the namespace from the POST parameters
        if 'namespace' in request.POST:
            filters = {
                'namespace': request.POST['namespace']
            }

        mark_all_user_notification_as_read(
            int(request.user.id),
            filters=filters
        )

        return Response([], status.HTTP_200_OK)