Ejemplo n.º 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 = list_notices({"user_id": 22}, db_conn)
    assert len(notices) == 10
    notices = list_notices({"user_id": 22, "skip": 20}, db_conn)
    assert len(notices) == 5
Ejemplo n.º 2
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 = list_notices({'user_id': 22}, db_conn)
    assert len(notices) == 10
    notices = list_notices({'user_id': 22, 'skip': 20}, db_conn)
    assert len(notices) == 5
Ejemplo n.º 3
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 = list_notices({'user_id': 22}, db_conn)
    assert len(notices) == 2
Ejemplo n.º 4
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 = list_notices({'user_id': 22}, db_conn)
    assert len(notices) == 4
Ejemplo n.º 5
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 = list_notices({'user_id': 22, 'kind': 'create_proposal'}, db_conn)
    assert len(notices) == 2
    assert notices[0]['kind'] == 'create_proposal'
    assert notices[1]['kind'] == 'create_proposal'
Ejemplo n.º 6
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 = list_notices({'user_id': 22, 'tag': 'apple'}, db_conn)
    assert len(notices) == 2
    assert 'apple' in notices[0]['tags']
    assert 'apple' in notices[1]['tags']
Ejemplo n.º 7
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 = list_notices({'user_id': 22, 'read': False}, db_conn)
    assert len(notices) == 2
    assert notices[0]['id'] in (3, 4)
    assert notices[1]['id'] in (3, 4)
Ejemplo n.º 8
0
def test_list_notices(db_conn):
  create_test_notices(db_conn)
  params = {
    'user_id': user_uuid
  }
  notices = list_notices(db_conn, params)
  assert notices
  assert len(notices) == 2
  assert notices[0]['user_id'] == user_uuid
  assert notices[1]['user_id'] == user_uuid
Ejemplo n.º 9
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 = list_notices({"user_id": 22}, db_conn)
    assert len(notices) == 2
Ejemplo n.º 10
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 = list_notices({"user_id": 22}, db_conn)
    assert len(notices) == 4
Ejemplo n.º 11
0
def list_notices_route(request):
    """
    List notices for current user.
    Take parameters `limit`, `skip`, `tag`, and `read`.
    """

    db_conn = request['db_conn']
    current_user = get_current_user(request)
    if not current_user:
        return abort(401)
    params = extend({}, request['params'], {'user_id': current_user['id']})
    notices = list_notices(params, db_conn)
    output = {'notices': [deliver_notice(notice, access='private')
                          for notice in notices]}
    return 200, output
Ejemplo n.º 12
0
def list_notices_route(request):
  """
  List notices for current user.
  Take parameters `limit`, `skip`, `tag`, and `read`.
  """

  db_conn = request['db_conn']
  current_user = get_current_user(request)
  if not current_user:
    return abort(401, '9oMIw3V8S3WeaLf9IgbmaQ')
  params = extend({}, request['params'], {'user_id': current_user['id']})
  notices = list_notices(db_conn, params)
  output = {'notices': [deliver_notice(notice, access='private')
                        for notice in notices]}
  return 200, output
Ejemplo n.º 13
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 = list_notices({"user_id": 22, "read": False}, db_conn)
    assert len(notices) == 2
    assert notices[0]["id"] in (3, 4)
    assert notices[1]["id"] in (3, 4)
Ejemplo n.º 14
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 = list_notices({"user_id": 22, "tag": "apple"}, db_conn)
    assert len(notices) == 2
    assert "apple" in notices[0]["tags"]
    assert "apple" in notices[1]["tags"]
Ejemplo n.º 15
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 = list_notices({"user_id": 22, "kind": "create_proposal"}, db_conn)
    assert len(notices) == 2
    assert notices[0]["kind"] == "create_proposal"
    assert notices[1]["kind"] == "create_proposal"
Ejemplo n.º 16
0
def test_list_empty(db_conn, notices_table):
    """
    Expect to get an empty list when run out of notices.
    """
    notices = list_notices({'user_id': 22}, db_conn)
    assert len(notices) == 0
Ejemplo n.º 17
0
def test_list_empty(db_conn, notices_table):
    """
    Expect to get an empty list when run out of notices.
    """
    notices = list_notices({"user_id": 22}, db_conn)
    assert len(notices) == 0