Commit 0c918987 by lin

api test v_0.1

parent 470952b5
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/26 16:41
# Description:
#
# ---------------------------------------------------------------------------
import functools
import logging
import os
import time
log_path = os.path.join(os.path.join(os.path.join(os.path.dirname(__file__),"report"),"log"),time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())+".log")
def log_1(log_file):
"""创建日志"""
logger = logging.getLogger()
logger.setLevel("INFO")
handler = logging.FileHandler(log_file, mode="a", encoding="utf-8")
formatter = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
log_2 = log_1(log_path)
"""创建生成器"""
def log(func_name):
@functools.wraps(func_name)
def inner(*args, **kwargs):
try:
log_2.info(f"执行的功能为:{func_name.__name__},功能的描述为:{func_name.__doc__}, 所在的文件路径为:{func_name.__code__.co_filename}, 所做的行为:{func_name.__code__.co_firstlineno}" )
res = func_name(*args, **kwargs)
except Exception as e:
log_2.error(f"执行的功能为:{func_name.__name__},功能的描述为:{func_name.__doc__}, 所在的文件路径为:{func_name.__code__.co_filename}, 所做的行为:{func_name.__code__.co_firstlineno}, 错误的类型为:{type(e)}, 错误为:{e}")
raise e
else:
return res
return inner
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/26 16:42
# Description:
#
# ---------------------------------------------------------------------------
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: db.py
# Author: lin
# Datetime: 2024/12/26 19:17
# Description:
#
# ---------------------------------------------------------------------------
import pymysql
from APITest_1226 import log
from APITest_1226.common.read_basic_ini import ReadBasicIni
class DB:
@log
def __init__(self):
"""连接数据库"""
self.basic_ini = ReadBasicIni()
self.conn = pymysql.connect(
host=self.basic_ini.get_sql("host"),
port=int(self.basic_ini.get_sql("port")),
user=self.basic_ini.get_sql("user"),
password=self.basic_ini.get_sql("pwd"),
database=self.basic_ini.get_sql("database"),
charset="utf8"
)
self.cursor =self.conn.cursor()
@log
def close(self):
"""关闭数据库的连接"""
self.cursor.close()
self.conn.close()
@log
def delete(self,sql):
"""删除语句"""
self.cursor.execute(sql)
self.conn.commit()
@log
def select(self,sql):
"""选择语句"""
self.cursor.execute(sql)
sql_result = self.cursor.fetchall()
if sql_result:
return sql_result[0][0]
if __name__ == '__main__':
res = DB()
print(res.select("""SELECT `ID_` FROM uc_demension where `CODE_`= 'testAddDemf';"""))
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: read_basic_ini.py
# Author: lin
# Datetime: 2024/12/26 16:47
# Description:
#
# ---------------------------------------------------------------------------
import configparser
import os
from APITest_1226 import log
class ReadBasicIni:
@log
def __init__(self):
"""获取basicini的路径并读取"""
data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),"data_config")
basic_ini = os.path.join(data_config_path, "config.ini")
self.conf = configparser.ConfigParser()
self.conf.read(basic_ini,encoding="utf-8")
@log
def get_host(self,key):
"""获取配置项目的域名"""
return self.conf.get("host",key)
@log
def get_sql(self,key):
"""获取连接数据库的信息"""
return self.conf.get("sql",key)
@log
def get_user(self,key):
"""获取用户用例文件名称"""
return self.conf.get("user",key)
if __name__ == '__main__':
res = ReadBasicIni()
print(res.get_host("bpm"))
print(res.get_sql("host"))
print(res.get_user("lisi"))
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: read_excel.py
# Author: lin
# Datetime: 2024/12/26 19:42
# Description:
#
# ---------------------------------------------------------------------------
import openpyxl
from APITest_1226 import log
from APITest_1226.common.read_basic_ini import ReadBasicIni
from APITest_1226.common.read_json import read_json
from APITest_1226.common.read_user_ini import ReadUserIni
class ReadExcel:
@log
def __init__(self, username, ReadBasicInia=None):
"""获取excel工作簿、工作簿,获取json文件的数据"""
user_ini = ReadUserIni(username)
excel_path = user_ini.get_file_path("excel")
case_path = user_ini.get_file_path("case")
expect_path = user_ini.get_file_path("expect")
sql_path = user_ini.get_file_path("sql")
table_name = user_ini.get_table_name("name")
self.basic_ini =ReadBasicIni()
wb = openpyxl.load_workbook(excel_path)
self.ws = wb[table_name]
self.case_data = read_json(case_path)
self.expect_data = read_json(expect_path)
self.sql_data = read_json(sql_path)
@log
def __get_value(self,column,row):
"""获取单元格的数据,并去掉前后空格"""
cell = self.ws[column+str(row)].value
if isinstance(cell,str) and cell.strip():
return cell.strip()
@log
def module_name(self,row):
"""获取模块名称"""
return self.__get_value("b",row)
@log
def api_name(self, row):
"""获取接口名称"""
return self.__get_value("c", row)
@log
def case_url(self, row):
"""获取访问的url"""
url = self.__get_value("f", row)
if url:
return self.basic_ini.get_host("bpm") +url
@log
def case_mime(self,row):
"""获取媒体类型"""
mime = self.__get_value("g",row)
if mime:
return mime.lower()
@log
def case_req(self,row):
"""获取请求方式"""
return self.__get_value("h",row)
@log
def case_data1(self,row):
"""获取用例数据"""
key = self.__get_value("i",row)
module = self.module_name(row)
api = self.api_name(row)
if key:
return self.case_data[module][api][key]
@log
def expect_data1(self, row):
"""获取期望数据"""
key = self.__get_value("j", row)
module = self.module_name(row)
api = self.api_name(row)
if key:
return self.expect_data[module][api][key]
@log
def sql_data1(self, row):
"""获取sql数据"""
key = self.__get_value("l", row)
module = self.module_name(row)
api = self.api_name(row)
if key:
return self.sql_data[module][api][key]
@log
def sql_type(self,row):
"""获取sql语句类型"""
sql_type = self.__get_value("k",row)
if sql_type:
return sql_type.lower()
@log
def update_key(self, row):
"""获取更新的key"""
return self.__get_value("m", row)
@log
def case_dict(self):
"""将数据放在一个二维列表中"""
case_dict =[]
for row in range(2,self.ws.max_row +1):
url = self.case_url(row)
mime = self.case_mime(row)
req = self.case_req(row)
case = self.case_data1(row)
expect = self.expect_data1(row)
sql = self.sql_data1(row)
sql_type = self.sql_type(row)
update_key = self.update_key(row)
if url is not None and expect is not None and req is not None:
case_dict.append([url,mime,req,case,expect,sql,sql_type,update_key])
return case_dict
if __name__ == '__main__':
res = ReadExcel("lisi")
print(res.case_dict())
print(res.case_url(3))
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: read_json.py
# Author: lin
# Datetime: 2024/12/26 19:38
# Description:
#
# ---------------------------------------------------------------------------
import json
from APITest_1226 import log
@log
def read_json(json_path):
"""读json文件,并序列化为python对象"""
with open(json_path,mode="r",encoding="utf-8") as f:
return json.load(f)
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: read_user_ini.py
# Author: lin
# Datetime: 2024/12/26 19:01
# Description:
#
# ---------------------------------------------------------------------------
import configparser
import os
from APITest_1226 import log
from APITest_1226.common.read_basic_ini import ReadBasicIni
class ReadUserIni:
@log
def __init__(self,username):
"""获取userini文件的路径,并读取数据"""
basic_ini = ReadBasicIni()
user_name =basic_ini.get_user(username)
self.data_config_path = os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config"),user_name)
user_name_ini = os.path.join(self.data_config_path, "config.ini")
self.conf = configparser.ConfigParser()
self.conf.read(user_name_ini, encoding="utf-8")
@log
def get_file_path(self,key):
"""获取文件路径"""
file_name = self.conf.get("file",key)
return os.path.join(self.data_config_path,file_name)
@log
def get_table_name(self,key):
"""获取工作表的名字"""
return self.conf.get("table",key)
if __name__ == '__main__':
res = ReadUserIni("lisi")
# print(res.get_file_path("excel"))
print(res.get_table_name("name"))
\ No newline at end of file
[host]
# 配置项目的域名
bpm= http://36.139.193.99:8088
[sql]
# 数据库的连接信息
host=36.139.193.99
port=3306
user=root
pwd=Rhrc@2024
database=eip8
[user]
# 随着用户的增加而增加选项,配置的是数据的目录名称
lisi=lisi_data
zs=zhangsan_data
ww=wangwu_data
\ No newline at end of file
[file]
# 配置数据配置层中文件的名称
excel=接口测试.xlsx
case=用例.json
expect=期望.json
sql=sql语句.json
[table]
# excel工作表名称
name=认证接口
\ No newline at end of file
{
{
"维度管理": {
"添加维度": {
"AddDemSuccess": "delete from uc_demension where CODE_=\"test_dem\";"
},
"根据维度编码删除维度": {
"DeleteDemSuccess": "select ID_ from uc_demension where CODE_=\"test_dem\";"
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"select": "select ID_ from uc_demension where CODE_=\"test_dem\";",
"delete": "delete from uc_org where CODE_=\"test_org_code\";"
}
}
}
}
{
{
"认证接口": {
"登录系统": {
"LoginSuccess": {"username":"超级管理员","account":"admin","userId":"1","expiration":86400},
"LoginErrorUsernameIsNone": {"message": "账户错误或该租户未启用"},
"LoginErrorUsernameIsShort": {"message": "账户错误或该租户未启用"},
"LoginErrorUsernameIsLong": {"message": "账户错误或该租户未启用"},
"LoginErrorUsernameIsSpecial": {"message": "账户错误或该租户未启用"},
"LoginErrorUsernameIsError": {"message": "账户错误或该租户未启用"},
"LoginErrorPwdIsNone": {"message": "账号或密码错误"},
"LoginErrorPwdIsShort": {"message": "账号或密码错误"},
"LoginErrorPwdIsSpecial":{"message": "账号或密码错误"},
"LoginErrorPwdIsLong":{"message": "账号或密码错误"}
},
"刷新token": {
"RefreshSuccess": {
"message": "刷新成功"
}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"message": "添加维度成功!"
}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {
"message": "删除维度成功!"
}
},
"更新维度": {
"PutDemSuccess": {
"message": "更新维度成功!"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"message": "添加组织成功"
}
},
"组织加入用户": {
"UserJoinOrgSuccess": {"message":"加入成功"}
},
"保存组织参数": {
"SaveOrgParamSuccess": {"message":"保存组织参数成功!"}
},
"删除组织": {
"DeleteOrgSuccess": {"message":"删除组织成功!"}
}
}
}
{
{
"认证接口": {
"登录系统": {
"LoginSuccess": {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsNone": {
"username": "",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsShort": {
"username": "a",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsLong": {
"username": "adminadminadminadminadminadminadmin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsSpecial": {
"username": "▣▤▥▦▩◘◙",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsError": {
"username": "Admin123",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorPwdIsNone": {
"username": "admin",
"password": ""
},
"LoginErrorPwdIsShort": {
"username": "admin",
"password": "1"
},
"LoginErrorPwdIsSpecial": {
"username": "admin",
"password": "▣▤▥▦▩◘◙"
},
"LoginErrorPwdIsLong": {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I=WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"code": "test_dem",
"description": "测试添加的维度",
"isDefault": 1,
"name": "测试维度"
}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {
"ids": "需要更新"
}
},
"更新维度": {
"PutDemSuccess": {
"code": "test_dem",
"description": "测试添加的维度",
"isDefault": 1,
"name": "测试维度-更新"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"code": "test_org_code",
"demId": "需要更新",
"exceedLimitNum": 0,
"grade": "",
"limitNum": 0,
"name": "测试组织",
"nowNum": 0,
"orderNo": 0,
"parentId": "0"
}
},
"组织加入用户": {
"UserJoinOrgSuccess": {"orgCode": "test_org_code", "accounts": "admin"}
},
"保存组织参数": {
"SaveOrgParamSuccess": {
"query": {"orgCode": "test_org_code"},
"json": [{"alias":"sz","value":100000}]
}
},
"删除组织": {
"DeleteOrgSuccess": "test_org_code"
}
}
}
{
"认证接口": {
"登录系统": {
"LoginSuccess": {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsNone": {
"username": "",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsShort": {
"username": "a",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsLong": {
"username": "adminadminadminadminadminadminadmin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsSpecial": {
"username": "▣▤▥▦▩◘◙",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsError": {
"username": "Admin123",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorPwdIsNone": {
"username": "admin",
"password": ""
},
"LoginErrorPwdIsShort": {
"username": "admin",
"password": "1"
},
"LoginErrorPwdIsSpecial": {
"username": "admin",
"password": "▣▤▥▦▩◘◙"
},
"LoginErrorPwdIsLong": {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I=WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"code": "test_dem",
"description": "测试添加的维度",
"isDefault": 1,
"name": "测试维度"
}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {
"ids": "需要更新"
}
},
"更新维度": {
"PutDemSuccess": {
"code": "test_dem",
"description": "测试添加的维度",
"isDefault": 1,
"name": "测试维度-更新"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"code": "test_org_code",
"demId": "需要更新",
"exceedLimitNum": 0,
"grade": "",
"limitNum": 0,
"name": "测试组织",
"nowNum": 0,
"orderNo": 0,
"parentId": "0"
}
},
"组织加入用户": {
"UserJoinOrgSuccess": {"orgCode": "test_org_code", "accounts": "admin"}
},
"保存组织参数": {
"SaveOrgParamSuccess": {
"query": {"orgCode": "test_org_code"},
"json": [{"alias":"sz","value":100000}]
}
},
"删除组织": {
"DeleteOrgSuccess": "test_org_code"
}
}
}
[file]
# 配置数据配置层中文件的名称
excel=apiAutoTest.xlsx
case=case_data.json
expect=expect_data.json
sql=sql_data.json
[table]
# excel工作表名称
name=BPM
{
"认证接口": {
"登录系统": {
"LoginSuccess": {
"username": "超级管理员",
"account": "admin",
"userId": "1",
"expiration": 86400
},
"LoginErrorUsernameIsNone": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsShort": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsLong": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsSpecial": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsError": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsNone": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsShort": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsSpecial": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsLong": {
"message": "账号或密码错误"
}
},
"刷新token": {
"RefreshSuccess": {
"message": "刷新成功"
}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"message": "添加维度成功!"
}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {
"message": "删除维度成功!"
}
},
"更新维度": {
"PutDemSuccess": {
"message": "更新维度成功!"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"message": "添加组织成功"
}
},
"组织加入用户": {
"UserJoinOrgSuccess": {"message":"加入成功"}
},
"保存组织参数": {
"SaveOrgParamSuccess": {"message":"保存组织参数成功!"}
},
"删除组织": {
"DeleteOrgSuccess": {"message":"删除组织成功!"}
}
}
}
{
"维度管理": {
"添加维度": {
"AddDemSuccess": "delete from uc_demension where CODE_=\"test_dem\";"
},
"根据维度编码删除维度": {
"DeleteDemSuccess": "select ID_ from uc_demension where CODE_=\"test_dem\";"
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"select": "select ID_ from uc_demension where CODE_=\"test_dem\";",
"delete": "delete from uc_org where CODE_=\"test_org_code\";"
}
}
}
}
{
"认证接口": {
"登录系统": {
"LoginSuccess": {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsNone": {
"username": "",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsShort": {
"username": "a",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsLong": {
"username": "adminadminadminadminadminadminadmin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsSpecial": {
"username": "▣▤▥▦▩◘◙",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorUsernameIsError": {
"username": "Admin123",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
},
"LoginErrorPwdIsNone": {
"username": "admin",
"password": ""
},
"LoginErrorPwdIsShort": {
"username": "admin",
"password": "1"
},
"LoginErrorPwdIsSpecial": {
"username": "admin",
"password": "▣▤▥▦▩◘◙"
},
"LoginErrorPwdIsLong": {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I=WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"code": "test_dem",
"description": "测试添加的维度",
"isDefault": 1,
"name": "测试维度"
}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {
"ids": "需要更新"
}
},
"更新维度": {
"PutDemSuccess": {
"code": "test_dem",
"description": "测试添加的维度",
"isDefault": 1,
"name": "测试维度-更新"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"code": "test_org_code",
"demId": "需要更新",
"exceedLimitNum": 0,
"grade": "",
"limitNum": 0,
"name": "测试组织",
"nowNum": 0,
"orderNo": 0,
"parentId": "0"
}
},
"组织加入用户": {
"UserJoinOrgSuccess": {"orgCode": "test_org_code", "accounts": "admin"}
},
"保存组织参数": {
"SaveOrgParamSuccess": {
"query": {"orgCode": "test_org_code"},
"json": [{"alias":"sz","value":100000}]
}
},
"删除组织": {
"DeleteOrgSuccess": "test_org_code"
}
}
}
[file]
# 配置数据配置层中文件的名称
excel=apiAutoTest.xlsx
case=case_data.json
expect=expect_data.json
sql=sql_data.json
[table]
# excel工作表名称
name=BPM
{
"认证接口": {
"登录系统": {
"LoginSuccess": {
"username": "超级管理员",
"account": "admin",
"userId": "1",
"expiration": 86400
},
"LoginErrorUsernameIsNone": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsShort": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsLong": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsSpecial": {
"message": "账号或密码错误"
},
"LoginErrorUsernameIsError": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsNone": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsShort": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsSpecial": {
"message": "账号或密码错误"
},
"LoginErrorPwdIsLong": {
"message": "账号或密码错误"
}
},
"刷新token": {
"RefreshSuccess": {
"message": "刷新成功"
}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"message": "添加维度成功!"
}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {
"message": "删除维度成功!"
}
},
"更新维度": {
"PutDemSuccess": {
"message": "更新维度成功!"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"message": "添加组织成功"
}
},
"组织加入用户": {
"UserJoinOrgSuccess": {"message":"加入成功"}
},
"保存组织参数": {
"SaveOrgParamSuccess": {"message":"保存组织参数成功!"}
},
"删除组织": {
"DeleteOrgSuccess": {"message":"删除组织成功!"}
}
}
}
{
"维度管理": {
"添加维度": {
"AddDemSuccess": "delete from uc_demension where CODE_=\"test_dem\";"
},
"根据维度编码删除维度": {
"DeleteDemSuccess": "select ID_ from uc_demension where CODE_=\"test_dem\";"
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"select": "select ID_ from uc_demension where CODE_=\"test_dem\";",
"delete": "delete from uc_org where CODE_=\"test_org_code\";"
}
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/26 16:42
# Description:
#
# ---------------------------------------------------------------------------
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: request_method.py
# Author: lin
# Datetime: 2024/12/26 20:29
# Description:
#
# ---------------------------------------------------------------------------
import requests
from APITest_1226 import log
from APITest_1226.common.db import DB
from APITest_1226.common.read_basic_ini import ReadBasicIni
class RequestMethod:
@log
def __init__(self):
"""关联token"""
ini = ReadBasicIni()
login_url = ini.get_host("bpm") + "/auth"
self.req_1 = requests.sessions.Session()
login_data = {
"username": "admin",
"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="
}
token = self.req_1.post(url=login_url,json=login_data).json().get("token")
self.req_1.headers["Authorization"] = "Bearer "+token
self.db = DB()
@log
def close(self):
self.db.close()
@log
def req_all(self, req_url, req_mime, req_req, req_case,sql_type, sql_data, update_key):
"""先删除存在的数据、查询需要的数据"""
if sql_type == "delete":
self.db.delete(sql_data)
elif sql_type == "select":
res =self.db.select(sql_data)
req_case[update_key] =res
elif sql_type == "delete|select" or sql_type== "select|delete":
self.db.delete(sql_data["delete"])
res = self.db.select(sql_data["select"])
req_case[update_key] = res
if req_mime == "application/json" or req_mime == "json":
return self.req_1.request(method=req_req,url=req_url,json=req_case)
elif req_mime == "application/x-www-form-urlencoded" or req_mime == "form":
return self.req_1.request(url=req_url, method=req_req, data=req_case)
elif req_mime == "multipart/form-data" or req_mime == "form-data":
return self.req_1.request(url=req_url, method=req_req, files=req_case)
elif req_mime == "query":
return self.req_1.request(url=req_url, method=req_req, params=req_case)
elif req_mime is None:
return self.req_1.request(url=req_url, method=req_req)
else:
raise ValueError(f"传入的媒体类型有误:媒体类型为{req_mime}")
if __name__ == '__main__':
res = RequestMethod()
url = "http://36.139.193.99:8088/auth"
mime = "application/json"
req = "POST"
case = {"password": "WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I=","username": "admin"}
expect = {'account': 'admin', 'expiration': 86400, 'userId': '1', 'username': '超级管理员'}
sql = "None"
type_sql ="None"
update_key = "None"
res_1=res.req_all(req_url=url,req_mime=mime,req_req=req,req_case=case,sql_type=type_sql, sql_data=sql, update_key=update_key)
print(res_1.json())
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/26 16:42
# Description:
#
# ---------------------------------------------------------------------------
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test64
# FileName: conftest.py
# Author: lao_zhao
# Datetime: 2024/12/27 11:48
# Description:
#
# ---------------------------------------------------------------------------
"""直接复制,不要做任何改动,必须放在用例层目录下的conftest.py文件类"""
def pytest_collection_modifyitems(items):
# item表示每个测试用例,解决用例名称中文显示问题
for item in items:
item.name = item.name.encode("utf-8").decode("unicode-escape")
item._nodeid = item._nodeid.encode("utf-8").decode("unicode-escape")
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/27 09:35
# Description:
#
# ---------------------------------------------------------------------------
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: conftest.py
# Author: lin
# Datetime: 2024/12/27 09:48
# Description:
#
# ---------------------------------------------------------------------------
import pytest
from APITest_1226 import log
from APITest_1226.request_method.request_method import RequestMethod
@log
@pytest.fixture(scope="session")
def req2_fix():
req_2 = RequestMethod()
yield req_2
req_2.close()
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: test_case.py
# Author: lin
# Datetime: 2024/12/27 09:38
# Description:
#
# ---------------------------------------------------------------------------
from APITest_1226 import log
from APITest_1226.common.read_excel import ReadExcel
import pytest
dict_case = ReadExcel("lisi").case_dict()
class TestBpm:
@log
@pytest.mark.parametrize("url,mime,req,case,expect,sql,sql_type,update_key",dict_case)
def test_bpm(self,req2_fix,url,mime,req,case,expect,sql,sql_type,update_key):
res = req2_fix.req_all(req_url=url, req_mime=mime, req_req=req, req_case=case,sql_type=sql_type, sql_data=sql, update_key=update_key)
for key in expect:
assert res.json().get(key) ==expect[key]
if __name__ == '__main__':
res =TestBpm()
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/27 09:35
# Description:
#
# ---------------------------------------------------------------------------
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: conftest.py
# Author: lin
# Datetime: 2024/12/27 09:48
# Description:
#
# ---------------------------------------------------------------------------
import pytest
from APITest_1226 import log
from APITest_1226.request_method.request_method import RequestMethod
@log
@pytest.fixture(scope="session")
def req2_fix():
req_2 = RequestMethod()
yield req_2
req_2.close()
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: test_case.py
# Author: lin
# Datetime: 2024/12/27 09:38
# Description:
#
# ---------------------------------------------------------------------------
from APITest_1226 import log
from APITest_1226.common.read_excel import ReadExcel
import pytest
dict_case = ReadExcel("ww").case_dict()
class TestBpm:
@log
@pytest.mark.parametrize("url,mime,req,case,expect,sql,sql_type,update_key",dict_case)
def test_bpm(self,req2_fix,url,mime,req,case,expect,sql,sql_type,update_key):
res = req2_fix.req_all(req_url=url, req_mime=mime, req_req=req, req_case=case,sql_type=sql_type, sql_data=sql, update_key=update_key)
for key in expect:
assert res.json().get(key) ==expect[key]
if __name__ == '__main__':
res =TestBpm()
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: __init__.py
# Author: lin
# Datetime: 2024/12/27 09:35
# Description:
#
# ---------------------------------------------------------------------------
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: conftest.py
# Author: lin
# Datetime: 2024/12/27 09:48
# Description:
#
# ---------------------------------------------------------------------------
import pytest
from APITest_1226 import log
from APITest_1226.request_method.request_method import RequestMethod
@log
@pytest.fixture(scope="session")
def req2_fix():
req_2 = RequestMethod()
yield req_2
req_2.close()
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test
# FileName: test_case.py
# Author: lin
# Datetime: 2024/12/27 09:38
# Description:
#
# ---------------------------------------------------------------------------
from APITest_1226 import log
from APITest_1226.common.read_excel import ReadExcel
import pytest
dict_case = ReadExcel("zs").case_dict()
class TestBpm:
@log
@pytest.mark.parametrize("url,mime,req,case,expect,sql,sql_type,update_key",dict_case)
def test_bpm(self,req2_fix,url,mime,req,case,expect,sql,sql_type,update_key):
res = req2_fix.req_all(req_url=url, req_mime=mime, req_req=req, req_case=case,sql_type=sql_type, sql_data=sql, update_key=update_key)
for key in expect:
assert res.json().get(key) ==expect[key]
if __name__ == '__main__':
res =TestBpm()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment