def test_get_blogs_of_user(self):
        logger.info("############test_get_blogs_of_user############")
        # 先注册,记录username和password(md5)
        username = '******' % random.randrange(1000)
        logger.info("username: %s" % username)
        passwordToRegister = "wulaoshi2019"
        logger.info("passwordToRegister: %s" % passwordToRegister)
        respOfRegister = self.register_user(username, passwordToRegister, '*****@*****.**')
        logger.info("respOfRegister: %s" % respOfRegister.json())

        # 记录password的md5加密串
        passwordOfUser = md5Hash(passwordToRegister)
        logger.info("passwordToLogin: %s" % passwordOfUser)

        # 然后登录,获取token和userid
        respOfLogin = self.login_user(username, passwordOfUser)
        logger.info("respOfLogin: %s" % respOfLogin.json())
        # 获取登录返回的userid
        useridOfUser = respOfLogin.json()['userid']
        logger.info("useridOfUser: %s" % useridOfUser)
        # 获取登录返回token
        tokenOfUser = respOfLogin.json()['token']
        logger.info("tokenOfUser: %s" % tokenOfUser)

        # 创建博文
        respOfCreate = self.create_blog(useridOfUser, tokenOfUser, title="mysql", content="mysql learn")
        logger.info("resp of create_blog: %s" % respOfCreate.json())

        # 查询用户博文,需要参数:userid、token
        respOfGetBlogsOfUser = self.get_blogs_of_user(useridOfUser, tokenOfUser)
        logger.info("respOfGetBlogsOfUser: %s" % respOfGetBlogsOfUser.json())
        self.assertEqual(200, respOfGetBlogsOfUser.status_code)
        self.assertEqual("00", respOfGetBlogsOfUser.json()['code'])
    def test_create_blog(self):
        logger.info("############test_create_blog############")
        username = '******' % random.randrange(1000)
        logger.info("username: %s" % username)
        passwordToRegister = "wulaoshi2019"
        logger.info("passwordToRegister")

        # 注册新用户,记录password(md5)
        respOfRegister = self.register_user(username, passwordToRegister, '*****@*****.**')
        logger.info("respOfRegister: %s" % respOfRegister.json())
        passwordToLogin = md5Hash(passwordToRegister)
        logger.info("passwordToLogin: %s" % passwordToLogin)

        # 登录用户,记录userid和token
        respOfLogin = self.login_user(username, passwordToLogin)
        logger.info("respOfLogin: %s" % respOfLogin.json())
        useridOfRegister = respOfLogin.json()['userid']
        logger.info("useridOfRegister: %s" % useridOfRegister)
        tokenOfLogin = respOfLogin.json()['token']
        logger.info("tokenOfLogin: %s" % tokenOfLogin)

        # 创建博文并断言
        respOfCreate = self.create_blog(useridOfRegister, tokenOfLogin, title = "mysql", content = "mysql learn")
        logger.info("resp of test_create_blog: %s" % respOfCreate.json())
        self.assertEqual(200, respOfCreate.status_code)
        self.assertEqual("00", respOfCreate.json()['code'])
    def test_login_user_not_existed(self):
        logger.info("############test_login_user_not_existed############")
        username = '******' % random.randrange(1000)
        passwordToLogin = md5Hash("wulaoshi2019")

        # 登录用户
        resp = self.login_user(username,passwordToLogin)
        logger.info("resp of test_login_user_not_existed: %s" % resp.json())
        self.assertEqual(200, resp.status_code)
        # 登录的用户不存在,返回"03": 参数错误
        self.assertEqual("02", resp.json()['code'])
    def test_delete_blogs(self):
        logger.info("############test_delete_blogs############")
        passwordToRegister = "wulaoshi2019"
        logger.info("passwordToRegister")
        # 先注册用户
        username = '******' % random.randrange(1000)
        logger.info("username: %s" % username)
        passwordToRegister = "wulaoshi2019"
        logger.info("passwordToRegister: %s" % passwordToRegister)
        respOfRegister = self.register_user(username, passwordToRegister, '*****@*****.**')
        logger.info("respOfRegister: %s" % respOfRegister.json())

        # 记录password的md5加密串
        passwordOfUser = md5Hash(passwordToRegister)
        logger.info("passwordToLogin: %s" % passwordOfUser)

        # 然后登录,获取token和userid
        respOfLogin = self.login_user(username, passwordOfUser)
        logger.info("respOfLogin: %s" % respOfLogin.json())
        # 获取登录返回的userid
        useridOfUser = respOfLogin.json()['userid']
        logger.info("useridOfUser: %s" % useridOfUser)
        # 获取登录返回token
        tokenOfUser = respOfLogin.json()['token']
        logger.info("tokenOfUser: %s" % tokenOfUser)

        # 创建第一个博文
        respOfCreate1 = self.create_blog(useridOfUser, tokenOfUser, title="mysql", content="mysql learn")
        logger.info("resp of create_blog1: %s" % respOfCreate1.json())
        # 再创第二个博文
        respOfCreate2 = self.create_blog(useridOfUser, tokenOfUser, title="mysql", content="mysql learn")
        logger.info("resp of create_blog2: %s" % respOfCreate2.json())
        # 再创第三个博文
        respOfCreate3 = self.create_blog(useridOfUser, tokenOfUser, title="mysql", content="mysql learn")
        logger.info("resp of create_blog3: %s" % respOfCreate3.json())

        # 查询用户博文,获取articleIds,需要参数:userid、token
        respOfGetBlogsOfUser = self.get_blogs_of_user(useridOfUser, tokenOfUser)
        logger.info("respOfGetBlogsOfUser: %s" % respOfGetBlogsOfUser.json())
        logger.info("respOfGetBlogsOfUser.text: %s" % respOfGetBlogsOfUser.text)

        # 正则表达式获取响应结果中所有的articleId,拼成字符串,如"1,2,3"
        reFindArticleIdsRes = re.findall(r'"articleId": (\d+)', respOfGetBlogsOfUser.text)
        logger.info("reFindArticleIdsRes: %s" % reFindArticleIdsRes)
        articleIdsListStr = [int(articleId) for articleId in reFindArticleIdsRes]


        # 删除博文
        respOfDeleteBlogs = self.delete_blog(useridOfUser, tokenOfUser, articleIdsListStr)
        logger.info("respOfDeleteBlogs: %s" % respOfDeleteBlogs.json())
        self.assertEqual(200, respOfDeleteBlogs.status_code)
        self.assertEqual("00", respOfDeleteBlogs.json()['code'])
    def test_login_user_existed(self):
        logger.info("############test_create_blog############")
        username = '******' % random.randrange(100)
        passwordToRegister = "wulaoshi2019"

        # 注册新用户
        resp = self.register_user(username, passwordToRegister, '*****@*****.**')
        passwordToLogin = md5Hash(passwordToRegister)
        logger.info("username: %s" % username)
        logger.info("passwordToLogin: %s" % passwordToLogin)

        # 登录用户
        resp = self.login_user(username, passwordToLogin)
        logger.info("resp of test_login_user_existed: %s" % resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual("00", resp.json()['code'])
    def test_update_blog(self):
        logger.info("############test_update_blog############")
        # 先注册用户
        username = '******' % random.randrange(1000)
        logger.info("username: %s" % username)
        passwordToRegister = "wulaoshi2019"
        logger.info("passwordToRegister: %s" % passwordToRegister)
        respOfRegister = self.register_user(username, passwordToRegister, '*****@*****.**')
        logger.info("respOfRegister: %s" % respOfRegister.json())

        # 记录password的md5加密串
        passwordOfUser = md5Hash(passwordToRegister)
        logger.info("passwordToLogin: %s" % passwordOfUser)

        # 然后登录,获取token和userid
        respOfLogin = self.login_user(username, passwordOfUser)
        logger.info("respOfLogin: %s" % respOfLogin.json())
        # 获取登录返回的userid
        useridOfUser = respOfLogin.json()['userid']
        logger.info("useridOfUser: %s" % useridOfUser)
        # 获取登录返回token
        tokenOfUser = respOfLogin.json()['token']
        logger.info("tokenOfUser: %s" % tokenOfUser)

        # 创建博文
        respOfCreate = self.create_blog(useridOfUser, tokenOfUser, title="mysql", content="mysql learn")
        logger.info("resp of create_blog: %s" % respOfCreate.json())
        # 查询用户博文,获取articleId,,需要参数:userid、token
        respOfGetBlogsOfUser = self.get_blogs_of_user(useridOfUser, tokenOfUser)
        logger.info("respOfGetBlogsOfUser: %s" % respOfGetBlogsOfUser.json())
        articleId = respOfGetBlogsOfUser.json()['data'][0]['articleId']
        logger.info("articleId: %s" % articleId)

        # 更新博文
        # update接口参数:userid,token,articleid, title, content
        respOfUpdate = self.update_blog(useridOfUser,tokenOfUser, articleId, "update title", "update blog content")
        logger.info("resp of update_blog: %s" % respOfUpdate)
        self.assertEqual(200, respOfUpdate.status_code)
        self.assertEqual("00", respOfUpdate.json()['code'])