Commit 08f82404 by why13350291551

接口自动化框架v1.0

parent 67bb96fe
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 上午9:12
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import logging
import os
import time
# 配置日志文件信息
def log(name="why"):
# 创建logger对象
logger = logging.getLogger(name)
# 设置log级别
logger.level = logging.INFO
# 设置写入日志的文件
log_name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+".log"
log_dir_path = os.path.join(os.path.join(os.path.dirname(__file__), "report"), "log")
log_path = os.path.join(log_dir_path, log_name)
handle = logging.FileHandler(log_path, mode="a", encoding="utf-8")
# 设置日志的显示格式
formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s -- %(name)s')
# 设置日志文件中的日志格式
handle.setFormatter(formatter)
# 给logger对象添加日志文件
logger.addHandler(handle)
# 返回logger对象
return logger
# 先执行一次log函数,获取函数返回值,之后就直接使用返回值写入日志
log = log()
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 上午9:12
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: db.py
# Author: why
# Datetime: 2024/9/7 上午10:07
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import pymysql
from apiAutoTest_v4 import log
from apiAutoTest_v4.common.read_project_ini import ReadProjectIni
class DB:
def __init__(self):
"""链接数据库,创建链接对象、游标对象"""
# 创建ReadProjectIni对象,获取数据库连接信息
pro_ini = ReadProjectIni()
self.conn = pymysql.connect(
host=pro_ini.get_sql_connect_msg("host"),
port=int(pro_ini.get_sql_connect_msg("port")),
user=pro_ini.get_sql_connect_msg("user"),
password=pro_ini.get_sql_connect_msg("password"),
database=pro_ini.get_sql_connect_msg("database"),
charset="utf8"
)
self.cursor = self.conn.cursor()
def delete(self, sql_st):
"""使用db类对象,执行删除的sql语句"""
# 判断输入的sql语句是否为字符串格式
if isinstance(sql_st, str):
# 判断sql语句是否以delete开头和;结尾:
if sql_st.strip().lower().startswith("delete") and sql_st.strip().lower().endswith(";"):
try:
# 执行sql语句
self.cursor.execute(sql_st)
self.conn.commit()
except Exception as e:
log.error(f"执行删除的sql语句{sql_st}失败,错误为{e}")
raise e
else:
log.error(f"删除的sql语句{sql_st}格式错误")
raise ValueError("sql语句错误")
else:
log.error(f"传入的sql语句{sql_st}不为字符串")
raise ValueError("请传入字符串格式的sql语句!")
def select(self, sql_st, n=0):
"""使用db类对象,执行查询的sql语句"""
# 判断输入的sql语句是否为字符串格式
if isinstance(sql_st, str):
# 判断sql语句是否以select开头和;结尾:
if sql_st.strip().lower().startswith("select") and sql_st.strip().lower().endswith(";"):
try:
# 执行sql语句
self.cursor.execute(sql_st)
except Exception as e:
log.error(f"执行查询的sql语句{sql_st}失败,错误为{e}")
raise e
else:
select_res = self.cursor.fetchall()
# 判断传入n是否为整数且查询结果是否为空,满足条件则返回查询值,不满足返回默认值None
if isinstance(n, int) and select_res:
try:
return select_res[n][0]
except Exception as e:
log.error(f"执行select方法查询结果失败,传入sql语句为{sql_st},传入形参n为{n},错误为{e}")
raise e
else:
log.error(f"查询的sql语句{sql_st}格式错误")
raise ValueError("sql语句错误")
else:
log.error(f"传入的sql语句{sql_st}不为字符串")
raise ValueError("请传入字符串格式的sql语句!")
def __del__(self):
self.cursor.close()
self.conn.close()
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: read_excel.py
# Author: why
# Datetime: 2024/9/7 上午10:35
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import openpyxl
from apiAutoTest_v4 import log
from apiAutoTest_v4.common.read_json import read_json
from apiAutoTest_v4.common.read_project_ini import ReadProjectIni
from apiAutoTest_v4.common.read_user_ini import ReadUserIni
from apiAutoTest_v4.data_config.settings import *
class ReadExcel:
def __init__(self, user_dir_name):
"""获取所有json文件路径并读取,创建excel对象,获取excel文件路径,加载工作簿,获取工作表"""
# 创建ReadUserIni对象,调用get_file_path方法获取文件路径
user_ini = ReadUserIni(user_dir_name)
# 获取json文件路径
case_path = user_ini.get_file_path(FILE_CASE)
expect_path = user_ini.get_file_path(FILE_EXPECT)
sql_path = user_ini.get_file_path(FILE_SQL)
# 读取json文件
self.case_dict = read_json(case_path)
self.expect_dict = read_json(expect_path)
self.sql_dict = read_json(sql_path)
# 获取excel路径和工作表名
excel_path = user_ini.get_file_path(FILE_EXCEL)
table_name = user_ini.get_table_name(TABLE_kEY)
# 创建excel对象,加载工作簿,获取工作表
try:
wb = openpyxl.load_workbook(excel_path)
self.ws = wb[table_name]
except Exception as e:
log.error(f"加载工作簿或获取工作表错误,传入excel路径为{excel_path},工作表名称为{table_name},错误为{e}")
raise e
# 创建ReadProjectIni对象,方便后续调用get_host方法
self.pro_ini = ReadProjectIni()
def __get_cell_value(self, column, row):
"""根据列号行号获取每个单元格的数据"""
try:
cell_value = self.ws[column+str(row)].value
except Exception as e:
log.error(f"获取单元格数据时产生错误,传入列号{column}、行号{row},错误为{e}")
raise e
else:
# 判断单元格数据是否为空,如为空返回默认值None,不为空则去掉空格后返回
if cell_value is None:
return None
elif cell_value.strip():
return cell_value.strip()
def module_name(self, row):
"""根据行号获取模块名"""
return self.__get_cell_value(MODULE, row)
def api_name(self, row):
"""根据行号获取接口名"""
return self.__get_cell_value(API, row)
def case_url(self, row):
"""根据行号,获取用例数据的url"""
path = self.__get_cell_value(URL, row)
# 判断path是否为空,不为空则与host拼接,返回完整的url
if path:
return self.pro_ini.get_host(HOST_KEY) + path
def case_req_method(self, row):
"""根据行号获取请求方法"""
return self.__get_cell_value(REQ_METHOD, row)
def case_mime(self, row):
"""根据行号获取请求媒体类型"""
mime = self.__get_cell_value(MIME, row)
if mime:
return mime.lower()
def case_data(self, row):
"""根据行号获取用例数据的key,再根据用例数据的key获取用例json文件中的数据"""
case_data_key = self.__get_cell_value(CASE_DATA, row)
# 根据用例数据的key,获取json文件中的用例数据
if case_data_key:
module_name = self.module_name(row)
api_name = self.api_name(row)
return self.case_dict[module_name][api_name][case_data_key]
def expect_data(self, row):
"""根据行号获取期望数据的key,再根据期望数据的key获取期望json文件中的数据"""
expect_data_key = self.__get_cell_value(EXPECT_DATA, row)
# 根据期望数据的key,获取json文件中的期望数据
if expect_data_key:
module_name = self.module_name(row)
api_name = self.api_name(row)
return self.expect_dict[module_name][api_name][expect_data_key]
def sql_data(self, row):
"""根据行号获取sql数据的key,再根据sql数据的key获取sql数据json文件中的数据"""
sql_data_key = self.__get_cell_value(SQL_DATA, row)
# 根据sql数据的key,获取json文件中的sql数据
if sql_data_key:
module_name = self.module_name(row)
api_name = self.api_name(row)
return self.sql_dict[module_name][api_name][sql_data_key]
def sql_type(self, row):
"""根据行号获取sql语句类型"""
sql_type = self.__get_cell_value(SQL_TYPE, row)
if sql_type:
return sql_type.lower()
def update_key(self, row):
"""根据行号获取要更新的key"""
return self.__get_cell_value(UPDATE_KEY, row)
def case_title(self, row):
"""根据行号获取用例数据标题"""
return self.__get_cell_value(TITLE, row)
def case_level(self, row):
"""根据行号获取用例等级"""
return self.__get_cell_value(LEVEL, row)
def get_data(self):
"""获取所有数据,并存放在一个二维列表中"""
# 创建一个空列表,存放所有数据
list_data = []
# 循环所有行,获取每行的用例数据
for row in range(2, self.ws.max_row+1):
module_name = self.module_name(row)
api_name = self.api_name(row)
title = self.case_title(row)
level = self.case_level(row)
url = self.case_url(row)
method = self.case_req_method(row)
mime = self.case_mime(row)
case_data = self.case_data(row)
expect_data = self.expect_data(row)
sql_type = self.sql_type(row)
sql_data = self.sql_data(row)
update_key = self.update_key(row)
# 过滤空行:如果url、请求方法、期望数据不为空,则该用例不为空?
if url is not None and method is not None and expect_data is not None:
list_data.append([module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key])
else:
return list_data
if __name__ == '__main__':
excel = ReadExcel("demo")
print(excel.get_data())
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: read_json.py
# Author: why
# Datetime: 2024/9/7 上午10:00
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import json
from apiAutoTest_v4 import log
def read_json(file_path):
"""根据json文件路径读取json文件"""
# 先判断传入路径是否为字符串,再把json文件序列化为python对象
if isinstance(file_path, str):
try:
with open(file_path, mode="r", encoding="utf-8") as f:
return json.load(f)
except Exception as e:
log.error(f"读取json文件错误,错误原因可能是文件路径不存在,也可能是文件数据格式错误,传入路径为{file_path},错误为{e}")
raise e
else:
log.error(f"传入json文件路径不为字符串,传入路径为{file_path}")
raise ValueError("传入文件路径必须为字符串!")
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: read_project_ini.py
# Author: why
# Datetime: 2024/9/7 上午9:21
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import configparser
import os
from apiAutoTest_v4 import log
class ReadProjectIni:
def __init__(self):
"""获取ini文件路径并读取"""
data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
project_ini_path = os.path.join(data_config_path, "project_config.ini")
self.conf = configparser.ConfigParser()
self.conf.read(project_ini_path, encoding="utf-8")
def get_host(self, key):
"""根据key获取host节点下被测系统的域名"""
try:
return self.conf.get("host", key)
except Exception as e:
log.error(f"使用方法get_host错误,形参传入key为{key},错误为{e}")
raise e
def get_sql_connect_msg(self, key):
"""根据key获取sql节点下数据库连接信息"""
try:
return self.conf.get("sql", key)
except Exception as e:
log.error(f"使用方法get_sql_connect_msg错误,形参传入key为{key},错误为{e}")
raise e
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: read_user_ini.py
# Author: why
# Datetime: 2024/9/7 上午9:48
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import configparser
import os
from apiAutoTest_v4 import log
class ReadUserIni:
def __init__(self, user_dir_name):
"""获取ini文件路径,并读取"""
# 获取数据配置层的目录路径
data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
# 获取存放用户数据的路径
self.user_data_path = os.path.join(data_config_path, user_dir_name)
# 拼接用户的ini文件路径
self.user_ini_path = os.path.join(self.user_data_path, "config.ini")
# 创建configparser对象,并读取ini文件
self.conf = configparser.ConfigParser()
self.conf.read(self.user_ini_path, encoding="utf-8")
def get_file_path(self, key):
"""获取file节点下各个key对应的文件路径"""
try:
log.info(f"开始执行get_file_path方法,传入形参key为{key}")
file_name = self.conf.get("file", key)
except Exception as e:
log.error(f"执行get_file_path方法错误,传入形参key为{key},错误为{e}")
raise e
else:
# 完成文件路径的拼接
return os.path.join(self.user_data_path, file_name)
def get_table_name(self, key):
"""获取table节点下工作表名称"""
try:
return self.conf.get("table", key)
except Exception as e:
log.error(f"执行get_table_name方法错误,传入形参key为{key},错误为{e}")
raise e
if __name__ == '__main__':
ini = ReadUserIni("demo")
# D:\Project\PythonDoc\test62\test62\apiAutoTest_v3\data_config\demo\apiAutoTest.xlsx
# D:\Project\PythonDoc\test62\test62\apiAutoTest_v3\data_config\demo\apiAutoTest.xlsx
print(ini.get_file_path("excel"))
\ No newline at end of file
[file]
# 配置数据配置层中文件的名称
excel=bright.xlsx
case=用例数据.json
expect=期望数据.json
sql=sql语句.json
[table]
# 配置工作表名称
table_name=BPM
{
{
"维度管理": {
"添加维度": {
"AddDemSuccess": {"delete": "dELETE FROM uc_demension WHERE `CODE_`=\"requestsAddDem\";"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"select": "select ID_ from uc_demension where CODE_=\"requestsAddDem\";"}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"select": "select ID_ from uc_demension where CODE_=\"requestsAddDem\"; ",
"delete": "delete from uc_org where CODE_=\"testAddOrg\";"
}
}
}
}
{
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username":"超级管理员","account":"admin","userId":"1","expiration":86400,"loginStatus":true},
"LoginErrorUsernameIsNone": {"message":"账号或密码错误"},
"LoginErrorUsernameIsSpecialChar": {"message":"账号或密码错误"},
"LoginErrorUsernameIsLong": {"message":"账号或密码错误"},
"LoginErrorUsernameIsShort": {"message":"账号或密码错误"},
"LoginErrorUsernameIsError": {"message":"账号或密码错误"},
"LoginErrorPasswordIsNone":{"message":"账号或密码错误"},
"LoginErrorPasswordIsSpecialChar": {"message":"账号或密码错误"},
"LoginErrorPasswordIsLong": {"message":"账号或密码错误"},
"LoginErrorPasswordIsShort": {"message":"账号或密码错误"},
"LoginErrorPasswordIsError":{"message":"账号或密码错误"}
},
"刷新token": {
"RefreshSuccess": {"message": "刷新token成功"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"message": "添加维度成功"}
},
"根据维度编码获取维度信息": {
"GetDemMessageSuccess": {"isDelete": "0"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"message": "删除维度成功!"}
},
"更新维度": {
"UpdateDemSuccess": {"message": "更新维度成功"}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {"message": "添加组织成功"}
},
"用户加入组织": {
"OrgAddUserSuccess": {"message":"加入成功"}
},
"保存组织参数": {
"SaveOrgparamsSuccess": {"message":"保存组织参数成功!"}
},
"删除组织": {
"DeleteOrgSuccess": {"message":"删除组织成功!"}
}
}
}
{
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsNone": {"username": "","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsSpecialChar": {"username": "#!$!@#!@#","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsLong": {"username": "adminadminadminadminadminadminadminadminadmin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsShort": {"username": "a","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsError": {"username": "adminxyz","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorPasswordIsNone": {"username": "admin","password": ""},
"LoginErrorPasswordIsSpecialChar": {"username": "admin","password": "#!$!@#!@#"},
"LoginErrorPasswordIsLong": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn"},
"LoginErrorPasswordIsShort": {"username": "admin","password": "123456"},
"LoginErrorPasswordIsError": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"code": "requestsAddDem","description": "requestsAddDem","isDefault": 1,"name": "requests添加的维度"}
},
"根据维度编码获取维度信息": {
"GetDemMessageSuccess": {"code": "requestsAddDem"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"ids": "需要更新"}
},
"更新维度": {
"UpdateDemSuccess": {
"code": "requestsAddDem",
"description": "requestsAddDem",
"isDefault": 0,
"name": "requestsAddDem"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"code": "testAddOrg",
"demId": "需要更新",
"exceedLimitNum": 0,
"grade": "",
"limitNum": 0,
"name": "测试添加的组织",
"nowNum": 0,
"orderNo": 0,
"parentId": "0"
}
},
"用户加入组织": {
"OrgAddUserSuccess": {"orgCode": "testAddOrg", "accounts": "admin,guest"}
},
"保存组织参数": {
"SaveOrgparamsSuccess": {
"query": {"orgCode": "testAddOrg"},
"body": [{"alias": "hxxmts", "value": "项目中没有关系户"}]
}
},
"删除组织": {
"DeleteOrgSuccess": "testAddOrg"
}
}
}
[file]
# 配置数据配置层中文件的名称
excel=dark.xlsx
case=用例数据.json
expect=期望数据.json
sql=sql语句.json
[table]
# 配置工作表名称
table_name=BPM
{
{
"维度管理": {
"添加维度": {
"AddDemSuccess": {"delete": "dELETE FROM uc_demension WHERE `CODE_`=\"requestsAddDem\";"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"select": "select ID_ from uc_demension where CODE_=\"requestsAddDem\";"}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"select": "select ID_ from uc_demension where CODE_=\"requestsAddDem\"; ",
"delete": "delete from uc_org where CODE_=\"testAddOrg\";"
}
}
}
}
{
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username":"超级管理员","account":"admin","userId":"1","expiration":86400,"loginStatus":true},
"LoginErrorUsernameIsNone": {"message":"账号或密码错误"},
"LoginErrorUsernameIsSpecialChar": {"message":"账号或密码错误"},
"LoginErrorUsernameIsLong": {"message":"账号或密码错误"},
"LoginErrorUsernameIsShort": {"message":"账号或密码错误"},
"LoginErrorUsernameIsError": {"message":"账号或密码错误"},
"LoginErrorPasswordIsNone":{"message":"账号或密码错误"},
"LoginErrorPasswordIsSpecialChar": {"message":"账号或密码错误"},
"LoginErrorPasswordIsLong": {"message":"账号或密码错误"},
"LoginErrorPasswordIsShort": {"message":"账号或密码错误"},
"LoginErrorPasswordIsError":{"message":"账号或密码错误"}
},
"刷新token": {
"RefreshSuccess": {"message": "刷新token成功"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"message": "添加维度成功"}
},
"根据维度编码获取维度信息": {
"GetDemMessageSuccess": {"isDelete": "0"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"message": "删除维度成功!"}
},
"更新维度": {
"UpdateDemSuccess": {"message": "更新维度成功"}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {"message": "添加组织成功"}
},
"用户加入组织": {
"OrgAddUserSuccess": {"message":"加入成功"}
},
"保存组织参数": {
"SaveOrgparamsSuccess": {"message":"保存组织参数成功!"}
},
"删除组织": {
"DeleteOrgSuccess": {"message":"删除组织成功!"}
}
}
}
{
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsNone": {"username": "","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsSpecialChar": {"username": "#!$!@#!@#","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsLong": {"username": "adminadminadminadminadminadminadminadminadmin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsShort": {"username": "a","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsError": {"username": "adminxyz","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorPasswordIsNone": {"username": "admin","password": ""},
"LoginErrorPasswordIsSpecialChar": {"username": "admin","password": "#!$!@#!@#"},
"LoginErrorPasswordIsLong": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn"},
"LoginErrorPasswordIsShort": {"username": "admin","password": "123456"},
"LoginErrorPasswordIsError": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"code": "requestsAddDem","description": "requestsAddDem","isDefault": 1,"name": "requests添加的维度"}
},
"根据维度编码获取维度信息": {
"GetDemMessageSuccess": {"code": "requestsAddDem"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"ids": "需要更新"}
},
"更新维度": {
"UpdateDemSuccess": {
"code": "requestsAddDem",
"description": "requestsAddDem",
"isDefault": 0,
"name": "requestsAddDem"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"code": "testAddOrg",
"demId": "需要更新",
"exceedLimitNum": 0,
"grade": "",
"limitNum": 0,
"name": "测试添加的组织",
"nowNum": 0,
"orderNo": 0,
"parentId": "0"
}
},
"用户加入组织": {
"OrgAddUserSuccess": {"orgCode": "testAddOrg", "accounts": "admin,guest"}
},
"保存组织参数": {
"SaveOrgparamsSuccess": {
"query": {"orgCode": "testAddOrg"},
"body": [{"alias": "hxxmts", "value": "项目中没有关系户"}]
}
},
"删除组织": {
"DeleteOrgSuccess": "testAddOrg"
}
}
}
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsNone": {"username": "","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsSpecialChar": {"username": "#!$!@#!@#","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsLong": {"username": "adminadminadminadminadminadminadminadminadmin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsShort": {"username": "a","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorUsernameIsError": {"username": "adminxyz","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="},
"LoginErrorPasswordIsNone": {"username": "admin","password": ""},
"LoginErrorPasswordIsSpecialChar": {"username": "admin","password": "#!$!@#!@#"},
"LoginErrorPasswordIsLong": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jznbF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn"},
"LoginErrorPasswordIsShort": {"username": "admin","password": "123456"},
"LoginErrorPasswordIsError": {"username": "admin","password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQqmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerVlYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"code": "requestsAddDem","description": "requestsAddDem","isDefault": 1,"name": "requests添加的维度"}
},
"根据维度编码获取维度信息": {
"GetDemMessageSuccess": {"code": "requestsAddDem"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"ids": "需要更新"}
},
"更新维度": {
"UpdateDemSuccess": {
"code": "requestsAddDem",
"description": "requestsAddDem",
"isDefault": 0,
"name": "requestsAddDem"
}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"code": "testAddOrg",
"demId": "需要更新",
"exceedLimitNum": 0,
"grade": "",
"limitNum": 0,
"name": "测试添加的组织",
"nowNum": 0,
"orderNo": 0,
"parentId": "0"
}
},
"用户加入组织": {
"OrgAddUserSuccess": {"orgCode": "testAddOrg", "accounts": "admin,guest"}
},
"保存组织参数": {
"SaveOrgparamsSuccess": {
"query": {"orgCode": "testAddOrg"},
"body": [{"alias": "hxxmts", "value": "项目中没有关系户"}]
}
},
"删除组织": {
"DeleteOrgSuccess": "testAddOrg"
}
}
}
[file]
# 配置数据配置层中文件的名称
excel=apiAutoTest.xlsx
case=case_data.json
expect=expect_data.json
sql=sql_data.json
[table]
# 配置工作表名称
table_name=BPM
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username":"超级管理员","account":"admin","userId":"1","expiration":86400,"loginStatus":true},
"LoginErrorUsernameIsNone": {"message":"账号或密码错误"},
"LoginErrorUsernameIsSpecialChar": {"message":"账号或密码错误"},
"LoginErrorUsernameIsLong": {"message":"账号或密码错误"},
"LoginErrorUsernameIsShort": {"message":"账号或密码错误"},
"LoginErrorUsernameIsError": {"message":"账号或密码错误"},
"LoginErrorPasswordIsNone":{"message":"账号或密码错误"},
"LoginErrorPasswordIsSpecialChar": {"message":"账号或密码错误"},
"LoginErrorPasswordIsLong": {"message":"账号或密码错误"},
"LoginErrorPasswordIsShort": {"message":"账号或密码错误"},
"LoginErrorPasswordIsError":{"message":"账号或密码错误"}
},
"刷新token": {
"RefreshSuccess": {"message": "刷新token成功"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"message": "添加维度成功"}
},
"根据维度编码获取维度信息": {
"GetDemMessageSuccess": {"isDelete": "0"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"message": "删除维度成功!"}
},
"更新维度": {
"UpdateDemSuccess": {"message": "更新维度成功"}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {"message": "添加组织成功"}
},
"用户加入组织": {
"OrgAddUserSuccess": {"message":"加入成功"}
},
"保存组织参数": {
"SaveOrgparamsSuccess": {"message":"保存组织参数成功!"}
},
"删除组织": {
"DeleteOrgSuccess": {"message":"删除组织成功!"}
}
}
}
{
"维度管理": {
"添加维度": {
"AddDemSuccess": {"delete": "dELETE FROM uc_demension WHERE `CODE_`=\"requestsAddDem\";"}
},
"根据维度编码删除维度": {
"DeleteDemSuccess": {"select": "select ID_ from uc_demension where CODE_=\"requestsAddDem\";"}
}
},
"组织管理": {
"添加组织": {
"AddOrgSuccess": {
"select": "select ID_ from uc_demension where CODE_=\"requestsAddDem\"; ",
"delete": "delete from uc_org where CODE_=\"testAddOrg\";"
}
}
}
}
[host]
# 配置被测系统的域名
bpm_host=http://36.139.193.99:8088
[sql]
host=36.139.193.99
port=3306
user=root
password=Rhrc@2024
database=eip8
[report]
log=log
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: settings.py
# Author: lao_zhao
# Datetime: 2024/9/4 16:03
# Description:
#
# ---------------------------------------------------------------------------
# excel的列号---------------------------------------------------------------------------
NUMBER = "A"
MODULE = "B"
API = "C"
TITLE = "D"
LEVEL = "E"
URL = "F"
REQ_METHOD = "G"
MIME = "H"
CASE_DATA = "I"
EXPECT_DATA = "J"
SQL_TYPE = "K"
SQL_DATA = "L"
UPDATE_KEY = "M"
# ini文件中file节点的key---------------------------------------------------------------------------
FILE_EXCEL = "excel"
FILE_CASE = "case"
FILE_EXPECT = "expect"
FILE_SQL = "sql"
# ini文件中host节点的key---------------------------------------------------------------------------
HOST_KEY = "bpm_host"
# ini文件中table节点的key---------------------------------------------------------------------------
TABLE_kEY = "table_name"
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 上午9:13
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: request_method.py
# Author: why
# Datetime: 2024/9/7 下午2:39
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import requests
from apiAutoTest_v4.common.read_project_ini import ReadProjectIni
from apiAutoTest_v4.data_config.settings import *
class RequestMethod:
def __init__(self):
"""登录系统并关联token"""
# 创建ReadProjectIni对象,调用get_host获取被测系统域名
pro_ini = ReadProjectIni()
login_url = pro_ini.get_host(HOST_KEY) + '/auth'
login_data = {
"username": "admin",
"password": "bF6N3L93cX8pV6x2yEqxNjwIIPaEOYw9bNI5GuIY4g9MeoFyPFPL5WteHaV0LcxQ"
"qmDJWlhuCRMXzAPvrFcxJrA8BgGjJpmB1WMrQrazIJPbWbCfmDit2s2jzn+DRerV"
"lYIFojDM96y24drEniwWzHtaJKiWoc7LGL1csNmokvQ="
}
# 创建session对象,并发送请求
self.session = requests.sessions.Session()
res = self.session.request(method="post", url=login_url, json=login_data)
# 获取token并更新到session的headers里
token = res.json().get("token")
self.session.headers["Authorization"] = f"Bearer {token}"
def request_all(self, req_method, req_url, req_mime, case_data):
"""
:param req_method: 发送请求的方法
:param req_url: 发送请求的url
:param req_mime: 发送请求的媒体类型
:param case_data: 发送请求的用例数据
:return: Response type
"""
# json类型
if req_mime == "application/json" or req_mime == "json":
return self.session.request(method=req_method, url=req_url, json=case_data)
# 表单类型
elif req_mime == "application/x-www-form-urlencoded" or req_mime == "form":
# 除了上传文件和json类型在请求体中传参以外,其他类型的数据全部使用data关键字传参。
return self.session.request(method=req_method, url=req_url, data=case_data)
# files类型
elif req_mime == "multipart/form-data" or req_mime == "form-data":
return self.session.request(method=req_method, url=req_url, files=case_data)
# params类型
elif req_mime == "query" or req_mime == "params":
return self.session.request(method=req_method, url=req_url, params=case_data)
# 无传参
elif req_mime is None:
return self.session.request(method=req_method, url=req_url)
# 判断媒体类型是否为query|json 或 json|query,是则在地址栏和请求体同时传参
elif req_mime == "query|json" or req_mime == "json|query":
# requests是支持地址栏和请求体同时传参的。地址栏使用params传参,请求体根据不同的媒体类型选择不同的关键字传参。
return self.session.request(method=req_method, url=req_url, json=case_data["body"], params=case_data["query"])
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 上午9:13
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 下午4:05
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
namespace = "brightlord"
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: conftest.py
# Author: why
# Datetime: 2024/9/7 下午3:01
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import pytest
from apiAutoTest_v4.common.db import DB
from apiAutoTest_v4.request_method.request_method import RequestMethod
@pytest.fixture(scope="session")
def fix_db():
db = DB()
yield db
@pytest.fixture(scope="session")
def fix_req():
req = RequestMethod()
yield req
[pytest]
; ;开启日志
; log_cli=true
; ;设置日志的级别,如果不设置级别的话,可以设置为NOTSET,如果要设置级别,级别可以有debug,info,warning,error,致命
; log_level=NOTSET
; ;设置日志显示的信息格式
; log_format=%(levelname)s--%(asctime)s--%(message)s
; ;设置日志中时间显示的格式
; log_date_format=%Y-%m-%d %H:%M:%S
; ;每个py文件运行的时候追加的命令
; ;addopts=-vs
; ;设置日志保存的文件
; log_file=../report/log/bpm_test.log
;设置日志保存在文件中的级别
log_file_level=error
;设置日志在文件中的信息格式
log_file_format=%(levelname)s--%(asctime)s--%(message)s
;设置文件日志中时间显示的格式
log_file_date_format=%Y-%m-%d %H:%M:%S
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: test_bpm.py
# Author: why
# Datetime: 2024/9/7 下午3:24
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import allure
import pytest
from apiAutoTest_v4 import log
from apiAutoTest_v4.common.read_excel_01 import ReadExcel
from apiAutoTest_v4.request_method.request_method import RequestMethod
from apiAutoTest_v4.test_case.test_brightlord import namespace
# 创建ReadExcel对象,便于获取用户的测试数据,所有创建ReadExcel对象时需要传入用户存放数据的目录名称
excel = ReadExcel(namespace)
class TestBpm:
@allure.epic("BPM项目-brightlord")
# @allure.feature("模块名称")
# @allure.story("接口名称")
# @allure.title("用例标题")
# @allure.severity("用例等级")
@pytest.mark.parametrize("module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key", excel.get_data())
def test_bpm(self, fix_db, fix_req, module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key):
allure.dynamic.feature(module_name)
allure.dynamic.story(api_name)
allure.dynamic.title(title)
allure.dynamic.severity(level)
# 判断sql语句类型是否为delete
if sql_type == "delete":
# 使用fix_db调用DB类对象的delete方法执行sql语句
fix_db.delete(sql_data['delete'])
# 判断sql语句类型是否为select
if sql_type == "select":
# 使用fix_db调用DB类对象的select方法执行sql语句
res_select = fix_db.select(sql_data['select'])
# 将查询到的结果更新到用例数据中去
case_data[update_key] = res_select
# 判断sql语句是否是delete|select 或 select|delete, 是则执行sql语句
if sql_type == "delete|select" or sql_type == "select|delete":
# 使用fix_db调用DB类对象的delete方法执行sql语句
fix_db.delete(sql_data['delete'])
# 使用fix_db调用DB类对象的select方法执行sql语句
res_select = fix_db.select(sql_data['select'])
# 将查询到的结果更新到用例数据中去
case_data[update_key] = res_select
# 使用RequestMethod对象调用request_all方法发送请求
res = RequestMethod().request_all(req_method=method, req_url=url, req_mime=mime, case_data=case_data)
# 断言
try:
for key in expect_data.keys():
assert res.json().get(key) == expect_data[key]
except AssertionError:
log.error(f"断言失败,接口为{url},期望数据为{expect_data},用例数据为{case_data},服务器返回数据为{res.text}")
raise AssertionError("断言失败")
else:
log.info(f"断言成功,接口为{url},期望数据为{expect_data},用例数据为{case_data},服务器返回数据为{res.text}")
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 下午4:06
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
namespace = "darkknight"
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: conftest.py
# Author: why
# Datetime: 2024/9/7 下午3:01
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import pytest
from apiAutoTest_v4.common.db import DB
from apiAutoTest_v4.request_method.request_method import RequestMethod
@pytest.fixture(scope="session")
def fix_db():
db = DB()
yield db
@pytest.fixture(scope="session")
def fix_req():
req = RequestMethod()
yield req
[pytest]
; ;开启日志
; log_cli=true
; ;设置日志的级别,如果不设置级别的话,可以设置为NOTSET,如果要设置级别,级别可以有debug,info,warning,error,致命
; log_level=NOTSET
; ;设置日志显示的信息格式
; log_format=%(levelname)s--%(asctime)s--%(message)s
; ;设置日志中时间显示的格式
; log_date_format=%Y-%m-%d %H:%M:%S
; ;每个py文件运行的时候追加的命令
; ;addopts=-vs
; ;设置日志保存的文件
; log_file=../report/log/bpm_test.log
;设置日志保存在文件中的级别
log_file_level=error
;设置日志在文件中的信息格式
log_file_format=%(levelname)s--%(asctime)s--%(message)s
;设置文件日志中时间显示的格式
log_file_date_format=%Y-%m-%d %H:%M:%S
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: test_bpm.py
# Author: why
# Datetime: 2024/9/7 下午3:24
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import allure
import pytest
from apiAutoTest_v4 import log
from apiAutoTest_v4.common.read_excel_01 import ReadExcel
from apiAutoTest_v4.request_method.request_method import RequestMethod
from apiAutoTest_v4.test_case.test_darkknight import namespace
# 创建ReadExcel对象,便于获取用户的测试数据,所有创建ReadExcel对象时需要传入用户存放数据的目录名称
excel = ReadExcel(namespace)
class TestBpm:
@allure.epic("BPM项目-darkknight")
# @allure.feature("模块名称")
# @allure.story("接口名称")
# @allure.title("用例标题")
# @allure.severity("用例等级")
@pytest.mark.parametrize("module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key", excel.get_data())
def test_bpm(self, fix_db, fix_req, module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key):
allure.dynamic.feature(module_name)
allure.dynamic.story(api_name)
allure.dynamic.title(title)
allure.dynamic.severity(level)
# 判断sql语句类型是否为delete
if sql_type == "delete":
# 使用fix_db调用DB类对象的delete方法执行sql语句
fix_db.delete(sql_data['delete'])
# 判断sql语句类型是否为select
if sql_type == "select":
# 使用fix_db调用DB类对象的select方法执行sql语句
res_select = fix_db.select(sql_data['select'])
# 将查询到的结果更新到用例数据中去
case_data[update_key] = res_select
# 判断sql语句是否是delete|select 或 select|delete, 是则执行sql语句
if sql_type == "delete|select" or sql_type == "select|delete":
# 使用fix_db调用DB类对象的delete方法执行sql语句
fix_db.delete(sql_data['delete'])
# 使用fix_db调用DB类对象的select方法执行sql语句
res_select = fix_db.select(sql_data['select'])
# 将查询到的结果更新到用例数据中去
case_data[update_key] = res_select
# 使用RequestMethod对象调用request_all方法发送请求
res = RequestMethod().request_all(req_method=method, req_url=url, req_mime=mime, case_data=case_data)
# 断言
try:
for key in expect_data.keys():
assert res.json().get(key) == expect_data[key]
except AssertionError:
log.error(f"断言失败,接口为{url},期望数据为{expect_data},用例数据为{case_data},服务器返回数据为{res.text}")
raise AssertionError("断言失败")
else:
log.info(f"断言成功,接口为{url},期望数据为{expect_data},用例数据为{case_data},服务器返回数据为{res.text}")
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: __init__.py
# Author: why
# Datetime: 2024/9/7 下午1:57
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
# 定义user_dir_name的值,即用户存放数据的目录名称
namespace = "demo"
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: conftest.py
# Author: why
# Datetime: 2024/9/7 下午3:01
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import pytest
from apiAutoTest_v4.common.db import DB
from apiAutoTest_v4.request_method.request_method import RequestMethod
@pytest.fixture(scope="session")
def fix_db():
db = DB()
yield db
@pytest.fixture(scope="session")
def fix_req():
req = RequestMethod()
yield req
[pytest]
; ;开启日志
; log_cli=true
; ;设置日志的级别,如果不设置级别的话,可以设置为NOTSET,如果要设置级别,级别可以有debug,info,warning,error,致命
; log_level=NOTSET
; ;设置日志显示的信息格式
; log_format=%(levelname)s--%(asctime)s--%(message)s
; ;设置日志中时间显示的格式
; log_date_format=%Y-%m-%d %H:%M:%S
; ;每个py文件运行的时候追加的命令
; ;addopts=-vs
; ;设置日志保存的文件
; log_file=../report/log/bpm_test.log
;设置日志保存在文件中的级别
log_file_level=error
;设置日志在文件中的信息格式
log_file_format=%(levelname)s--%(asctime)s--%(message)s
;设置文件日志中时间显示的格式
log_file_date_format=%Y-%m-%d %H:%M:%S
\ No newline at end of file
# -*-coding:utf-8-*- #
# ---------------------------------------------------------------------------
# ProjectName: test62
# FileName: test_bpm.py
# Author: why
# Datetime: 2024/9/7 下午3:24
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# --------------------------------------------------------------------------
import allure
import pytest
from apiAutoTest_v4 import log
from apiAutoTest_v4.common.read_excel_01 import ReadExcel
from apiAutoTest_v4.request_method.request_method import RequestMethod
from apiAutoTest_v4.test_case.test_demo import namespace
# 创建ReadExcel对象,便于获取用户的测试数据,所有创建ReadExcel对象时需要传入用户存放数据的目录名称
excel = ReadExcel(namespace)
class TestBpm:
@allure.epic("BPM项目-Demo")
# @allure.feature("模块名称")
# @allure.story("接口名称")
# @allure.title("用例标题")
# @allure.severity("用例等级")
@pytest.mark.parametrize("module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key", excel.get_data())
def test_bpm(self, fix_db, fix_req, module_name, api_name, title, level, url, method, mime, case_data, expect_data, sql_type, sql_data, update_key):
allure.dynamic.feature(module_name)
allure.dynamic.story(api_name)
allure.dynamic.title(title)
allure.dynamic.severity(level)
# 判断sql语句类型是否为delete
if sql_type == "delete":
# 使用fix_db调用DB类对象的delete方法执行sql语句
fix_db.delete(sql_data['delete'])
# 判断sql语句类型是否为select
if sql_type == "select":
# 使用fix_db调用DB类对象的select方法执行sql语句
res_select = fix_db.select(sql_data['select'])
# 将查询到的结果更新到用例数据中去
case_data[update_key] = res_select
# 判断sql语句是否是delete|select 或 select|delete, 是则执行sql语句
if sql_type == "delete|select" or sql_type == "select|delete":
# 使用fix_db调用DB类对象的delete方法执行sql语句
fix_db.delete(sql_data['delete'])
# 使用fix_db调用DB类对象的select方法执行sql语句
res_select = fix_db.select(sql_data['select'])
# 将查询到的结果更新到用例数据中去
case_data[update_key] = res_select
# 使用RequestMethod对象调用request_all方法发送请求
res = RequestMethod().request_all(req_method=method, req_url=url, req_mime=mime, case_data=case_data)
# 断言
try:
for key in expect_data.keys():
assert res.json().get(key) == expect_data[key]
except AssertionError:
log.error(f"断言失败,接口为{url},期望数据为{expect_data},用例数据为{case_data},服务器返回数据为{res.text}")
raise AssertionError("断言失败")
else:
log.info(f"断言成功,接口为{url},期望数据为{expect_data},用例数据为{case_data},服务器返回数据为{res.text}")
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