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_tag_view(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() user1 = backend.add_user('username01','photo_url01','weibo_id01') post1 = backend.add_post('post01',user1['id'], 'video_url','pic_small1') post2 = backend.add_post('post02',user1['id'], 'video_url','pic_small2') 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) headers = self.generate_header('weibo_id01') # get resp = self.client.get('/tag/%d'% tag1.id,headers=headers) data_get = json.loads(resp.data) assert data_get['tag']['name'] == 'tag1' # get tags resp = self.client.get('/tags',headers=headers) data_get = json.loads(resp.data) assert len(data_get['results']) == 2
def test_get_latest_feed(self): user1 = backend.add_user('username01', 'photo_url01', 'weibo_id01') user2 = backend.add_user('username02', 'photo_url02', 'weibo_id02') user3 = backend.add_user('username03', 'photo_url03', 'weibo_id03') user4 = backend.add_user('username04', 'photo_url04', 'weibo_id04') post1 = backend.add_post('title01', user1['id'], 'video_url01', pic_small='pic_small01') post2 = backend.add_post('title02', user2['id'], 'video_url02', pic_small='pic_small') post3 = backend.add_post('title03', user3['id'], 'video_url03', pic_small='pic_small03') post4 = backend.add_post('title04', user4['id'], 'video_url04', pic_small='pic_small04') backend.follow_user(user4['id'], user1['id']) backend.follow_user(user4['id'], user2['id']) ret = backend.get_latest_feed(user4['id'], limit=10, offset=0) assert len(ret) == 3 backend.set_post(post3['id'], {'recommended': True}) ret = backend.get_latest_feed(user4['id'], limit=10, offset=0) assert len(ret) == 4
def test_get_latest_feed(self): user1 = backend.add_user('username01','photo_url01','weibo_id01') user2 = backend.add_user('username02','photo_url02','weibo_id02') user3 = backend.add_user('username03','photo_url03','weibo_id03') user4 = backend.add_user('username04','photo_url04','weibo_id04') post1 = backend.add_post('title01',user1['id'],'video_url01', pic_small='pic_small01') post2 = backend.add_post('title02',user2['id'],'video_url02', pic_small='pic_small') post3 = backend.add_post('title03',user3['id'],'video_url03', pic_small='pic_small03') post4 = backend.add_post('title04',user4['id'],'video_url04', pic_small='pic_small04') backend.follow_user(user4['id'],user1['id']) backend.follow_user(user4['id'],user2['id']) ret = backend.get_latest_feed(user4['id'],limit=10,offset=0) assert len(ret) == 3 backend.set_post(post3['id'],{'recommended':True}) ret = backend.get_latest_feed(user4['id'],limit=10,offset=0) assert len(ret) == 4
def test_feeds_view(self): user1 = backend.add_user('username01','photo_url01','weibo_id01') user2 = backend.add_user('username02','photo_url02','weibo_id02') user3 = backend.add_user('username03','photo_url03','weibo_id03') user4 = backend.add_user('username04','photo_url04','weibo_id04') post1 = backend.add_post('title01',user1['id'],'video_url01', pic_small='pic_small01') post2 = backend.add_post('title02',user2['id'],'video_url02', pic_small='pic_small') post3 = backend.add_post('title03',user3['id'],'video_url03', pic_small='pic_small03') post4 = backend.add_post('title04',user4['id'],'video_url04', pic_small='pic_small04') backend.follow_user(user4['id'],user1['id']) backend.follow_user(user4['id'],user2['id']) headers = self.generate_header('weibo_id04') resp = self.client.get('/feeds/%d' % user4['id'],headers=headers) ret = json.loads(resp.data) assert len(ret['results']) == 3 backend.set_post(post3['id'],{'recommended':True}) resp = self.client.get('/feeds/%d'% user4['id'],headers=headers) ret = json.loads(resp.data) assert len(ret['results']) == 4
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 test_get_user_post(self): 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') posts = backend.get_user_post(user['id']) assert len(posts) == 2 count = backend.get_user_post_count(user['id']) assert count == 2
def test_is_like_post(self): user1 = backend.add_user('username1','photo_url','weibo_id1') 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') backend.add_like(user1['id'],post1['id']) backend.add_like(user1['id'],post2['id']) ret = backend.is_like_post(user1['id'],[post1['id'],post2['id']]) assert ret[post1['id']] == True
def test_user_posts(self): user1 = backend.add_user('username01','photo_url01','weibo_id01') post1 = backend.add_post('post01',user1['id'], 'video_url','pic_small1') post2 = backend.add_post('post02',user1['id'], 'video_url','pic_small2') post3 = backend.add_post('post03',user1['id'], 'video_url','pic_small3') headers = self.generate_header('weibo_id01') resp = self.client.get('/posts/user/%d'%user1['id'],headers=headers) data_get = json.loads(resp.data) assert len(data_get['posts']) == 3
def test_user_posts(self): user1 = backend.add_user('username01', 'photo_url01', 'weibo_id01') post1 = backend.add_post('post01', user1['id'], 'video_url', 'pic_small1') post2 = backend.add_post('post02', user1['id'], 'video_url', 'pic_small2') post3 = backend.add_post('post03', user1['id'], 'video_url', 'pic_small3') headers = self.generate_header('weibo_id01') resp = self.client.get('/posts/user/%d' % user1['id'], headers=headers) data_get = json.loads(resp.data) assert len(data_get['posts']) == 3
def test_get_user_post(self): 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') posts = backend.get_user_post(user['id']) assert len(posts) == 2 count = backend.get_user_post_count(user['id']) assert count == 2
def test_comment_view(self): # post user1 = backend.add_user('username01','photo_url01','weibo_id01') headers = self.generate_header('weibo_id01') post1 = backend.add_post('post01',user1['id'], 'video_url','pic_small1') data = { 'author_id':user1['id'], 'content':'comment01', 'post_id':post1['id'] } resp = self.client.post('/comment',data=json.dumps(data),headers=headers, content_type='application/json') _data = json.loads(resp.data) assert resp.status_code == 200 assert _data['content'] == 'comment01' # delete resp = self.client.delete('/comment/%d'%_data['id'], headers=headers,content_type='application/json') print resp.data assert resp.status_code == 204
def post(self): _data = { 'author_id':request.values.get('author_id'), 'title':request.values.get('title'), } data = NewPostSchema().deserialize(_data) user = backend.get_user(data['author_id']) if user['uid'] != g.ukey: return jsonify(error='not the user') # video_file video_file = request.files.get('video_file') video_data = strutil.read_data(video_file) video_id,video_url = save_file(video_data,'video') # pic_file pic_file = request.files.get('pic_file') pic_data = strutil.read_data(pic_file) pic_id,pic_url = save_file(pic_data,'pic') data['title'] = data['title'].encode('utf-8') if data['title'] else '' try: post = backend.add_post( data['title'], data['author_id'], video_url, pic_small=pic_url ) except BackendError,ex: raise
def test_is_like_post(self): user1 = backend.add_user('username1', 'photo_url', 'weibo_id1') 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') backend.add_like(user1['id'], post1['id']) backend.add_like(user1['id'], post2['id']) ret = backend.is_like_post(user1['id'], [post1['id'], post2['id']]) assert ret[post1['id']] == True
def test_add_post(self): user = backend.add_user('username','photo_url','weibo_id') post = backend.add_post('title',user['id'],'video_url', pic_small='pic_small') assert post['title'] == 'title' post = backend.set_post(post['id'],{'title':'title2'}) assert post['title'] == 'title2'
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
def test_add_like(self): user1 = backend.add_user('username1','photo_url','weibo_id1') post1 = backend.add_post('title1',user1['id'],'video_url', pic_small='pic_small') ret = backend.add_like(user1['id'],post1['id']) assert ret == 1 ret = backend.del_like(user1['id'],post1['id']) assert ret == True
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
def test_add_post(self): user = backend.add_user('username', 'photo_url', 'weibo_id') post = backend.add_post('title', user['id'], 'video_url', pic_small='pic_small') assert post['title'] == 'title' post = backend.set_post(post['id'], {'title': 'title2'}) assert post['title'] == 'title2'
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
def test_add_like(self): user1 = backend.add_user('username1', 'photo_url', 'weibo_id1') post1 = backend.add_post('title1', user1['id'], 'video_url', pic_small='pic_small') ret = backend.add_like(user1['id'], post1['id']) assert ret == 1 ret = backend.del_like(user1['id'], post1['id']) assert ret == True
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
def test_feeds_view(self): user1 = backend.add_user('username01', 'photo_url01', 'weibo_id01') user2 = backend.add_user('username02', 'photo_url02', 'weibo_id02') user3 = backend.add_user('username03', 'photo_url03', 'weibo_id03') user4 = backend.add_user('username04', 'photo_url04', 'weibo_id04') post1 = backend.add_post('title01', user1['id'], 'video_url01', pic_small='pic_small01') post2 = backend.add_post('title02', user2['id'], 'video_url02', pic_small='pic_small') post3 = backend.add_post('title03', user3['id'], 'video_url03', pic_small='pic_small03') post4 = backend.add_post('title04', user4['id'], 'video_url04', pic_small='pic_small04') backend.follow_user(user4['id'], user1['id']) backend.follow_user(user4['id'], user2['id']) headers = self.generate_header('weibo_id04') resp = self.client.get('/feeds/%d' % user4['id'], headers=headers) ret = json.loads(resp.data) assert len(ret['results']) == 3 backend.set_post(post3['id'], {'recommended': True}) resp = self.client.get('/feeds/%d' % user4['id'], headers=headers) ret = json.loads(resp.data) assert len(ret['results']) == 4
def test_user_liked_posts(self): user1 = backend.add_user('username01','photo_url01','weibo_id01') post1 = backend.add_post('post01',user1['id'], 'video_url','pic_small1') post2 = backend.add_post('post02',user1['id'], 'video_url','pic_small2') post3 = backend.add_post('post03',user1['id'], 'video_url','pic_small3') headers = self.generate_header('weibo_id01') ula1 = UserLikeAsso(user_id=user1['id'],post_id=post1['id']) ula2 = UserLikeAsso(user_id=user1['id'],post_id=post2['id']) ula3 = UserLikeAsso(user_id=user1['id'],post_id=post3['id']) db.session.add(ula1) db.session.add(ula2) db.session.add(ula3) db.session.commit() resp = self.client.get('/posts/user/%d/liked'%user1['id'],headers=headers) data_get = json.loads(resp.data) assert len(data_get['posts']) == 3
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
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
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
def test_user_liked_posts(self): user1 = backend.add_user('username01', 'photo_url01', 'weibo_id01') post1 = backend.add_post('post01', user1['id'], 'video_url', 'pic_small1') post2 = backend.add_post('post02', user1['id'], 'video_url', 'pic_small2') post3 = backend.add_post('post03', user1['id'], 'video_url', 'pic_small3') headers = self.generate_header('weibo_id01') ula1 = UserLikeAsso(user_id=user1['id'], post_id=post1['id']) ula2 = UserLikeAsso(user_id=user1['id'], post_id=post2['id']) ula3 = UserLikeAsso(user_id=user1['id'], post_id=post3['id']) db.session.add(ula1) db.session.add(ula2) db.session.add(ula3) db.session.commit() resp = self.client.get('/posts/user/%d/liked' % user1['id'], headers=headers) data_get = json.loads(resp.data) assert len(data_get['posts']) == 3
def test_post_like(self): user1 = backend.add_user('username01','photo_url01','weibo_id01') post1 = backend.add_post('post01',user1['id'], 'video_url','pic_small1') headers = self.generate_header('weibo_id01') _data = { 'user_id':user1['id'], 'post_id':post1['id'] } resp = self.client.post('/post/like',data=json.dumps(_data), headers=headers,content_type='application/json') data_get = json.loads(resp.data) assert data_get['like_count'] == 1 resp = self.client.post('/post/unlike',data=json.dumps(_data), headers=headers,content_type='application/json') data_get = json.loads(resp.data) assert data_get['like_count'] == 0
def test_post_like(self): user1 = backend.add_user('username01', 'photo_url01', 'weibo_id01') post1 = backend.add_post('post01', user1['id'], 'video_url', 'pic_small1') headers = self.generate_header('weibo_id01') _data = {'user_id': user1['id'], 'post_id': post1['id']} resp = self.client.post('/post/like', data=json.dumps(_data), headers=headers, content_type='application/json') data_get = json.loads(resp.data) assert data_get['like_count'] == 1 resp = self.client.post('/post/unlike', data=json.dumps(_data), headers=headers, content_type='application/json') data_get = json.loads(resp.data) assert data_get['like_count'] == 0
def post(self): _data = {"author_id": request.values.get("author_id"), "title": request.values.get("title")} data = NewPostSchema().deserialize(_data) user = backend.get_user(data["author_id"]) if user["uid"] != g.ukey: return jsonify(error="not the user") # video_file video_file = request.files.get("video_file") video_data = strutil.read_data(video_file) video_id, video_url = save_file(video_data, "video") # pic_file pic_file = request.files.get("pic_file") pic_data = strutil.read_data(pic_file) pic_id, pic_url = save_file(pic_data, "pic") data["title"] = data["title"].encode("utf-8") if data["title"] else "" try: post = backend.add_post(data["title"], data["author_id"], video_url, pic_small=pic_url) except BackendError, ex: raise
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