def review(self, review_type, review_id, audit_status, reject_reason=None, user=None, passwd=None): if user: user, passwd = user, passwd else: user, passwd = self.root, self.root_pass data = { "audit_status": audit_status, "reject_reason": reject_reason } if review_type == "sign": url = self.choice_url("sign_review") data["sign_id"] = review_id elif review_type == "temp": url = self.choice_url("temp_review") data["temp_id"] = review_id else: logging.error("[审核参数有误]: {}".format(review_type)) return logging.info("[请求地址是]: {}".format(url)) res = requests.post(url, json=data, auth=(user, passwd), headers=self.headers) logging.info("[审核结果是]: {} {} ".format(res.status_code, res.text)) self.status_code = res.status_code try: self.json = res.json() return self.json except Exception as e: self.text = res.text return self.text
def __init__(self, env=0): logging.info("[当前环境是]: {}".format(env)) if env == 0: self.head_url = url_config.get("test") elif env == 1: self.head_url = url_config.get("dev") elif env == 2: self.head_url = url_config.get("pro") else: self.head_url = url_config.get("test") self.s = requests.session() self.headers = url_config.get("default_headers") self.tieba = url_config.get("tieba") self.user = account_config.get("default_user") self.passwd = account_config.get("default_passwd") self.root = account_config.get("root_user") self.root_pass = account_config.get("root_passwd") self.phone_heads = data_config.get("default_heads") self.sign_id = data_config.get("default_sign_id") self.temp_id = data_config.get("default_temp_id") self.status_code = '' self.text = '' self.json = {} self.exp_str = ''
def download_all(self, url_list): """下载所有链接""" if isinstance(url_list, list): for url in url_list: logging.info("[当前下载的链接是]: ".format(url)) self.download_by_url(url) else: logging.error("[传入的链接格式有误]:".format(url_list))
def get_field(self, field, **kwargs): """解析get请求的指定字段""" for k, v in kwargs.items(): for d in self.json["items"]: if d[k] == v: logging.info("[当前查询字段 {} 的值是]: {}".format(field, d[field])) return d[field] logging.error("[未找到指定的字段]: {}".format(field))
def get(getkey, res_dict): if isinstance(res_dict, dict): for key, value in res_dict.items(): if key == getkey: logging.info("[当前解析的字段是 {} 解析结果是]: {}".format(key, value)) self.exp_list.append(value) break get(getkey, value) elif isinstance(res_dict, list): for ele in res_dict: get(getkey, ele)
def para_fail(request): """ 测试夹具:测试所有异常data """ code = request.param.get("http_code") exp = request.param.get("expect") logging.info("[获取的code 和 exp 是]: {} {}".format(code, exp)) for k, v in request.param.items(): if k in data: data[k] = v self.req_post(para_type, data=data) assert self.status_code == code assert self.json == exp
def tsms_get(self, url_type, user=None, passwd=None, *, headers=None): url = self.choice_url(url_type) if user and passwd: user, passwd = user, passwd else: user, passwd = self.user, self.passwd logging.info("[鉴权用户密码为]: {} {}".format(user, passwd)) hd = headers if headers else self.headers response = requests.get(url, auth=(user, passwd), headers=hd) self.status_code = response.status_code logging.info("[返回码是:] {}".format(self.status_code)) self.json = response.json() logging.info("[返回内容是]: {}".format(self.json)) return self.json
def req_delete(self, url_type, data, user=None, passwd=None, *, headers=None): url = self.choice_url(url_type) hd = headers if headers else self.headers if user and passwd: user, passwd = user, passwd else: user, passwd = self.user, self.passwd response = requests.delete(url, json=data, auth=(user, passwd), headers=hd) self.status_code = response.status_code logging.info("[req_delete 返回码是:] {}".format(self.status_code)) try: self.json = response.json() logging.info("[返回内容是]: {}".format(self.json)) return self.json except Exception as e: logging.warning("[req_delete 触发异常]".format(e)) self.text = response.text logging.info("[返回内容是]: {}".format(self.text)) return self.text