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 )
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 )
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)
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)