Beispiel #1
0
    def get(self,post_id):
        try:
            page = int(request.values.get('page','1'))
        except:
            page = 1

        limit = 20
        offset = (page-1)*limit

        comments = backend.get_post_comment(post_id,
                limit=limit,offset=offset)

        for comment in comments:
            user = backend.get_user(comment['author_id'])
            comment['user'] = user

        count = backend.get_post_comment_count(post_id)
        total_page = (count + limit -1 ) / limit
        return jsonify(comments=comments,page=page,total_page=total_page)
Beispiel #2
0
    def test_comment(self):
        user1 = backend.add_user('username1','photo_url','weibo_id1')
        user2 = backend.add_user('username2','photo_url','weibo_id2')
        post1 = backend.add_post('title1',user1['id'],'video_url',
                    pic_small='pic_small')
        post2 = backend.add_post('title2',user1['id'],'video_url',
                    pic_small='pic_small')

        
        comment1 = backend.add_comment(post1['id'],'comment1',user2['id'])
        assert comment1['post_id'] == post1['id']

        comment2 = backend.add_comment(post1['id'],'comment2',user2['id'])
        
        comments = backend.get_post_comment(post1['id'])

        assert len(comments) == 2
        
        ret = backend.get_post_comment_count(post1['id'])
        assert ret == 2
Beispiel #3
0
    def get(self, post_id):
        try:
            page = int(request.values.get('page', '1'))
        except:
            page = 1

        limit = 20
        offset = (page - 1) * limit

        comments = backend.get_post_comment(post_id,
                                            limit=limit,
                                            offset=offset)

        for comment in comments:
            user = backend.get_user(comment['author_id'])
            comment['user'] = user

        count = backend.get_post_comment_count(post_id)
        total_page = (count + limit - 1) / limit
        return jsonify(comments=comments, page=page, total_page=total_page)
Beispiel #4
0
    def test_comment(self):
        user1 = backend.add_user('username1', 'photo_url', 'weibo_id1')
        user2 = backend.add_user('username2', 'photo_url', 'weibo_id2')
        post1 = backend.add_post('title1',
                                 user1['id'],
                                 'video_url',
                                 pic_small='pic_small')
        post2 = backend.add_post('title2',
                                 user1['id'],
                                 'video_url',
                                 pic_small='pic_small')

        comment1 = backend.add_comment(post1['id'], 'comment1', user2['id'])
        assert comment1['post_id'] == post1['id']

        comment2 = backend.add_comment(post1['id'], 'comment2', user2['id'])

        comments = backend.get_post_comment(post1['id'])

        assert len(comments) == 2

        ret = backend.get_post_comment_count(post1['id'])
        assert ret == 2