예제 #1
0
    def test_get_user_liked_post(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')

        ula1 = UserLikeAsso(user_id=user2['id'],post_id=post1['id'])
        ula2 = UserLikeAsso(user_id=user2['id'],post_id=post2['id'])
        db.session.add(ula1)
        db.session.add(ula2)
        db.session.commit()

        posts = backend.get_user_liked_post(user2['id'])
        assert len(posts) == 2

        count = backend.get_user_liked_post_count(user2['id'])
        assert count == 2
예제 #2
0
파일: post.py 프로젝트: gitthinkoo/motiky
    def get(self, user_id):
        try:
            page = int(request.values.get("page"))
        except:
            page = 1

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

        liked_posts = backend.get_user_liked_post(user_id, limit=limit, offset=offset)
        for p in liked_posts:
            p["is_like"] = True
            p["like_count"] = backend.get_post_liked_count(p["id"])
            p["comment_count"] = backend.get_post_comment_count(p["id"])

        count = backend.get_user_liked_post_count(user_id)
        total_page = (count + limit - 1) / limit

        return jsonify(posts=liked_posts, page=page, total_page=total_page)
예제 #3
0
    def get(self,user_id):
        try:
            page = int(request.values.get('page'))
        except:
            page = 1

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

        liked_posts = backend.get_user_liked_post(user_id,limit=limit,offset=offset)
        for p in liked_posts:
            p['is_like'] = True
            p['like_count'] = backend.get_post_liked_count(p['id'])
            p['comment_count'] = backend.get_post_comment_count(p['id'])
        

        count = backend.get_user_liked_post_count(user_id)
        total_page = (count + limit -1) / limit
        
        return jsonify(posts=liked_posts,page=page,total_page=total_page)
예제 #4
0
    def test_get_user_liked_post(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')

        ula1 = UserLikeAsso(user_id=user2['id'], post_id=post1['id'])
        ula2 = UserLikeAsso(user_id=user2['id'], post_id=post2['id'])
        db.session.add(ula1)
        db.session.add(ula2)
        db.session.commit()

        posts = backend.get_user_liked_post(user2['id'])
        assert len(posts) == 2

        count = backend.get_user_liked_post_count(user2['id'])
        assert count == 2