Пример #1
0
    def test_post_comment_view(self):

        user1 = backend.add_user('username01','photo_url01','weibo_id01')
        post1 = backend.add_post('post01',user1['id'],
                        'video_url','pic_small1')
        comment1 = backend.add_comment(post1['id'],'comment1',user1['id'])
        comment2 = backend.add_comment(post1['id'],'comment2',user1['id'])
        comment3 = backend.add_comment(post1['id'],'comment3',user1['id'])

        headers = self.generate_header('weibo_id01')

        resp = self.client.get('/post/%d/comment' % post1['id'],headers=headers)
        data_get = json.loads(resp.data)
        assert len(data_get['comments']) == 3
Пример #2
0
    def test_user_activity_view(self):

        # get
        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',user1['id'])

        ac1 = {
                'post_id':post1['id'],
                'from_id':user1['id'],
                'to_id':user2['id'],
                'atype':'like'
                }
        ac2 = {
                'post_id':post1['id'],
                'from_id':user1['id'],
                'comment_id':comment1['id'],
                'to_id':user2['id'],
                'atype':'comment'
                }


        ret = backend.add_activity(ac1)
        ret = backend.add_activity(ac2)
        backend.new_install(user2['id'],'device_token')

        headers = self.generate_header('weibo_id2')
        resp = self.client.get('/user/%d/activity' % user2['id'],headers=headers)
        _data = json.loads(resp.data)
        assert resp.status_code == 200
        assert len(_data['results']) == 2

        redis.flushall()
        redis.hset('ACTIVITY::UPDATETIME::%(user_id)s' % {'user_id':user2['id']},
                                'last_update_time',int(time.time() - 3600 * 6))

        resp = self.client.get('/user/%d/activity/count' % user2['id'],
                headers=headers)
        _data = json.loads(resp.data)
        assert resp.status_code == 200
        assert _data['count'] == 2

        redis.hset('ACTIVITY::UPDATETIME::%(user_id)s' % {'user_id':user2['id']},
                                'last_update_time',int(time.time()) + 2)

        resp = self.client.get('/user/%d/activity/count' % user2['id'],
                headers=headers)
        _data = json.loads(resp.data)
        assert resp.status_code == 200
        assert _data['count'] == 0
Пример #3
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
Пример #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
Пример #5
0
    def post(self):
        data = NewCommentSchema().deserialize(request.json)

        user = backend.get_user(data['author_id'])

        post = backend.get_post(data['post_id'])

        if user['uid'] != g.ukey:
            return jsonify(error='not the user')

        try:
            comment = backend.add_comment(data['post_id'],
                                          data['content'].encode('utf-8'),
                                          data['author_id'])
        except BackendError, ex:
            raise
Пример #6
0
    def post(self):
        data = NewCommentSchema().deserialize(request.json)
        
        user = backend.get_user(data['author_id'])

        post = backend.get_post(data['post_id'])

        if user['uid'] != g.ukey:
            return jsonify(error='not the user')
        
        try:
            comment = backend.add_comment(
                    data['post_id'],
                    data['content'].encode('utf-8'),
                    data['author_id']
                    )
        except BackendError,ex:
            raise
Пример #7
0
    def test_user_activity_view(self):

        # get
        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', user1['id'])

        ac1 = {
            'post_id': post1['id'],
            'from_id': user1['id'],
            'to_id': user2['id'],
            'atype': 'like'
        }
        ac2 = {
            'post_id': post1['id'],
            'from_id': user1['id'],
            'comment_id': comment1['id'],
            'to_id': user2['id'],
            'atype': 'comment'
        }

        ret = backend.add_activity(ac1)
        ret = backend.add_activity(ac2)
        backend.new_install(user2['id'], 'device_token')

        headers = self.generate_header('weibo_id2')
        resp = self.client.get('/user/%d/activity' % user2['id'],
                               headers=headers)
        _data = json.loads(resp.data)
        assert resp.status_code == 200
        assert len(_data['results']) == 2

        redis.flushall()
        redis.hset(
            'ACTIVITY::UPDATETIME::%(user_id)s' % {'user_id': user2['id']},
            'last_update_time', int(time.time() - 3600 * 6))

        resp = self.client.get('/user/%d/activity/count' % user2['id'],
                               headers=headers)
        _data = json.loads(resp.data)
        assert resp.status_code == 200
        assert _data['count'] == 2

        redis.hset(
            'ACTIVITY::UPDATETIME::%(user_id)s' % {'user_id': user2['id']},
            'last_update_time',
            int(time.time()) + 2)

        resp = self.client.get('/user/%d/activity/count' % user2['id'],
                               headers=headers)
        _data = json.loads(resp.data)
        assert resp.status_code == 200
        assert _data['count'] == 0