apitest/scripts/writePage.py

74 lines
2.0 KiB
Python

# coding:utf-8
import os
import time
from config.confManage import dir_manage
from scripts.log import Log
from scripts.readYamlFile import ini_yaml
Log()
import logging
def getFilePathList(path, filetype):
pathList = []
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(filetype):
pathList.append(os.path.join(root, file))
return pathList
def write_pages(_file,pagename):
t1 = time.time()
path = dir_manage('${pro_dir}$') + dir_manage('${test_suite}$') + dir_manage('${page_dir}$') + dir_manage('${test_name}$')
print(path)
with open(path +"/" +r"{}".format(pagename), 'w+', encoding='utf-8') as f:
f.write("""# coding:utf-8\nfrom test_suite.page.{} import *\n\nurlData = ini_yaml("{}")\n\n""".format(dir_manage('${test_name}$'),_file))
yml_data = ini_yaml(_file)
for item in yml_data.items():
logging.debug("正在生成page文件.{}".format(str(item)))
f.write("""
def {testtitle}(casedata):""".format(testtitle=item[0]))
f.write("""
data = urlData["{0}"]""".format(item[0])
)
f.write(
"""
logging.info("{}".format(casedata["info"]))
res, restime = apisend(host=data["host"], address=data["address"], method=data["method"], headers=casedata["headers"],
data=casedata["data"],rel=data["relevance"])"""
)
if item[1]["relevanceCheck"]:
f.write(
"""
return {casedata["info"]:res}, restime\n\n"""
)
else :
f.write(
"""
return res, restime\n\n"""
)
t2 = time.time() - t1
print(t2)
# def write_case(f):
#
if __name__ == '__main__':
# ym_path = r'thirdUrl.yml'
# pagenames = "third_pages_1.py"
ym_path = r'urlData.yml'
pagenames = "saasApp_pages_1.py"
# write_case(ym_path,pagenames)
# ym_path = r'urlData.yml'
# pagenames = "saasWeb_pages_1.py"
write_pages(ym_path,pagenames)