コード例 #1
0
    def test_tag(self):

        tag1 = Tag(name='tag1', show=True, pic_url='pic_url', recommended=True)
        tag2 = Tag(name='tag2', show=True, pic_url='pic_url', recommended=True)
        db.session.add(tag1)
        db.session.add(tag2)
        db.session.commit()

        tags = backend.get_all_tags()
        assert len(tags) == 2

        tags = backend.get_recommend_tags()
        assert len(tags) == 2

        tag = backend.get_tag(tag1.id)

        assert tag['name'] == 'tag1'

        user = backend.add_user('username', 'photo_url', 'weibo_id')
        post1 = backend.add_post('title1',
                                 user['id'],
                                 'video_url',
                                 pic_small='pic_small')
        post2 = backend.add_post('title2',
                                 user['id'],
                                 'video_url',
                                 pic_small='pic_small')

        tagging1 = Tagging(taggable_type='post',
                           taggable_id=post1['id'],
                           tag_id=tag1.id)
        tagging2 = Tagging(taggable_type='post',
                           taggable_id=post2['id'],
                           tag_id=tag1.id)

        db.session.add(tagging1)
        db.session.add(tagging2)
        db.session.commit()

        posts = backend.get_tag_post(tag1.id)
        assert len(posts) == 2

        post_count = backend.get_tag_post_count(tag1.id)
        assert post_count == 2
コード例 #2
0
ファイル: tag.py プロジェクト: xiaoguangjj/motiky
    def get(self, tag_id):
        try:
            page = int(request.values.get('page'))
        except:
            page = 1

        limit = 10
        offset = (page - 1) * 50

        tag = backend.get_tag(tag_id)
        posts = backend.get_tag_post(tag_id, limit=limit, offset=offset)
        count = backend.get_tag_post_count(tag_id)

        for post in posts:
            try:
                user = backend.get_user(post['author_id'])
                post['user'] = user
            except BackendError, ex:
                continue
コード例 #3
0
ファイル: tag.py プロジェクト: gitthinkoo/motiky
    def get(self, tag_id):
        try:
            page = int(request.values.get("page"))
        except:
            page = 1

        limit = 10
        offset = (page - 1) * 50

        tag = backend.get_tag(tag_id)
        posts = backend.get_tag_post(tag_id, limit=limit, offset=offset)
        count = backend.get_tag_post_count(tag_id)

        for post in posts:
            try:
                user = backend.get_user(post["author_id"])
                post["user"] = user
            except BackendError, ex:
                continue
コード例 #4
0
ファイル: test_backend.py プロジェクト: MonaDogg/motiky
    def test_tag(self):

        tag1 = Tag(name='tag1',show=True,pic_url='pic_url',
                    recommended=True)
        tag2 = Tag(name='tag2',show=True,pic_url='pic_url',
                    recommended=True)
        db.session.add(tag1)
        db.session.add(tag2)
        db.session.commit()

        tags = backend.get_all_tags()
        assert len(tags) == 2

        tags = backend.get_recommend_tags()
        assert len(tags) == 2

        tag = backend.get_tag(tag1.id)

        assert tag['name'] == 'tag1'
        
        user = backend.add_user('username','photo_url','weibo_id')
        post1 = backend.add_post('title1',user['id'],'video_url',
                    pic_small='pic_small')
        post2 = backend.add_post('title2',user['id'],'video_url',
                    pic_small='pic_small')

        tagging1 = Tagging(taggable_type='post',taggable_id=post1['id'],
                tag_id=tag1.id)
        tagging2 = Tagging(taggable_type='post',taggable_id=post2['id'],
                tag_id=tag1.id)
        
        db.session.add(tagging1)
        db.session.add(tagging2)
        db.session.commit()

        posts = backend.get_tag_post(tag1.id)
        assert len(posts) == 2

        post_count = backend.get_tag_post_count(tag1.id)
        assert post_count == 2