def test_get_notification_model(client):
    noti = Notification.from_pk(1)
    assert noti.id == 1
    assert noti.user_id == 1
    assert noti.type == 'subscripple'
    assert noti.contents['contents'] == 'A Subscribe!'
    assert noti.read is False
Esempio n. 2
0
def modify_notification(id: int, read: bool):
    """
    Change the read status of a notification. Requires the
    ``notifications_modify`` permission. Modifying another user's
    notifications requires the ``notifications_modify_others`` permission.

    .. :quickref: Notification; Flag notification as read/unread.

    **Example response**:

    .. parsed-literal::

       {
         "status": "success",
         "response": "Notification 1243 marked as read."
       }

    :>json str response: Response message

    :statuscode 200: Successfully modified notification.
    :statuscode 403: User does not have permission to modify notifications.
    :statuscode 404: Notification does not exist.
    """
    noti = Notification.from_pk(id,
                                asrt=NotificationPermissions.MODIFY_OTHERS,
                                error=True)
    noti.read = read
    db.session.commit()
    Notification.clear_cache_keys(noti.user_id, noti.type)
    return flask.jsonify(
        f'Notification {id} marked as {"read" if read else "unread"}.')