#!/usr/bin/env/python3
# -*- coding:utf-8 -*-
'''
Author:leo
Date&Time:2020/2/24 and 17:29
Project:Python3
FileName:tmp_comment.py
Description:...
1.快速构造请求头:
(.*?):(.*) "$1":"$2",
(.*?): (.*) # (.*) $1: "", # $3
(.*?): (.*), # (.*) $1: kwargs.get($1, ""), # $3
2.快速构建表头注释:(.*?)\s(.*) "$1":$1 #$2
3.批量去除注释:#(.*) ""
'''
import re
comment_path = "D:\Mytest\Python3\Python3\...\sit\\testcase\\testUI\comment_txt"
# 移除代码内部注释信息
def remove_comment():
'''
描述:移除代码内部注释信息,去掉#后面的内容
举例:
# 注释信息
""
@return: None
'''
with open("D:\Mytest\Python3\Python3\...\hb_config.py", "r+", encoding="utf-8") as f:
all = f.read().splitlines()
for i in all:
if "#" in str(i.strip(" ")):
i = re.sub(r'#(.*)', "", i)
print(i)
# 构建接口请求参数
def build_request_parameters():
'''
描述:批量构建函数请求体body中的参数
举例:
token 登录授权码
"token":kwargs.get("token", "") # 登录授权码
@return: None
'''
with open(comment_path, "r+", encoding="gbk") as f:
all = f.read().splitlines()
str_all = ""
for i in all:
i = re.sub(r'(.*?)\s(.*)', r'"\1": kwargs.get("\1", ""), # \2', i)
str_all = str_all + i + "\n"
print(str_all)
# with open(r"D:\Mytest\Python3\Python3\...\testfile\tmp1", "w+", encoding="gbk") as ff:
# ff.write(str_all)
# return str_all
# 构建函数的默认参数
def build_default_parameters():
"""
描述:批量构建函数的默认参数
举例:
"token": kwargs.get("token", ""), # 登录授权码
"userName": kwargs.get("userName", ""), # 姓名
token=None, userName=None
@return: None
"""
with open(comment_path, "r+", encoding="gbk") as f:
all = f.read().splitlines()
newstr = ""
for i in all:
if ":" in i and "[" not in i and "{" not in i and "}" not in i:
# i = i.split(',')[0].strip().split(":")[1].strip()
i = i.split(":")[0].strip(" ").replace('"', "")
newstr = newstr+i+"=None, "
print(newstr)
def buile_comment():
import ast
"""
描述:批量构建函数的默认参数
举例:
0 - 仅鉴权
1 - 仅登记
2 - 鉴权并登记
(0-仅鉴权, 1-仅登记, 2-鉴权并登记)
@return: None
"""
with open(comment_path, "r+", encoding="gbk") as f:
all = f.read().splitlines()
user_str = ""
for i in all:
# i = f"{i}=user_dic['{i}'], "
i = "".join(i.split()) + ", "
user_str = user_str + i
user_str = "("+user_str[0:-2]+")"
print(user_str)
# build_request_parameters() # 快速构建接口默认参数
# build_default_parameters() # 快速构建请求参数
buile_comment() # 快速注释枚举
#!/usr/bin/env/python3
# -*- coding:utf-8 -*-
'''
Author:leo
Date&Time:2020/6/28 and 10:30
Project:Python3
FileName:
Description:
1.接口测试,单接口模板
'''
import requests, time, random, linecache, os, re, datetime, json, sys, ast
from sit.library.basic import Basic
# 单个业务测试类
class test():
# 初始化静态参数
def __init__(self):
self.logTime = time.strftime('%Y%m%d_%H:%M:%S', time.localtime(time.time()))
self.curTime = time.strftime('%Y%m%d %H%M%S', time.localtime(time.time()))
self.nowdate_8, self.nowtime_6, self.random_3 = self.curTime.split(" ")[0], self.curTime.split(" ")[1], str(random.randint(100, 999))
# 1.test
def test(self, *args, **kwargs):
message = "test"
url = "/v1/customerLogin/test"
headers = {"Content-Type": "application/json", "User-Agent": "PostmanRuntime/7.24.0"}
payload = {
"body": {
"identifier": kwargs.get("identifier", ""), # !登录账号
"password": kwargs.get("password", ""), # !登录密码
}
}
res = Basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))
return res
# 2.test
def test(self, *args, **kwargs):
message = "test"
url = "/v1/customerLogin/test"
headers = {"Content-Type": "application/json", "User-Agent": "PostmanRuntime/7.24.0"}
payload = {
"body": {
"identifier": kwargs.get("identifier", ""), # !登录账号
"password": kwargs.get("password", ""), # !登录密码
}
}
res = Basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))
return res
# 2.test
def test(self, *args, **kwargs):
message = "test"
url = "/v1/customerLogin/test"
headers = {"Content-Type": "application/json", "User-Agent": "PostmanRuntime/7.24.0"}
payload = {
"body": {
"identifier": kwargs.get("identifier", ""), # !登录账号
"password": kwargs.get("password", ""), # !登录密码
}
}
res = Basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))
return res
# 4.test
def test(self, *args, **kwargs):
message = "test"
url = "/v1/customerLogin/test"
headers = {"Content-Type": "application/json", "User-Agent": "PostmanRuntime/7.24.0"}
payload = {
"body": {
"identifier": kwargs.get("identifier", ""), # !登录账号
"password": kwargs.get("password", ""), # !登录密码
}
}
res = Basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))
return res
# 5.原始接口测试
def tmp_test(self):
message = "3.2.2.25. 查询贷款可选期限(实时接口)"
url = "https://"
headers = {"Content-Type": "application/json", "User-Agent": "PostmanRuntime/7.24.0"}
payload = {}
print(payload)
response = requests.post(url, headers, payload)
print(response.json())
return response
if __name__ == "__main__":
pass