data={ 'email': email, 'nonce': nonce, 'sign': sign }, allow_redirects=False) jsonRaw = jsbeautifier.beautify(res.text) jsonObj = json.loads(jsonRaw) except: login = True log.error("登录失败") log.response(jsonRaw, 1) quit() token = jsonObj['data']['token'] log.success("登录成功, token = " + token) print() timestamp = time.time() username = jsonObj['data']['username'] sign = sha1(str(timestamp) + username + token) api = "/score/add" log.info( api + ' 添加一个曲谱, 只指定标题和正文, 期待服务器自动处理未赋值字段, \n并返回 ret=200 和添加的曲谱的 id (%s:%d)' % (currentFileName, cf.f_lineno), 0, getNum()) res = requests.post(baseUrl + api, data={ 'username': username, 'timestamp': timestamp, 'sign': sign,
log.info('/auth/nonce ' + '进行 GET 请求, 期待返回 Unexpected method 错误', 0, '#1 ') res = requests.get(baseUrl + "/auth/nonce") jsonRaw = jsbeautifier.beautify(res.text) log.response(jsonRaw, 1) jsonPass = False try: jsonObj = json.loads(jsonRaw) jsonPass = True except: log.error("返回不是有效json") if jsonPass: log.info("ret: " + str(jsonObj['ret']), 1) log.info("msg: " + str(jsonObj['msg']), 1) if 'ret' in jsonObj and jsonObj['ret'] == 405: log.success('测试通过\n', 1) log.info('/auth/nonce ' + '进行 POST 请求, 期待返回 ret=200 & nonce', 0, '#2 ') res = requests.post(baseUrl + "/auth/nonce", data={}, allow_redirects=False) jsonRaw = jsbeautifier.beautify(res.text) log.response(jsonRaw, 1) jsonPass = False try: jsonObj = json.loads(jsonRaw) jsonPass = True except: log.error("响应 body 不是有效 json") if jsonPass: log.info("ret: " + str(jsonObj['ret']), 1) log.info("nonce: " + jsonObj['data']['nonce'], 1)