def test_add_activity(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') ac1 = { 'post_id': post1['id'], 'from_id': user1['id'], 'to_id': user2['id'], 'atype': 'like' } ac2 = { 'post_id': post1['id'], 'from_id': user1['id'], 'to_id': user2['id'], 'atype': 'comment' } ret = backend.add_activity(ac1) assert ret['to_id'] == user2['id'] ret = backend.add_activity(ac2) rets = backend.get_activity_by_user(user2['id']) assert len(rets) == 2
def test_add_activity(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') ac1 = { 'post_id':post1['id'], 'from_id':user1['id'], 'to_id':user2['id'], 'atype':'like' } ac2 = { 'post_id':post1['id'], 'from_id':user1['id'], 'to_id':user2['id'], 'atype':'comment' } ret = backend.add_activity(ac1) assert ret['to_id'] == user2['id'] ret = backend.add_activity(ac2) rets = backend.get_activity_by_user(user2['id']) assert len(rets) == 2
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
def post(self): '''关注用户''' data = UserFollowSchema().deserialize(request.json) from_id = authutil.get_user_id(g.ukey) for uid in data['user_ids']: try: backend.follow_user(from_id, uid) backend.add_activity({ 'from_id': from_id, 'to_id': uid, 'atype': 'follow' }) except BackendError, ex: pass
def post(self): '''关注用户''' data = UserFollowSchema().deserialize(request.json) from_id = authutil.get_user_id(g.ukey) for uid in data['user_ids']: try: backend.follow_user(from_id,uid) backend.add_activity({ 'from_id':from_id, 'to_id':uid, 'atype':'follow' }) except BackendError,ex: pass
class CommentView(MethodView): 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 if post['author_id'] != data['author_id']: try: backend.add_activity({ 'post_id': data['post_id'], 'comment_id': comment['id'], 'from_id': data['author_id'], 'to_id': post['author_id'], 'atype': 'comment' }) except BackendError, ex: pass
class PostLikeView(MethodView): def post(self): data = PostLikeSchema().deserialize(request.json) try: ret = backend.add_like(data['user_id'],data['post_id']) except BackendError,ex: return jsonify(error='can not add like') try: post = backend.get_post(data['post_id']) backend.add_activity({ 'post_id':data['post_id'], 'from_id':data['user_id'], 'to_id':post['author_id'], 'atype':'like' }) except BackendError,ex: pass
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