Commit d19b4b74 by 鲁丽沙

删除

parent 2e946496
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username":"admin","password":"MTIzNDU2"},
"LoginErrorPasswordIsNone": {"username":"admin","password":""},
"LoginErrorPasswordIsLong":{"username":"admin","password":"MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2"},
"LoginErrorPasswordIsShort":{"username":"admin","password":"m"},
"LoginErrorPasswordIsSpecial":{"username":"admin","password":"☯㍿卍卐"},
"LoginErrorUsernameIsNone":{"username":"","password":"MTIzNDU2"},
"LoginErrorUsernameIsLong":{"username":"adminadminadminadmin","password":"MTIzNDU2"},
"LoginErrorUsernameIsShort":{"username":"a","password":"MTIzNDU2"},
"LoginErrorUsernameIsSpecial":{"username":"☯㍿卍卐","password":"MTIzNDU2"},
"LoginErrorUsernameIsErr":{"username":"admin123","password":"MTIzNDU2"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {
"code": "api_auto_test_add_dem",
"description": "api_auto_test_add_dem",
"isDefault": 0,
"name": "api_auto_test_add_dem"
}
}
}
}
\ No newline at end of file
;配置数据配置层的文件
[file]
# 用例管理文件名称,auto自动
excel = APIAutoTest000.xlsx
# 用例数据
case = case_data.json
# 期望数据
except = expect_data.json
# 表名
[worksheet]
table_name = BPM
# 配置域名
[host]
bpm = http://120.46.172.186:8080
# 配置链接SQL
[db]
\ No newline at end of file
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"username":"超级管理员","loginStatus":true, "account":"admin"},
"LoginErrorPasswordIsNone": {"message":"账号或密码错误"},
"LoginErrorPasswordIsLong":{"message":"账号或密码错误"},
"LoginErrorPasswordIsShort":{"message":"账号或密码错误"},
"LoginErrorPasswordIsSpecial":{"message":"账号或密码错误"},
"LoginErrorUsernameIsNone":{"message":"账号或密码错误"},
"LoginErrorUsernameIsLong":{"message":"账号或密码错误"},
"LoginErrorUsernameIsShort":{"message":"账号或密码错误"},
"LoginErrorUsernameIsSpecial":{"message":"账号或密码错误"},
"LoginErrorUsernameIsErr":{"message":"账号或密码错误"}
},
"刷新token": {
"RefreshTokenSuccess": {"message": "刷新token成功"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess":{"message": "添加维度成功!"}
}
}
}
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: selenium_lianxi
# FileName: new.py
# Author: lisa
# Datetime: 2024/5/16 19:48
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# ---------------------------------------------------------------------------
import openpyxl
# ws = openpyxl.load_workbook("./xxx.xlsx")
# with open("./xxx.xlsx",mode="w") as f:
# f.write("1")
dic = {
"1":{
"2":{
}
}
}
print(dic)
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: selenium_lianxi
# FileName: test_case.py
# Author: lisa
# Datetime: 2024/5/16 18:22
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# ---------------------------------------------------------------------------
from Thefirst_test_lianxi.common.read_excel import ReadExcel
from Thefirst_test_lianxi.req_method.req_method import RequestMethod
# 可以写成函数,但类好看
# 安装了pytest ,命名不要以test开头或者结尾
class tcase():
def tbpm(self):
RM = RequestMethod()
RE = ReadExcel()
for i in RE.get_data():
res = RM.request_all(req_method=i[0],req_url=i[1],req_mime=i[2],case_data=i[3])
# 断言
for key in i[-1]:
# print(i[4])
try:
assert i[-1][key] == res.json().get(key)
except Exception as e:
print("断言失败",e)
# raise e # 不要抛出错误,会标红
else:
print("断言成功")
'''def test_bpm1():
# 获取所有的用例
excel = ReadExcel()
case_datas = excel.get_data()
# 创建请求的对象
req = RequestMethod()
# 对所有的用例数据发送请求
for data in case_datas:
print(data)
res = req.request_all(req_method=data[0], req_url=data[1], req_mime=data[2], case_data=data[3])
# 断言
for key in data[-1].keys():
try:
assert data[-1][key] == res.json().get(key)
except Exception as e:
print("断言失败", e)
else:
print("断言成功")'''
if __name__ == "__main__":
# print("++++++++",test_bpm1(),"+"*10)
T = tcase()
T.tbpm()
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: selenium_lianxi
# FileName: read_excel.py
# Author: lisa
# Datetime: 2024/5/15 18:49
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# ---------------------------------------------------------------------------
import re
import openpyxl
from Thefirst_test_lianxi.common.read_ini import ReadIni
from Thefirst_test_lianxi.common.read_json import ReadJson
class ReadExcel:
# 加载工作簿——打开工作表——
def __init__(self):
# 获取路径和表名
self.ini = ReadIni()
excel_path = self.ini.get_file_path("excel")
# print(wb_path)
excel_table = self.ini.get_table_name("table_name")
# 加载工作簿-工作表
try:
wb = openpyxl.load_workbook(excel_path)
self.ws = wb[excel_table]
except Exception as e:
print(e)
raise e
# 拿到单元格数据
def __get_cell_value(self, r: int, c):
try:
values = self.ws[c + str(r)].value
except Exception as e:
print(e)
raise e
else:
if values is None:
return None
elif values.strip():
return values.strip() # 来用正则re模块,可以去除中间的空格,但是用例数据比较复杂,有符号等等,正则不好搞定,后续全是空
# return re.findall(r"%s",values)
def get_req_method(self,r):
return self.__get_cell_value(r, "f")
def get_req_url(self,r): # clomn , row
req_url = self.__get_cell_value(r,"g")
if req_url:
host = self.ini.get_host("BPM")
return host+req_url
def get_req_mime(self,r):
req_mime = self.__get_cell_value(r,"h")
if req_mime:
return req_mime.lower()
def get_case_module(self,r):
case_module= self.__get_cell_value(r,"b")
if case_module:
return case_module
# return self.__get_cell_value(r,"b")
def get_case_api(self,r):
case_api = self.__get_cell_value(r,"c")
if case_api:
return case_api
# return self.__get_cell_value(r,"c")
def case_data(self,r):
case_key = self.__get_cell_value(r,"i")
# print("key",case_key)
if case_key:
json_case_data = ReadJson(self.ini.get_file_path("case"))
# list_case = []
# key 已经取出来了,就是case_key
# 解耦
# print(json_case_data)
module_name =self.get_case_module(r)
api_name = self.get_case_api(r)
# print(case_name,"====",api_name)
return json_case_data[module_name][api_name][case_key]
def except_data(self,r):
except_key = self.__get_cell_value(r, "j")
if except_key:
json_except_data = ReadJson(self.ini.get_file_path("except"))
module_name = self.get_case_module(r)
api_name = self.get_case_api(r) # self定义在初始化函数中才能全局调用,定义在单个方法中并不能全局使用
return json_except_data[module_name][api_name][except_key]
def get_data(self): # 综合为二维列表
list_two_dimensional = []
for r in range(2,self.ws.max_row+1):
list_one = [self.get_req_method(r), self.get_req_url(r), self.get_req_mime(r), self.case_data(r), self.except_data(r)]
# print(r,self.case_data(r))
if list_one.count(None) <= 2:
list_two_dimensional.append(list_one)
return list_two_dimensional
if __name__ == "__main__":
RE = ReadExcel()
# print(RE.get_cell_value(1,"a"))
print(RE.get_data())
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: selenium_lianxi
# FileName: read_ini.py
# Author: lisa
# Datetime: 2024/5/15 18:47
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# ---------------------------------------------------------------------------
import os
import configparser
class ReadIni:
def __init__(self):
# 动态获取文件路径
# os.path.join(os.path.dirname(os.path.dirname(__file__)), "Data_config") + r'\config.ini'或者再join一次config.ini
# 目录和文件路径分开写,方便后续使用
self.Data_dir_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "Data_config")
Data_conf_path = os.path.join(self.Data_dir_path, 'config.ini') # 不判断是否是Ini文件
# print(Data_conf_path)
# 读取Ini文件,ConfigParser——read,后面使用了get方法
self.conf = configparser.ConfigParser()
self.conf.read(Data_conf_path, encoding='utf-8')
def get_file_path(self,key):
# 获取key所对应文件的绝对路径,并返回
try:
value = self.conf.get("file", key) # ConfigParser 的get方法,根据节点和key取value
except Exception as e:
print('输入的key错误')
raise e
else:
return os.path.join(self.Data_dir_path, value)
def get_host(self, key):
# 取出域名
try:
value = self.conf.get("host", key)
except Exception as e:
print('输入的key错误')
raise e
else:
return value
def get_table_name(self, key):
# 工作表名字
try:
value = self.conf.get("worksheet",key)
except Exception as e:
print('输入的key错误')
raise e
else:
return value
if __name__ == "__main__":
ini = ReadIni()
print(ini.get_file_path("case"))
print(ini.get_table_name("table_name"))
print(ini.get_host("BPM"))
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: selenium_lianxi
# FileName: read_json.py
# Author: lisa
# Datetime: 2024/5/15 18:49
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# ---------------------------------------------------------------------------
import json
import os
from Thefirst_test_lianxi.common.read_ini import ReadIni
def ReadJson(filename):
# 判断是不是json文件,读出json内容即可【因为是传入的参数】
if os.path.isfile(filename) and filename.endswith(".json"):
try:
with open(filename,mode="r",encoding="utf-8") as f :
return json.load(f) # loads ——str参数是字符串
except Exception as e:
print(e)
raise e
else:
raise FileNotFoundError("文件路径错误")
if __name__ == "__main__":
ini = ReadIni()
json_path = ini.get_file_path(key="case")
# print(json_path)
print(ReadJson(json_path))
\ No newline at end of file
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: selenium_lianxi
# FileName: req_method.py
# Author: lisa
# Datetime: 2024/5/16 17:07
# Description:
# 命名规范:文件名全小写+下划线,类名大驼峰,方法和变量小写+下划线连接,
# 常量大写,变量和常量用名词,方法用动词
# ---------------------------------------------------------------------------
import base64
import requests
from Thefirst_test_lianxi.common.read_excel import ReadExcel
from Thefirst_test_lianxi.common.read_ini import ReadIni
# 应该叫登录预处理
class RequestMethod:
def __init__(self):
"""关联登录状态,不太熟练,多加练习"""
login_data = {"username":"admin","password": base64.b64encode("123456".encode()).decode()}
ini = ReadIni()
login_url = ini.get_host("BPM") + "/auth"
# RE = ReadExcel()
# login_url = RE.get_data()[0][1]
# print(login_url)
# token
self.bpm_session = requests.sessions.Session()
res = self.bpm_session.post(url=login_url,json=login_data)
token = res.json().get("token") # 获取响应体json类型的数据,转换为Python的对象
# 将token更新到session的头部headers
self.bpm_session.headers["Authorization"] = "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
"""
if req_mime == "application/json" or req_mime == "json":
return self.bpm_session.request(method=req_method,url=req_url,json=case_data)
elif req_mime == "application/x-www-form-urlencoded" or req_mime == "x-www-form-urlencoded" or req_mime == "form":
return self.bpm_session.request(method=req_method,url=req_url,data=case_data)
elif req_mime == "multipart/form-data" or req_mime == "form-data":
return self.bpm_session.request(method=req_method,url=req_url,files=case_data)
elif req_mime == "query" or req_mime == "params":
return self.bpm_session.request(method=req_method,url=req_url,params=case_data)
elif req_mime is None:
return self.bpm_session.request(method=req_method,url=req_url)
else:
raise ValueError("请求的媒体类型错误!!!")
if __name__ == "__main__":
RM = RequestMethod() # 不带括号就是对类重命名
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