Exemple #1
0
def view_notification_type(
    type: str,
    user: User,
    page: int = 1,
    limit: int = 50,
    include_read: bool = False,
):
    """
    View all pending notifications of a specific type. Requires the
    ``notifications_view`` permission. Viewing the notifications of
    another user requires the ``notifications_view_others`` permission.

    .. :quickref: Notification; View notifications of a type.

    **Example request**:

    .. parsed-literal::

       GET /notifications/type_1 HTTP/1.1

       {
         "page": 1,
         "limit": 50,
         "include_read": False
       }

    **Example response**:

    .. parsed-literal::

       {
         "status": "success",
         "response": [
           "<Notification>",
           "<Notification>"
         ]
       }

    :>json dict response: A list of notifications

    :statuscode 200: Successfully viewed notifications.
    :statuscode 400: Notification type is invalid.
    :statuscode 403: User does not have access to view notifications.
    """
    return flask.jsonify(
        Notification.from_type(user.id, type, include_read=include_read))
def test_get_notification_from_type_false(client):
    with pytest.raises(APIException) as e:
        Notification.from_type(1, 'bahaha', include_read=True)
    assert e.value.message == 'bahaha is not a notification type.'
def test_get_notification_from_type_include_read(client):
    notis = Notification.from_type(1, 'unreal', include_read=True)
    assert len(notis) == 1
def test_get_notification_from_type_read(client):
    notis = Notification.from_type(1, 'unreal')
    assert len(notis) == 0
def test_get_notification_from_type(client):
    notis = Notification.from_type(1, 'quote')
    assert len(notis) == 1
    assert notis[0].id == 3
def test_mentioned_post(app, client):
    post = ForumPostFake(contents=ment_c, user_id=1)
    check_post_contents_for_mentions(post)
    assert len(Notification.from_type(user_id=2, type='forums_mentioned')) == 0
    assert len(Notification.from_type(user_id=3, type='forums_mentioned')) == 1
    assert len(Notification.from_type(user_id=1, type='forums_mentioned')) == 0
def test_quoted_post_by_self(app, client):
    post = ForumPostFake(contents=quote_d, user_id=1)
    check_post_contents_for_quotes(post)
    assert len(Notification.from_type(user_id=2, type='forums_quoted')) == 1
    assert len(Notification.from_type(user_id=1, type='forums_quoted')) == 0
    assert len(Notification.from_type(user_id=3, type='forums_quoted')) == 0