Ejemplo n.º 1
0
def test_get_posts(db_conn, users_table, topics_table, posts_table):
    """
    Expect to get posts for given topic.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    posts_table.insert([{
        'id': 'jklm',
        'created': r.now(),
        'modified': r.now(),
        'user_id': 'abcd1234',
        'topic_id': 'wxyz7890',
        'body': '''A Modest Proposal for Preventing the Children of Poor
            People From Being a Burthen to Their Parents or Country, and
            for Making Them Beneficial to the Publick.''',
        'kind': 'post',
    }, {
        'id': 'tyui',
        'created': r.now(),
        'modified': r.now(),
        'user_id': 'abcd1234',
        'topic_id': 'wxyz7890',
        'body': 'A follow up.',
        'kind': 'post',
    }]).run(db_conn)

    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert code == 200
    assert ('Beneficial to the Publick' in response['posts'][0]['body']
            or 'Beneficial to the Publick' in response['posts'][1]['body'])
Ejemplo n.º 2
0
def test_update_vote(db_conn, users_table, topics_table, posts_table, session):
    """
    Expect update vote to handle proposals correctly.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_proposal_in_db(posts_table, db_conn)
    posts_table.insert({
        'id': 'vbnm1234',
        'created': r.now(),
        'modified': r.now(),
        'user_id': 'abcd1234',
        'topic_id': 'wxyz7890',
        'proposal_id': 'jklm',
        'body': 'Boo!',
        'response': False,
        'kind': 'vote',
        'replies_to_id': 'val2345t',
    }).run(db_conn)

    request = {
        'cookies': {
            'session_id': session
        },
        'params': {
            'body': 'Yay!',
            'response': True,
        }
    }
    code, response = routes.topic.update_post_route(request, 'wxyz7890',
                                                    'vbnm1234')
    assert code == 200
    assert True is response['post']['response']
Ejemplo n.º 3
0
def test_get_posts(db_conn):
    """
  Expect to get posts for given topic.
  """

    create_user_in_db(db_conn)
    create_topic_in_db(db_conn)
    raw_insert_posts(db_conn, [{
        'user_id': user_id,
        'topic_id': topic_a_uuid,
        'body': '''A Modest Proposal for Preventing the Children of Poor
    People From Being a Burthen to Their Parents or Country, and
    for Making Them Beneficial to the Publick.''',
        'kind': 'post',
    }, {
        'user_id': user_id,
        'topic_id': topic_a_uuid,
        'body': 'A follow up.',
        'kind': 'post',
    }])

    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.post.get_posts_route(request, topic_a_uuid)
    assert code == 200
    assert ('Beneficial to the Publick' in response['posts'][0]['body']
            or 'Beneficial to the Publick' in response['posts'][1]['body'])
Ejemplo n.º 4
0
def test_get_posts_votes(db_conn, users_table, units_table, topics_table,
                         posts_table):
    """
    Expect get posts for topic to render votes correctly.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_proposal_in_db(posts_table, units_table, db_conn)
    posts_table.insert({
        'id': 'asdf4567',
        'created': r.now(),
        'modified': r.now(),
        'kind': 'vote',
        'body': 'Hooray!',
        'proposal_id': 'jklm',
        'topic_id': 'wxyz7890',
        'response': True,
        'user_id': 'abcd1234',
    }).run(db_conn)

    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')

    assert code == 200
    assert response['posts'][0]['kind'] in ('proposal', 'vote')
    assert response['posts'][1]['kind'] in ('proposal', 'vote')
Ejemplo n.º 5
0
def test_get_posts_paginate(db_conn, users_table, topics_table,
                            posts_table):
    """
    Expect get posts for topic to paginate.
    """
    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    for i in range(0, 25):
        posts_table.insert({
            'id': 'jklm%s' % i,
            'created': r.now(),
            'modified': r.now(),
            'user_id': 'abcd1234',
            'topic_id': 'wxyz7890',
            'body': 'test %s' % i,
            'kind': 'post',
        }).run(db_conn)

    request = {
        'params': {},
        'db_conn': db_conn
    }
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert code == 200
    assert len(response['posts']) == 10
    request.update({'params': {'skip': 20}})
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert len(response['posts']) == 5
Ejemplo n.º 6
0
def test_get_posts(db_conn, users_table, topics_table, posts_table):
    """
    Expect to get posts for given topic.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    posts_table.insert([{
        'id': 'jklm',
        'created': r.now(),
        'modified': r.now(),
        'user_id': 'abcd1234',
        'topic_id': 'wxyz7890',
        'body': '''A Modest Proposal for Preventing the Children of Poor
            People From Being a Burthen to Their Parents or Country, and
            for Making Them Beneficial to the Publick.''',
        'kind': 'post',
    }, {
        'id': 'tyui',
        'created': r.now(),
        'modified': r.now(),
        'user_id': 'abcd1234',
        'topic_id': 'wxyz7890',
        'body': 'A follow up.',
        'kind': 'post',
    }]).run(db_conn)

    request = {
        'params': {},
        'db_conn': db_conn
    }
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert code == 200
    assert ('Beneficial to the Publick' in response['posts'][0]['body']
            or 'Beneficial to the Publick' in response['posts'][1]['body'])
Ejemplo n.º 7
0
def test_update_vote(db_conn, users_table, topics_table,
                     posts_table, units_table, session):
    """
    Expect update vote to handle proposals correctly.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_proposal_in_db(posts_table, units_table, db_conn)
    posts_table.insert({
        'id': 'vbnm1234',
        'created': r.now(),
        'modified': r.now(),
        'user_id': 'abcd1234',
        'topic_id': 'wxyz7890',
        'proposal_id': 'jklm',
        'body': 'Boo!',
        'response': False,
        'kind': 'vote',
        'replies_to_id': 'val2345t',
    }).run(db_conn)

    request = {
        'cookies': {'session_id': session},
        'params': {
            'body': 'Yay!',
            'response': True,
        },
        'db_conn': db_conn
    }
    code, response = routes.topic.update_post_route(request,
                                                    'wxyz7890', 'vbnm1234')
    assert code == 200
    assert True is response['post']['response']
Ejemplo n.º 8
0
def test_get_posts_votes(db_conn, users_table, units_table, topics_table,
                         posts_table):
    """
    Expect get posts for topic to render votes correctly.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_proposal_in_db(posts_table, units_table, db_conn)
    posts_table.insert({
        'id': 'asdf4567',
        'created': r.now(),
        'modified': r.now(),
        'kind': 'vote',
        'body': 'Hooray!',
        'proposal_id': 'jklm',
        'topic_id': 'wxyz7890',
        'response': True,
    }).run(db_conn)

    request = {
        'params': {},
        'db_conn': db_conn
    }
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')

    assert code == 200
    assert response['posts'][0]['kind'] in ('proposal', 'vote')
    assert response['posts'][1]['kind'] in ('proposal', 'vote')
Ejemplo n.º 9
0
def test_user_token_fail(db_conn, users_table):
    """
    Expect to create a token so the user can get a new password.
    """

    create_user_in_db(users_table, db_conn)
    request = {'params': {'email': 'other'}, 'db_conn': db_conn}
    code, response = routes.user.create_token_route(request)
    assert code == 404
Ejemplo n.º 10
0
def test_user_get(db_conn, users_table):
    """
    Ensure a user can be retrieved by ID.
    """

    create_user_in_db(users_table, db_conn)
    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.user.get_user_route(request, 'abcd1234')
    assert response['user']['name'] == 'test'
Ejemplo n.º 11
0
def test_user_get(db_conn, users_table):
    """
    Ensure a user can be retrieved by ID.
    """

    create_user_in_db(users_table, db_conn)
    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.user.get_user_route(request, 'abcd1234')
    assert response['user']['name'] == 'test'
Ejemplo n.º 12
0
def test_user_token_success(db_conn, users_table):
    """
    Expect to create a token so the user can get a new password.
    """

    create_user_in_db(users_table, db_conn)
    request = {'params': {'email': '*****@*****.**'}, 'db_conn': db_conn}
    code, response = routes.user.create_token_route(request)
    assert code == 200
Ejemplo n.º 13
0
def test_user_token_fail(db_conn):
    """
  Expect to create a token so the user can get a new password.
  """

    create_user_in_db(db_conn)
    request = {'params': {'email': 'other'}, 'db_conn': db_conn}
    code, _ = routes.user.create_token_route(request)
    assert code == 404
Ejemplo n.º 14
0
def test_user_log_in_password_fail(db_conn, users_table):
    """
    Ensure a user can't log in if password is wrong.
    """

    create_user_in_db(users_table, db_conn)
    request = {"params": {"name": "test", "password": "******"}}
    code, response = routes.user.log_in_route(request)
    assert "errors" in response
Ejemplo n.º 15
0
def test_user_token_success(db_conn, users_table):
    """
    Expect to create a token so the user can get a new password.
    """

    create_user_in_db(users_table, db_conn)
    request = {"params": {"email": "*****@*****.**"}}
    code, response = routes.user.create_token_route(request)
    assert code == 200
Ejemplo n.º 16
0
def test_user_get(db_conn, users_table):
    """
    Ensure a user can be retrieved by ID.
    """

    create_user_in_db(users_table, db_conn)
    request = {"params": {}}
    code, response = routes.user.get_user_route(request, "abcd1234")
    assert response["user"]["name"] == "test"
Ejemplo n.º 17
0
def test_user_log_in(db_conn, users_table):
    """
    Ensure a user can log in.
    """

    create_user_in_db(users_table, db_conn)
    request = {"params": {"name": "test", "password": "******"}}
    code, response = routes.user.log_in_route(request)
    assert "*****@*****.**" == response["user"]["email"]
Ejemplo n.º 18
0
def test_log_in_user(users_table, db_conn):
    """
    Expect to log in as a user.
    """

    create_user_in_db(users_table, db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    token = log_in_user(user)
    assert token
    assert redis.get(token).decode() == 'abcd1234'
Ejemplo n.º 19
0
def test_user_get(db_conn):
    """
  Ensure a user can be retrieved by ID.
  """

    create_user_in_db(db_conn)
    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.user.get_user_route(request, user_id)
    assert code == 200
    assert response['user']['name'] == 'test'
Ejemplo n.º 20
0
def test_log_in_user(db_conn):
    """
  Expect to log in as a user.
  """

    create_user_in_db(db_conn)
    user = get_user(db_conn, {'id': user_id})
    token = log_in_user(user)
    assert token
    assert red.get(token).decode() == convert_uuid_to_slug(user_id)
Ejemplo n.º 21
0
def test_log_in_user(users_table, db_conn):
    """
    Expect to log in as a user.
    """

    create_user_in_db(users_table, db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    token = log_in_user(user)
    assert token
    assert redis.get(token).decode() == 'abcd1234'
Ejemplo n.º 22
0
def test_get_current_user(users_table, db_conn):
    """
    Expect to get the current user given session info.
    """

    create_user_in_db(users_table, db_conn)
    token = log_in()
    user = get_current_user({'cookies': {'session_id': token}})
    assert user
    assert user['id'] == 'abcd1234'
Ejemplo n.º 23
0
def test_get_my_recent_proposals(db_conn, posts_table, users_table,
                                 units_table, subjects_table):
    """
    Get the user's most recent proposals.
    """

    create_user_in_db(users_table, db_conn)
    current_user = users_table.get('abcd1234').run(db_conn)
    create_some_proposals(posts_table, units_table, subjects_table, db_conn)
    proposals = get_my_recent_proposals(current_user, db_conn)
    assert len(proposals) == 2
Ejemplo n.º 24
0
def test_log_out_user(users_table, db_conn):
    """
    Expect to log out as a user.
    """

    create_user_in_db(users_table, db_conn)
    user = User.get(id='abcd1234')
    token = log_in_user(user)
    assert redis.get(token).decode() == 'abcd1234'
    log_out_user({'cookies': {'session_id': token}})
    assert redis.get(token) is None
Ejemplo n.º 25
0
def test_user_log_in(db_conn, users_table):
    """
    Ensure a user can log in.
    """

    create_user_in_db(users_table, db_conn)
    request = {
        'params': {'name': 'test', 'password': '******'},
        'db_conn': db_conn
    }
    code, response = routes.user.log_in_route(request)
    assert '*****@*****.**' == response['user']['email']
Ejemplo n.º 26
0
def test_user_log_in_password_fail(db_conn, users_table):
    """
    Ensure a user can't log in if password is wrong.
    """

    create_user_in_db(users_table, db_conn)
    request = {
        'params': {'name': 'test', 'password': '******'},
        'db_conn': db_conn
    }
    code, response = routes.user.log_in_route(request)
    assert 'errors' in response
Ejemplo n.º 27
0
def test_get_my_recently_created_subjects(db_conn, posts_table, units_table,
                                          subjects_table, users_table):
    """
    Get the user's most recent subjects.
    """

    create_user_in_db(users_table, db_conn)
    current_user = users_table.get('abcd1234').run(db_conn)
    create_some_proposals(posts_table, units_table, subjects_table, db_conn)
    subjects = get_my_recently_created_subjects(current_user, db_conn)
    assert len(subjects) == 2
    assert subjects[0]['entity_id'] == 'A'
    assert subjects[1]['entity_id'] == 'C'
Ejemplo n.º 28
0
def test_get_posts_proposal(db_conn, users_table, topics_table, posts_table):
    """
    Expect get posts for topic to render a proposal correctly.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_proposal_in_db(posts_table, db_conn)

    request = {'params': {}}
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert code == 200
    assert response['posts'][0]['kind'] == 'proposal'
Ejemplo n.º 29
0
def test_user_log_out(db_conn, users_table):
    """
    Ensure a user can log out.
    """

    create_user_in_db(users_table, db_conn)
    request = {"params": {"name": "test", "password": "******"}}
    code, response = routes.user.log_in_route(request)
    assert code == 200
    session_id = response["cookies"]["session_id"]
    request = {"cookies": {"session_id": session_id}}
    code, response = routes.user.log_out_route(request)
    assert code == 200
    assert "cookies" in response
Ejemplo n.º 30
0
def test_update_post_log_in(db_conn):
    """
  Expect update post to require log in.
  """

    create_user_in_db(db_conn)
    create_topic_in_db(db_conn)
    create_post_in_db(db_conn)
    request = {'params': {'body': 'Update.'}, 'db_conn': db_conn}
    code, response = routes.post.update_post_route(request, topic_a_uuid,
                                                   post_a_uuid)

    assert code == 401
    assert 'errors' in response
Ejemplo n.º 31
0
def test_get_posts_proposal(db_conn, users_table, topics_table,
                            posts_table):
    """
    Expect get posts for topic to render a proposal correctly.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_proposal_in_db(posts_table, db_conn)

    request = {'params': {}}
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert code == 200
    assert response['posts'][0]['kind'] == 'proposal'
Ejemplo n.º 32
0
def test_update_post_log_in(db_conn, users_table, topics_table, posts_table):
    """
    Expect update post to require log in.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_post_in_db(posts_table, db_conn)
    request = {'params': {'post': {'body': 'Update.'}}, 'db_conn': db_conn}
    code, response = routes.topic.update_post_route(request, 'wxyz7890',
                                                    'jklm')

    assert code == 401
    assert 'errors' in response
Ejemplo n.º 33
0
def test_user_log_in_password_fail(db_conn, users_table):
    """
    Ensure a user can't log in if password is wrong.
    """

    create_user_in_db(users_table, db_conn)
    request = {
        'params': {
            'name': 'test',
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.log_in_route(request)
    assert 'errors' in response
Ejemplo n.º 34
0
def test_user_log_in(db_conn, users_table):
    """
    Ensure a user can log in.
    """

    create_user_in_db(users_table, db_conn)
    request = {
        'params': {
            'name': 'test',
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.log_in_route(request)
    assert '*****@*****.**' == response['user']['email']
Ejemplo n.º 35
0
def test_get_current_user(db_conn):
    """
  Expect to get the current user given session info.
  """

    create_user_in_db(db_conn)
    token = log_in()
    user = get_current_user({
        'cookies': {
            'session_id': token
        },
        'db_conn': db_conn,
    })
    assert user
    assert user['id'] == convert_slug_to_uuid(user_id)
Ejemplo n.º 36
0
def test_user_create_password_ok(db_conn, users_table):
    """
    Expect a user to be able to reset their password.
    """

    create_user_in_db(users_table, db_conn)
    user = User.get(id="abcd1234")
    pw1 = user["password"]
    token = user.get_email_token(send_email=False)

    request = {"params": {"token": token, "password": "******"}}
    code, response = routes.user.create_password_route(request, "abcd1234")
    assert code == 200
    user.sync()
    assert user["password"] != pw1
Ejemplo n.º 37
0
def test_get_posts_proposal(db_conn):
    """
  Expect get posts for topic to render a proposal correctly.
  """

    create_user_in_db(db_conn)
    create_topic_in_db(db_conn)
    create_proposal_in_db(db_conn)

    request = {
        'params': {},
        'db_conn': db_conn,
    }
    code, response = routes.post.get_posts_route(request, topic_a_uuid)
    assert code == 200
    assert response['posts'][0]['kind'] == 'proposal'
Ejemplo n.º 38
0
def test_log_out_user(db_conn):
    """
  Expect to log out as a user.
  """

    create_user_in_db(db_conn)
    user = get_user(db_conn, {'id': user_id})
    token = log_in_user(user)
    assert red.get(token).decode() == convert_uuid_to_slug(user_id)
    log_out_user({
        'cookies': {
            'session_id': token
        },
        'db_conn': db_conn,
    })
    assert red.get(token) is None
Ejemplo n.º 39
0
def test_user_log_out(db_conn, users_table):
    """
    Ensure a user can log out.
    """

    create_user_in_db(users_table, db_conn)
    request = {
        'params': {'name': 'test', 'password': '******'},
        'db_conn': db_conn
    }
    code, response = routes.user.log_in_route(request)
    assert code == 200
    session_id = response['cookies']['session_id']
    request = {'cookies': {'session_id': session_id}}
    code, response = routes.user.log_out_route(request)
    assert code == 200
    assert 'cookies' in response
Ejemplo n.º 40
0
def test_user_log_out(db_conn, users_table):
    """
    Ensure a user can log out.
    """

    create_user_in_db(users_table, db_conn)
    request = {
        'params': {
            'name': 'test',
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.log_in_route(request)
    assert code == 200
    session_id = response['cookies']['session_id']
    request = {'cookies': {'session_id': session_id}}
    code, response = routes.user.log_out_route(request)
    assert code == 200
    assert 'cookies' in response
Ejemplo n.º 41
0
def test_user_create_password_ok(db_conn, users_table):
    """
    Expect a user to be able to reset their password.
    """

    create_user_in_db(users_table, db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    pw1 = user['password']
    token = get_email_token(user, send_email=False)

    request = {
        'params': {
            'token': token,
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.create_password_route(request, 'abcd1234')
    assert code == 200
    user = get_user({'id': 'abcd1234'}, db_conn)
    assert user['password'] != pw1
Ejemplo n.º 42
0
def test_user_create_password_ok(db_conn):
    """
  Expect a user to be able to reset their password.
  """

    create_user_in_db(db_conn)
    user = get_user(db_conn, {'id': user_id})
    pw1 = user['password']
    token = get_email_token(user)

    request = {
        'params': {
            'token': token,
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, _ = routes.user.create_password_route(request, user_id)
    assert code == 200
    user = get_user(db_conn, {'id': user_id})
    assert user['password'] != pw1
Ejemplo n.º 43
0
def test_user_create_password_ok(db_conn, users_table):
    """
    Expect a user to be able to reset their password.
    """

    create_user_in_db(users_table, db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    pw1 = user['password']
    token = get_email_token(user, send_email=False)

    request = {
        'params': {
            'token': token,
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.create_password_route(request, 'abcd1234')
    assert code == 200
    user = get_user({'id': 'abcd1234'}, db_conn)
    assert user['password'] != pw1
Ejemplo n.º 44
0
def test_update_post_log_in(db_conn, users_table, topics_table,
                            posts_table):
    """
    Expect update post to require log in.
    """

    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    create_post_in_db(posts_table, db_conn)
    request = {
        'params': {
            'post': {
                'body': 'Update.'
            }
        }
    }
    code, response = routes.topic.update_post_route(request,
                                                    'wxyz7890', 'jklm')

    assert code == 401
    assert 'errors' in response
Ejemplo n.º 45
0
def test_get_posts_votes(db_conn):
    """
  Expect get posts for topic to render votes correctly.
  """

    create_user_in_db(db_conn)
    create_topic_in_db(db_conn)
    create_proposal_in_db(db_conn)
    raw_insert_posts(db_conn, [{
        'kind': 'vote',
        'body': 'Hooray!',
        'replies_to_id': proposal_a_uuid,
        'topic_id': topic_a_uuid,
        'response': True,
        'user_id': user_id,
    }])

    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.post.get_posts_route(request, topic_a_uuid)

    assert code == 200
    assert response['posts'][0]['kind'] in ('proposal', 'vote')
    assert response['posts'][1]['kind'] in ('proposal', 'vote')
Ejemplo n.º 46
0
def test_get_posts_paginate(db_conn, users_table, topics_table, posts_table):
    """
    Expect get posts for topic to paginate.
    """
    create_user_in_db(users_table, db_conn)
    create_topic_in_db(topics_table, db_conn)
    for i in range(0, 25):
        posts_table.insert({
            'id': 'jklm%s' % i,
            'created': r.now(),
            'modified': r.now(),
            'user_id': 'abcd1234',
            'topic_id': 'wxyz7890',
            'body': 'test %s' % i,
            'kind': 'post',
        }).run(db_conn)

    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert code == 200
    assert len(response['posts']) == 10
    request.update({'params': {'skip': 20}})
    code, response = routes.topic.get_posts_route(request, 'wxyz7890')
    assert len(response['posts']) == 5
Ejemplo n.º 47
0
def test_get_posts_paginate(db_conn):
    """
  Expect get posts for topic to paginate.
  """
    create_user_in_db(db_conn)
    create_topic_in_db(db_conn)
    raw_insert_posts(db_conn, [{
        'user_id': user_id,
        'topic_id': topic_a_uuid,
        'body': 'test %s' % i,
        'kind': 'post',
    } for i in range(0, 25)])
    request = {'params': {}, 'db_conn': db_conn}
    code, response = routes.post.get_posts_route(request, topic_a_uuid)
    assert code == 200
    assert len(response['posts']) == 10
    request = {
        'params': {
            'offset': 20,
        },
        'db_conn': db_conn
    }
    code, response = routes.post.get_posts_route(request, topic_a_uuid)
    assert len(response['posts']) == 5