mirror of https://gitee.com/a529548204/apitest.git
增加自动生成page的脚本 根据urlData.yml文件
This commit is contained in:
parent
6f575a3749
commit
6d92b3460a
|
@ -140,18 +140,21 @@ def assert_sql(hope_res, real_res):
|
|||
t1 = time.time()
|
||||
datas = db.run_sql(h_sql)
|
||||
try:
|
||||
with allure.step("断言判断相等"):
|
||||
with allure.step("数据库校验"):
|
||||
allure.attach(name="期望结果", body=str(datas))
|
||||
allure.attach(name='实际实际结果', body=str(r_res))
|
||||
allure.attach(name='sql命令', body=str(h_sql))
|
||||
assert r_res == datas[0][i["name"]]
|
||||
logging.info("sql断言通过, 期望结果{0}, 实际结果{1},sql耗时{2:.5f}秒".format(datas, r_res,time.time()-t1))
|
||||
logging.info(
|
||||
"sql断言通过, 期望结果{0}, 实际结果{1},sql耗时{2:.5f}秒".format(datas, r_res, time.time() - t1))
|
||||
except AssertionError:
|
||||
logging.error("sql断言未通过, 期望结果{0}, 实际结果{1},sql耗时{2:.5f}秒".format(datas, r_res,time.time()-t1))
|
||||
logging.error("sql断言未通过, 期望结果{0}, 实际结果{1},sql耗时{2:.5f}秒".format(datas, r_res, time.time() - t1))
|
||||
raise
|
||||
else:
|
||||
raise ValueError("获取json值失败,请检查jsonpath")
|
||||
|
||||
def asserting(hope_res, real_res,re_time=None):
|
||||
|
||||
def asserting(hope_res, real_res, re_time=None):
|
||||
if hope_res["jsonpath"]:
|
||||
assert_text(hope_res, real_res)
|
||||
if hope_res["sqlassert"]:
|
||||
|
@ -160,11 +163,10 @@ def asserting(hope_res, real_res,re_time=None):
|
|||
assert_time(hope_res, re_time)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
j = {'code': 0, 'msg': 'Success.', 'data': {
|
||||
'token': 'eyJ1c2VyX2lkIjoxOTYsInVzZXJuYW1lIjoiZmluc2lvdCIsImV4cCI6MTYzMzc2MDg0NCwiZW1haWwiOiIifQ',
|
||||
'id': 196,'username': '123'}}
|
||||
'id': 196, 'username': '123'}}
|
||||
# hp = {
|
||||
# "jsonpath": [
|
||||
#
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
import datetime
|
||||
import hashlib
|
||||
import random
|
||||
import time
|
||||
import re
|
||||
import time
|
||||
|
||||
|
||||
def choice_data(data):
|
||||
"""
|
||||
|
@ -127,13 +128,20 @@ def get_time(time_type, layout, unit="0,0,0,0,0"):
|
|||
|
||||
"""
|
||||
ti = datetime.datetime.now()
|
||||
if time_type != "now":
|
||||
if time_type == "future":
|
||||
resolution = unit.split(",")
|
||||
try:
|
||||
ti = ti + datetime.timedelta(seconds=int(resolution[0]), minutes=int(resolution[1]),
|
||||
hours=int(resolution[2]), days=int(resolution[3]), weeks=int(resolution[4]))
|
||||
except ValueError:
|
||||
raise Exception("获取时间错误,时间单位%s" % unit)
|
||||
elif time_type == "past":
|
||||
resolution = unit.split(",")
|
||||
try:
|
||||
ti = ti - datetime.timedelta(seconds=int(resolution[0]), minutes=int(resolution[1]),
|
||||
hours=int(resolution[2]), days=int(resolution[3]), weeks=int(resolution[4]))
|
||||
except ValueError:
|
||||
raise Exception("获取时间错误,时间单位%s" % unit)
|
||||
if layout == "10timestamp":
|
||||
ti = ti.strftime('%Y-%m-%d %H:%M:%S')
|
||||
ti = int(time.mktime(time.strptime(ti, "%Y-%m-%d %H:%M:%S")))
|
||||
|
@ -148,6 +156,7 @@ def get_time(time_type, layout, unit="0,0,0,0,0"):
|
|||
ti = ti.strftime(layout)
|
||||
return ti
|
||||
|
||||
|
||||
def replace_random(value):
|
||||
"""
|
||||
调用定义方法替换字符串
|
||||
|
@ -214,13 +223,15 @@ def replace_random(value):
|
|||
pass
|
||||
return value
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from scripts.readYamlFile import ini_yaml
|
||||
import json
|
||||
|
||||
int_num = "$RandomPosInt(1,333)$"
|
||||
str_num = '$RandomString($RandomPosInt(2,23)$)$'
|
||||
float_num = '$RandomFloat($RandomPosInt(2,13)$,$RandomPosInt(2,13)$,$RandomPosInt(2,13)$)$'
|
||||
time_num = '$GetTime(time_type=else,layout=%Y-%m-%d 00:00:00,unit=0,0,0,0,0)$'
|
||||
time_num = '$GetTime(time_type=else,layout=%Y-%m-%d %H:%M:%S,unit=0,0,0,0,0)$'
|
||||
choice_num = '$Choice($RandomPosInt(2,13)$,$RandomPosInt(2,13)$)$'
|
||||
a = json.dumps(ini_yaml("homePageData.yml")["companyAlarm"])
|
||||
# print(type(ini_yaml("家庭详情.yml")[0]["data"]))
|
||||
|
@ -228,5 +239,6 @@ if __name__ == '__main__':
|
|||
# print(replace_random(str_num))
|
||||
# print(replace_random(float_num))
|
||||
print(replace_random(time_num))
|
||||
t = "$GetTime(time_type=past,layout=%Y-%m-%d %H:%M:%S,unit=0,0,0,5,0)$"
|
||||
# print(replace_random(choice_num))
|
||||
print(replace_random(a))
|
||||
print(replace_random(t))
|
||||
|
|
|
@ -2,8 +2,12 @@
|
|||
import os
|
||||
|
||||
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 = []
|
||||
|
@ -16,18 +20,18 @@ def getFilePathList(path, filetype):
|
|||
|
||||
def write_case(_file):
|
||||
path = dir_manage(dir_manage('${pro_dir}$') + dir_manage('${test_suite}$') + dir_manage('${page_dir}$'))
|
||||
print(path)
|
||||
|
||||
with open(path + r"saasApp_pages_1.py", 'w+', encoding='utf-8') as f:
|
||||
f.write("""# coding:utf-8\nfrom test_suite.page import *\n\nurlData = ini_yaml("urlData.yml")\n\n""")
|
||||
yml_data = ini_yaml(_file)
|
||||
|
||||
for item in yml_data.items():
|
||||
print(item)
|
||||
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"]))
|
||||
|
|
Loading…
Reference in New Issue