def test_BlogAll_001(self): '''发布微博,对该条微博进行分享,评论,点赞,收藏,还原测试环境''' # 微博分享 blogShareParams = {'blogId': self.blogId} blogShareRes = Social.blogShare(userData['hostName'] + socialData['blogShare_url'], datas=blogShareParams, headers=self.headers) self.assertEqual(blogShareRes.status_code, userData['status_code_200']) # 对该微博进行评论 commentParams = {'combody': '测试评论微博'} blogcommentRes = Social.addComment( userData['hostName'] + socialData['addComment_url1'] + str(self.blogId) + socialData['addComment_url2'], headers=self.headers, datas=commentParams) self.assertEqual(blogcommentRes.status_code, userData['status_code_200']) self.commentId = json.loads(blogcommentRes.text)['data']['Imsg'] #对微博点赞 praiseBlogRes = Social.praiseBlog( userData['hostName'] + socialData['praiseBlog_url1'] + str(self.blogId) + socialData['praiseBlog_url2'], headers=self.headers) self.assertEqual(praiseBlogRes.status_code, userData['status_code_200']) # 收藏微博 collectBlogRes = Social.collectBlog( userData['hostName'] + socialData['collectBlog_url1'] + str(self.blogId) + socialData['collectBlog_url2'], headers=self.headers) self.assertEqual(collectBlogRes.status_code, userData['status_code_200']) # 删除评论 delCommentRes = Social.deleteComment(userData['hostName'] + socialData['deleteComment_url'] + str(self.commentId), headers=self.headers) self.assertEqual(delCommentRes.status_code, userData['status_code_200']) # 取消点赞 delPariseRes = Social.praiseBlog( userData['hostName'] + socialData['praiseBlog_url1'] + str(self.blogId) + socialData['praiseBlog_url2'], headers=self.headers) self.assertEqual(delPariseRes.status_code, userData['status_code_200']) # 取消收藏 delcollectBlogRes = Social.collectBlog( userData['hostName'] + socialData['collectBlog_url1'] + str(self.blogId) + socialData['collectBlog_url2'], headers=self.headers) self.assertEqual(delcollectBlogRes.status_code, userData['status_code_200'])
def test_collectBlog(self): '''收藏微博,检查我的收藏列表,取消收藏,检查我的收藏列表''' #登录账号B收藏微博 signinParams = { "account": userData['followAccount'], "password": userData['followPasswd'], "remember": False } singinRes = Auth.signin(userData['hostName'] + authData['signin_url'], datas=signinParams, headers=userData['headers']) self.assertEqual(singinRes.status_code, userData['status_code_200']) tokenRes = json.loads(singinRes.text)['data']['token'] headersRes = dict( userData['headers'], **{userData['Authorization']: userData['Bearer'] + tokenRes}) #账号B收藏微博,断言,返回200即成功 collectBlogRes = Social.collectBlog( userData['hostName'] + socialData['collectBlog_url1'] + str(self.blogId) + socialData['collectBlog_url2'], headers=headersRes) self.assertEqual(collectBlogRes.status_code, userData['status_code_200']) #检查我的收藏列表 params = {'pageIndex': 1, 'pageSize': 10} collectBlogListRes = Social.getCollectionList( userData['hostName'] + socialData['getCollectionList_url'], datas=params, headers=headersRes) self.assertEqual(collectBlogListRes.status_code, userData['status_code_200']) collectBlogList = json.loads(collectBlogListRes.text)['data']['List'] #断言:B收藏A的微博后,该微博存在于B的我的收藏列表中 collectBlogListId = [] for i in collectBlogList: collectBlogListId.append(i['MBlog']['id']) self.assertIn(self.blogId, collectBlogListId) #取消收藏,断言,返回200即成功 delCollectBlogRes = Social.collectBlog( userData['hostName'] + socialData['collectBlog_url1'] + str(self.blogId) + socialData['collectBlog_url2'], headers=headersRes) self.assertEqual(delCollectBlogRes.status_code, userData['status_code_200']) #取消收藏后,检查我的收藏列表 delcollectBlogListRes = Social.getCollectionList( userData['hostName'] + socialData['getCollectionList_url'], datas=params, headers=headersRes) self.assertEqual(delcollectBlogListRes.status_code, userData['status_code_200']) delcollectBlogList = json.loads( delcollectBlogListRes.text)['data']['List'] #断言,B取消收藏后,我的收藏列表没有该条微博 delCollectBlogListId = [] for x in delcollectBlogList: delCollectBlogListId.append(x['MBlog']['id']) self.assertNotIn(self.blogId, delCollectBlogListId)