def test_modify_notification(app, authed_client):
    add_permissions(app, 'notifications_modify')
    response = authed_client.put(
        '/notifications/1', data=json.dumps({'read': True})
    )
    print(response.get_json())
    assert response.status_code == 200
    assert not len(Notification.get_all_unread(1)['subscripple'])
    assert len(Notification.get_all_unread(1)['quote']) == 1
def test_get_unread_notifications(client):
    unread = Notification.get_all_unread(1)
    assert unread['subscripple'][0].id == 1
    assert len(unread['subscripple']) == 1
    assert unread['quote'][0].id == 3
    assert len(unread['quote']) == 1
    assert len(unread['unreal']) == 0
Exemple #3
0
def view_notifications(user: User):
    """
    View all pending notifications for a user. This includes thread subscriptions,
    collage notifications, torrent notifications, and inbox messages. Requires the
    ``notifications_view`` permission. Viewing the notifications of another user
    requires the ``notifications_view_others`` permission.

    .. :quickref: Notification; View unread notifications.

    **Example response**:

    .. parsed-literal::

       {
         "status": "success",
         "response": {
           "notification type 1": [
             "<Notification>",
             "<Notification>"
           ],
           "notification type 2": [
             "<Notification>",
             "<Notification>"
           ]
         }
       }

    :>json dict response: A dictionary of notification types and lists of notifications

    :statuscode 200: Successfully viewed notifications.
    :statuscode 403: User does not have access to view notifications.
    """
    return flask.jsonify(Notification.get_all_unread(user.id))
def test_clear_notifications(app, authed_client):
    add_permissions(app, 'notifications_modify')
    assert (
        authed_client.put(
            '/notifications', data=json.dumps({'read': True})
        ).status_code
        == 200
    )
    n = Notification.get_all_unread(1)
    assert all(len(v) == 0 for v in n.values())
def test_clear_notifications_type(app, authed_client):
    add_permissions(app, 'notifications_modify')
    assert (
        authed_client.put(
            '/notifications/quote', data=json.dumps({'read': True})
        ).status_code
        == 200
    )
    n = Notification.get_all_unread(1)
    assert len(n['quote']) == 0
    assert len(n['subscripple']) == 1