def test_add_thread_forum_subscriptions(app, authed_client):
    add_permissions(app, 'forums_view', 'forums_threads_create')
    ForumThread.from_subscribed_user(user_id=1)  # cache
    response = authed_client.post(
        '/forums/threads',
        data=json.dumps(
            {'topic': 'New Thread', 'forum_id': 4, 'contents': 'aa'}
        ),
    )
    check_json_response(response, {'id': 6})
    assert response.get_json()['response']['forum']['id'] == 4
    assert {1, 2} == set(ForumThreadSubscription.user_ids_from_thread(6))
    assert 6 in {t.id for t in ForumThread.from_subscribed_user(user_id=1)}
示例#2
0
def test_subscribe_thread_deletes_cache_keys(app, authed_client):
    add_permissions(app, ForumPermissions.MODIFY_SUBSCRIPTIONS)
    ForumThread.from_subscribed_user(1)
    ForumThreadSubscription.user_ids_from_thread(5)
    response = authed_client.post('/subscriptions/threads/5')
    assert response.status_code == 200
    assert not cache.get(
        ForumThreadSubscription.__cache_key_users__.format(thread_id=5)
    )
    assert not cache.get(
        ForumThreadSubscription.__cache_key_of_user__.format(user_id=1)
    )
    assert ForumThreadSubscription.user_ids_from_thread(5) == [1]
示例#3
0
def view_thread_subscriptions() -> flask.Response:
    """
    This is the endpoint to view forum and thread subscriptions. The
    ``forums_view_subscriptions`` permission is required to access this endpoint.

    .. :quickref: ForumSubscription; View forum subscriptions.

    **Example response**:

    .. parsed-literal::

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

    :>json dict response: The forum and thread subscriptions

    :statuscode 200: The forum subscriptions
    """
    return flask.jsonify(ForumThread.from_subscribed_user(flask.g.user.id))
示例#4
0
def test_thread_subscriptions(app, authed_client):
    threads = ForumThread.from_subscribed_user(1)
    assert all(t.id in {1, 3, 4} for t in threads)
    assert {1, 3, 4} == set(
        cache.get(
            ForumThreadSubscription.__cache_key_of_user__.format(user_id=1)))