コード例 #1
0
def test_list_paginate(db_conn, notices_table):
    """
    Expect to paginate lists of notices.
    """
    for i in range(0, 25):
        notices_table.insert({
            'id': i, 'user_id': 22, 'kind': 'create_proposal',
        }).run(db_conn)
    notices = Notice.list(user_id=22)
    assert len(notices) == 10
    notices = Notice.list(user_id=22, skip=20)
    assert len(notices) == 5
コード例 #2
0
def test_list_user(db_conn, notices_table):
    """
    Expect to get a only notices of user.
    """
    notices_table.insert([
        {'id': 1, 'user_id': 22, 'kind': 'create_proposal'},
        {'id': 2, 'user_id': 22, 'kind': 'create_proposal'},
        {'id': 3, 'user_id': 24, 'kind': 'create_proposal'},
        {'id': 4, 'user_id': 25, 'kind': 'create_proposal'},
    ]).run(db_conn)
    notices = Notice.list(user_id=22)
    assert len(notices) == 2
コード例 #3
0
def test_list(db_conn, notices_table):
    """
    Expect to get a list of 10 notices by user ID.
    """
    notices_table.insert([
        {'id': 1, 'user_id': 22, 'kind': 'create_proposal'},
        {'id': 2, 'user_id': 22, 'kind': 'create_proposal'},
        {'id': 3, 'user_id': 22, 'kind': 'create_proposal'},
        {'id': 4, 'user_id': 22, 'kind': 'create_proposal'},
    ]).run(db_conn)
    notices = Notice.list(user_id=22)
    assert len(notices) == 4
コード例 #4
0
ファイル: notice.py プロジェクト: Folashade/sagefy
def list_notices_route(request):
    """
    List notices for current user.
    Take parameters `limit`, `skip`, `tag`, and `read`.
    """

    current_user = get_current_user(request)
    if not current_user:
        return abort(401)
    notices = Notice.list(user_id=current_user['id'], **request['params'])
    output = {'notices': [notice.deliver(access='private')
                          for notice in notices]}
    return 200, output
コード例 #5
0
def test_list_unread(db_conn, notices_table):
    """
    Expect to get a list of unread notices.
    """
    notices_table.insert([
        {'id': 1, 'user_id': 22, 'kind': 'create_proposal', 'read': True},
        {'id': 3, 'user_id': 22, 'kind': 'create_proposal', 'read': False},
        {'id': 4, 'user_id': 22, 'kind': 'create_proposal', 'read': False},
    ]).run(db_conn)
    notices = Notice.list(user_id=22, read=False)
    assert len(notices) == 2
    assert notices[0]['id'] in (3, 4)
    assert notices[1]['id'] in (3, 4)
コード例 #6
0
ファイル: notice.py プロジェクト: Folashade/sagefy
def list_notices_route(request):
    """
    List notices for current user.
    Take parameters `limit`, `skip`, `tag`, and `read`.
    """

    current_user = get_current_user(request)
    if not current_user:
        return abort(401)
    notices = Notice.list(user_id=current_user['id'], **request['params'])
    output = {
        'notices': [notice.deliver(access='private') for notice in notices]
    }
    return 200, output
コード例 #7
0
def test_list_tag(db_conn, notices_table):
    """
    Expect to get a list of notices by tag.
    """
    notices_table.insert([
        {'id': 1, 'user_id': 22, 'kind': 'create_proposal',
            'tags': ['apple', 'banana']},
        {'id': 2, 'user_id': 22, 'kind': 'create_proposal',
            'tags': ['orange', 'banana']},
        {'id': 3, 'user_id': 23, 'kind': 'create_proposal',
            'tags': ['apple', 'grape']},
        {'id': 4, 'user_id': 22, 'kind': 'create_proposal',
            'tags': ['apple', 'peach']},
    ]).run(db_conn)
    notices = Notice.list(user_id=22, tag='apple')
    assert len(notices) == 2
    assert 'apple' in notices[0]['tags']
    assert 'apple' in notices[1]['tags']
コード例 #8
0
def test_notices_kind(db_conn, notices_table):
    """
    Expect to filter notices by kind.
    """

    notices_table.insert([
        {'id': 1, 'user_id': 22, 'kind': 'create_proposal',
            'tags': ['apple', 'banana']},
        {'id': 2, 'user_id': 22, 'kind': 'accepted_proposal',
            'tags': ['orange', 'banana']},
        {'id': 3, 'user_id': 22, 'kind': 'create_proposal',
            'tags': ['apple', 'grape']},
        {'id': 4, 'user_id': 22, 'kind': 'new_topic',
            'tags': ['apple', 'peach']},
    ]).run(db_conn)
    notices = Notice.list(user_id=22, kind='create_proposal')
    assert len(notices) == 2
    assert notices[0]['kind'] == 'create_proposal'
    assert notices[1]['kind'] == 'create_proposal'
コード例 #9
0
def test_list_empty(db_conn, notices_table):
    """
    Expect to get an empty list when run out of notices.
    """
    notices = Notice.list(user_id=22)
    assert len(notices) == 0