状态码
errorcode
message
json
code和message的json 文件
{
"api3/getbanneradvertver2":[
{"1006":"token error"},
{"1006":"用户名错误"},
{"1006":"密码错误"}
],
"api3/beta4":[
{"1006":"登陆成功"},
{"1006":"用户名错误"},
{"1006":"密码错误"}
],
"api3/getcourseintro":[
{"1006":"token error"},
{"10001":"用户名错误"},
{"10002":"密码错误"}
]
}
def read_json(file_name=None):
if file_name == None:
file_path = base_path+"/Config/user_data.json"
else:
file_path = base_path+file_name
with open(file_path,encoding='UTF-8') as f:
data = json.load(f)
return data
def get_value(key,file_name=None):
data = read_json(file_name)
return data.get(key)
封装校验message 和code
#coding=utf-8
import sys
import os
import configparser
base_path = os.getcwd()
sys.path.append(base_path)
import json
from deepdiff import DeepDiff
from Util.handle_json import get_value
#print(get_value('api3/getbanneradvertver2',"/Config/code_message.json"))
'''[
{"1006,":"token error"},
{"10001":"用户名错误"},
{"10002":"密码错误"}
]'''
def handle_result(url,code):
data = get_value(url,"/Config/code_message.json")
if data !=None:
for i in data:
message = i.get(str(code))
if message:
return message
return None
def get_result_json(url,status):
data = get_value(url,"/Config/result.json")
if data !=None:
for i in data:
message = i.get(status)
if message:
return message
return None