Arthur-Wu commit
This commit is contained in:
5
YiMao/__init__.py
Normal file
5
YiMao/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author:: Arthur Wu
|
||||
# @Date:: 2024/5/21-15:36
|
||||
# @Description::
|
@ -1 +0,0 @@
|
||||
业务方法目录
|
59
YiMao/config/ApiInfo.py
Normal file
59
YiMao/config/ApiInfo.py
Normal file
@ -0,0 +1,59 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author:: Arthur Wu
|
||||
# @Date:: 2024/10/14-11:50
|
||||
# @Description:: API接口信息
|
||||
api_env = {
|
||||
"test_env": "https://api.test.yimaogo.com/",
|
||||
"gray_env": "https://api.yimaogo.com/",
|
||||
}
|
||||
ManagementPlatformApi_zh = {
|
||||
"编辑超市系统参数": "admin/system/settings", # 超市管理 (MarketID:可以通过查询超市接口获取)
|
||||
|
||||
"编辑门店系统参数": "admin/system/settings", # 门店管理 (StoreID:可以通过查询门店接口获取)
|
||||
"删除门店系统参数": "admin/system/settings/{StoreID}",
|
||||
"新建促销商品白名单": "admin/goods/promotion",
|
||||
"修改与删除促销商品白名单": "admin/goods/promotion/{GoodsWhiteListID}", # GoodsWhiteListID:可以通过新建时过程存储,调用删除接口时再读取
|
||||
"新建重量放通白名单": "admin/goods/weight/promotion",
|
||||
"修改与删除重量放通白名单": "admin/goods/weight/promotion/{WeightWhiteListID}", # WeightWhiteListID:可以通过新建时过程存储,其他接口使用时再读取
|
||||
|
||||
"新建派样活动": "admin/sample/activity", # 派样活动
|
||||
"查询派样活动": "admin/sample/activity/list",
|
||||
"修改与删除派样活动": "admin/sample/activity/{SampleActivityID}", # :可以通过新建时过程存储,其他接口使用时再读取
|
||||
"暂停派样活动": "admin/sample/activity/change/status/{SampleActivityID}?status=3",
|
||||
"重新发布派样活动": "admin/sample/activity/change/status/{SampleActivityID}?status=2",
|
||||
"立即结束派样活动": "admin/sample/activity/change/status/{SampleActivityID}?status=4",
|
||||
"复制派样活动": "admin/sample/activity",
|
||||
"新建抽奖活动": "admin/lotteryAct", # 抽奖活动
|
||||
"查询抽奖活动": "admin/lotteryAct/list",
|
||||
"修改与删除抽奖活动": "admin/lotteryAct/{LotteryActID}",
|
||||
"编辑抽奖活动状态": "admin/lotteryAct/modifyStatus/{LotteryActID}", # :可以通过新建时过程存储,其他接口使用时再读取
|
||||
"复制抽奖活动": "admin/lotteryAct/copy/{LotteryActID}",
|
||||
|
||||
"新建优惠券活动": "admin/coupon/setting", # 优惠券活动
|
||||
"查询优惠券活动": "admin/coupon/setting/list",
|
||||
"暂停优惠券活动": "admin/coupon/setting/status/{CouponID}?status=6", # :可以通过新建时过程存储,其他接口使用时再读取
|
||||
"重新开启优惠券活动": "admin/coupon/setting/status/{CouponID}?status=4",
|
||||
"结束投放优惠券活动": "admin/coupon/setting/status/{CouponID}?status=7",
|
||||
"修改与删除优惠券活动": "admin/coupon/setting/{CouponID}",
|
||||
"复制优惠券活动": "admin/coupon/setting",
|
||||
|
||||
"新建广告": "admin/ads", # 广告活动
|
||||
"复制广告": "admin/ads", # 广告活动
|
||||
"查询广告": "admin/ads/list",
|
||||
"修改与删除广告": "admin/ads/{ADsID}", # :可以通过新建时过程存储,其他接口使用时再读取
|
||||
"暂停广告投放": "admin/ads/status/{ADsID}?status=6",
|
||||
"重新投放广告": "admin/ads/status/{ADsID}?status=4",
|
||||
"结束投放广告": "admin/ads/status/{ADsID}?status=7",
|
||||
|
||||
"新建版本信息": "admin/apk", # 版本管理
|
||||
"查询版本信息": "admin/apk/list",
|
||||
"修改与删除版本信息": "admin/apk/{VersionID}", # :可以通过新建时过程存储,其他接口使用时再读取
|
||||
|
||||
"新建升级任务": "admin/upgrade/settings", # 升级任务
|
||||
"查询升级任务": "admin/upgrade/settings/list",
|
||||
"修改与删除升级任务": "admin/upgrade/settings/{UpgradeID}", # :可以通过新建时过程存储,其他接口使用时再读取
|
||||
"启禁升级任务": "admin/upgrade/settings/active/{UpgradeID}",
|
||||
}
|
||||
|
||||
|
5
YiMao/config/__init__.py
Normal file
5
YiMao/config/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author:: Arthur Wu
|
||||
# @Date:: 2024/5/21-15:36
|
||||
# @Description::
|
@ -1 +0,0 @@
|
||||
# 项目级配置文件
|
21
YiMao/conftest.py
Normal file
21
YiMao/conftest.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
'''@Author:: Arthur Wu
|
||||
@Date:: 2024/05/21
|
||||
@Description:: This is the webservices library conftest file
|
||||
'''
|
||||
|
||||
|
||||
@pytest.fixture(scope='function', autouse=True)
|
||||
def init_webservices():
|
||||
"""@Author:: Arthur
|
||||
@Date:: 2022/05/19
|
||||
@Description::
|
||||
:return:
|
||||
"""
|
||||
print("function setup")
|
||||
yield
|
||||
print("function teardwon")
|
||||
|
||||
|
BIN
YiMao/data/YMHT_ApiTestCase_0.0.1.xlsx
Normal file
BIN
YiMao/data/YMHT_ApiTestCase_0.0.1.xlsx
Normal file
Binary file not shown.
BIN
YiMao/data/YMHT_ApiTestCase_0.02.xlsx
Normal file
BIN
YiMao/data/YMHT_ApiTestCase_0.02.xlsx
Normal file
Binary file not shown.
@ -1 +0,0 @@
|
||||
测试用例
|
0
YiMao/debugLib/__init__.py
Normal file
0
YiMao/debugLib/__init__.py
Normal file
0
YiMao/debugLib/demo1024.py
Normal file
0
YiMao/debugLib/demo1024.py
Normal file
@ -1 +0,0 @@
|
||||
自动化报告目录
|
5
YiMao/scripts/__init__.py
Normal file
5
YiMao/scripts/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author:: Arthur Wu
|
||||
# @Date:: 2024/10/21-9:21
|
||||
# @Description::
|
@ -1 +0,0 @@
|
||||
项目自动化脚本目录
|
61
YiMao/scripts/test_01MarketSystemParameters.py
Normal file
61
YiMao/scripts/test_01MarketSystemParameters.py
Normal file
@ -0,0 +1,61 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='01-超市管理')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_MarketManagementModule(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.timestamp = int(time.time())
|
||||
|
||||
@allure.story('[管理平台] 超市管理模块')
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_market_system_parameters(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 超市管理模块接口
|
||||
'''
|
||||
''' step01: '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:超市管理模块接口自动化测试")
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口 '''
|
||||
time.sleep(1)
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] + "/64" # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
|
||||
''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, f"---断言失败!"
|
||||
LOGGER.info(f">>> {data['BusinessModule']}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
145
YiMao/scripts/test_02StoreMangementModule.py
Normal file
145
YiMao/scripts/test_02StoreMangementModule.py
Normal file
@ -0,0 +1,145 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='02-门店管理')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_StoreManagementModule(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.timestamp = int(time.time())
|
||||
|
||||
@allure.story('[管理平台] 门店管理模块')
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_store_management(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 门店管理模块接口
|
||||
'''
|
||||
''' step01:获取测试用例数据 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:门店管理模块接口自动化测试")
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02:请求接口 '''
|
||||
if data['BusinessModule'] == '删除门店系统参数':
|
||||
time.sleep(0.5)
|
||||
sysSettingID = 97
|
||||
storeId = 65
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] # 请求地址
|
||||
last_api_url = api_url.replace("{StoreID}", str(sysSettingID))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
elif data['BusinessModule'] == '修改与删除促销商品白名单':
|
||||
GoodsWhiteListIDList = Txt().read_txt("GoodsWhiteListID.txt")
|
||||
LOGGER.info(f"---促销商品白名单ID列表为:{GoodsWhiteListIDList}")
|
||||
if requestType_c == "DELETE":
|
||||
for i in range(len(GoodsWhiteListIDList)):
|
||||
if GoodsWhiteListIDList[i] not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[
|
||||
data['BusinessModule']] # 请求地址
|
||||
last_api_url = api_url.replace("{GoodsWhiteListID}", str(GoodsWhiteListIDList[i]))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(1)
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
else:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] # 请求地址
|
||||
last_api_url = api_url.replace("{GoodsWhiteListID}", str(GoodsWhiteListIDList[-2]))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
elif data['BusinessModule'] == '修改与删除重量放通白名单':
|
||||
WeightWhiteListIDList = Txt().read_txt("WeightWhiteListID.txt")
|
||||
LOGGER.info(f"---删除重量放通白名单ID列表为:{WeightWhiteListIDList}")
|
||||
if requestType_c == "DELETE":
|
||||
for j in range(len(WeightWhiteListIDList)):
|
||||
if WeightWhiteListIDList[j] not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[
|
||||
data['BusinessModule']] # 请求地址
|
||||
last_api_url2 = api_url.replace("{WeightWhiteListID}", str(WeightWhiteListIDList[j]))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url2}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(method=requestType_c, url=last_api_url2, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---删除第 {j+1} 条数据,接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---第 {j+1} 条数据,接口返回体为:: {rspJsonFormat}\n")
|
||||
else:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] # 请求地址
|
||||
last_api_url = api_url.replace("{WeightWhiteListID}", str(WeightWhiteListIDList[0]))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
else:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
if data['BusinessModule'] == '新建促销商品白名单':
|
||||
time.sleep(0.5)
|
||||
goodsWhiteListID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("GoodsWhiteListID.txt", str(goodsWhiteListID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 新建促销商品白名单ID 失败!")
|
||||
elif data['BusinessModule'] == '新建重量放通白名单':
|
||||
time.sleep(0.5)
|
||||
weightWhiteListID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("WeightWhiteListID.txt", str(weightWhiteListID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 新建重量放通白名单ID 失败!")
|
||||
|
||||
''' step03: 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, f"---断言失败!"
|
||||
LOGGER.info(f">>> {data['BusinessModule']}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
110
YiMao/scripts/test_03SampleDistributionActivity.py
Normal file
110
YiMao/scripts/test_03SampleDistributionActivity.py
Normal file
@ -0,0 +1,110 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests,datetime
|
||||
from datetime import datetime,timedelta
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.PgSqlLib import PGSQL
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='03-派样活动')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_SampleDistributionActivity_Module(unittest.TestCase):
|
||||
|
||||
@allure.story('[管理平台] 派样活动模块')
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_sample_distribution_activity(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 派样活动模块接口
|
||||
'''
|
||||
''' step01:获取测试用例数据 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:派样活动模块接口自动化测试")
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口
|
||||
执行复制接口时,存储对应 rspJson["data"]["id"],为删除接口使用
|
||||
'''
|
||||
if data['BusinessModule'] in ["新建派样活动", "复制派样活动", "查询派样活动"]:
|
||||
# 新建、查询、复制
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
# LOGGER.info(f"---处理前,请求体为:{data['Payload']}\n")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---处理后,请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
time.sleep(0.5)
|
||||
if data['BusinessModule'] == "新建派样活动":
|
||||
if "存为草稿" in caseName_c:
|
||||
SampleActivityID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt(
|
||||
"03_DraftOfActivityID.txt", str(SampleActivityID)
|
||||
)
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 派样活动(新建)ID 失败!")
|
||||
else:
|
||||
SampleActivityID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt(
|
||||
"03_CreateSampleActivityID.txt", str(SampleActivityID)
|
||||
)
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 派样活动(草稿)ID 失败!")
|
||||
elif data['BusinessModule'] == "复制派样活动":
|
||||
SampleActivityID = rspJson["data"]['id']
|
||||
# writeResult = Txt().append_write_txt("03_CopySampleActivityID.txt", str(SampleActivityID))
|
||||
writeResult = Txt().append_write_txt(
|
||||
"03_CreateSampleActivityID.txt", str(SampleActivityID)
|
||||
)
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 派样活动(复制)ID 失败!")
|
||||
else:
|
||||
sampleActIDList = Txt().read_txt("03_CreateSampleActivityID.txt")
|
||||
LOGGER.info(f"---新建并发布的派样活动ID list为:{sampleActIDList}")
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[data['BusinessModule']] # 请求地址
|
||||
last_api_url = api_url.replace("{SampleActivityID}", str(sampleActIDList[0]))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
|
||||
''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, f"---断言失败!"
|
||||
LOGGER.info(f">>> {data['BusinessModule']}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
LOGGER.info(f">>> 派样活动模块接口自动化测试所有用例执行完毕 <<<\n")
|
||||
LOGGER.info(f">>> 开始执行清理-派样活动模块-测试数据 <<<\n")
|
||||
sampActIDList = (Txt().read_txt("03_CreateSampleActivityID.txt") +
|
||||
Txt().read_txt("03_DraftOfActivityID.txt"))
|
||||
LOGGER.info(f"---待删除的派样活动ID list为:{sampActIDList}")
|
||||
PGSQL().del_sample_activity_data(sampActIDList)
|
||||
LOGGER.info(f">>> 清理-派样活动模块-测试数据完毕 <<<\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
112
YiMao/scripts/test_04LotteryDraw.py
Normal file
112
YiMao/scripts/test_04LotteryDraw.py
Normal file
@ -0,0 +1,112 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,json,requests
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='04-抽奖活动')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_LotteryDraw_Module(unittest.TestCase):
|
||||
|
||||
@allure.story("[管理后台] 抽奖活动模块")
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_lottery_draw(self, data):
|
||||
'''@Date:: 2024/10/25
|
||||
@Desc::
|
||||
管理后台 -> 抽奖活动 模块接口
|
||||
'''
|
||||
''' step01- 前置数据、接口信息描述等 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:抽奖活动 模块接口自动化测试")
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口 '''
|
||||
rspJson = {}
|
||||
if caseModule_c in ["新建抽奖活动", "查询抽奖活动"]:
|
||||
# 新建、查询
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
if caseModule_c == "新建抽奖活动":
|
||||
if "存为草稿" in caseName_c:
|
||||
LottreyActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("04_LottreyDrawID.txt", str(LottreyActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 抽奖活动(新建)ID 失败!")
|
||||
else:
|
||||
LottreyActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("04_CreateLottreyActID.txt", str(LottreyActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 抽奖活动(草稿)ID 失败!")
|
||||
else:
|
||||
# 编辑抽奖活动状态
|
||||
if "存为草稿" in caseName_c:
|
||||
lotteryActIDList = Txt().read_txt("04_LottreyDrawID.txt")
|
||||
LOGGER.info(f"---新建抽奖活动 存为草稿的活动ID list为:{lotteryActIDList}")
|
||||
elif requestType_c == "DELETE":
|
||||
lotteryActIDList = (Txt().read_txt("04_CreateLottreyActID.txt") +
|
||||
Txt().read_txt("04_LottreyDrawID.txt"))
|
||||
LOGGER.info(f"---新建并发布的抽奖活动ID list为:{lotteryActIDList}")
|
||||
else:
|
||||
lotteryActIDList = Txt().read_txt("04_CreateLottreyActID.txt")
|
||||
LOGGER.info(f"---新建并发布的抽奖活动ID list为:{lotteryActIDList}")
|
||||
if requestType_c == "DELETE" or caseModule_c == "编辑抽奖活动状态":
|
||||
# 编辑抽奖活动状态、删除抽奖活动
|
||||
for i in range(len(lotteryActIDList)):
|
||||
lotteryId = lotteryActIDList[i]
|
||||
if lotteryId not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{LotteryActID}", str(lotteryId))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
else:
|
||||
# 编辑抽奖活动、复制抽奖活动
|
||||
lotteryId = lotteryActIDList[0]
|
||||
if lotteryId not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{LotteryActID}", str(lotteryId))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
rspJsonFormat = json.dumps(response.json(), indent=4, ensure_ascii=False)
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {rspJsonFormat}\n")
|
||||
|
||||
''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, AssertionError(f"---断言失败!")
|
||||
LOGGER.info(f">>> {caseModule_c}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
126
YiMao/scripts/test_05CouponPromotion.py
Normal file
126
YiMao/scripts/test_05CouponPromotion.py
Normal file
@ -0,0 +1,126 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests,datetime
|
||||
from datetime import datetime,timedelta
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.PgSqlLib import PGSQL
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='05-优惠券活动')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_CouponPromotion_Module(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.timestamp = int(time.time())
|
||||
|
||||
@allure.story("管理后台:优惠券活动模块")
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_coupon_promotion(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 优惠券活动模块接口
|
||||
'''
|
||||
LOGGER.info(f"---用例data信息为:{data}")
|
||||
''' step01- 前置数据、接口信息描述等 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:优惠券活动 模块接口自动化测试")
|
||||
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口 '''
|
||||
if requestType_c == "POST":
|
||||
# 新建、查询
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
if caseModule_c == "新建优惠券活动":
|
||||
if "存为草稿" in caseName_c:
|
||||
CouponActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("05_CouponDrawID.txt", str(CouponActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 优惠券活动(新建)ID 失败!")
|
||||
elif "复制" in caseName_c:
|
||||
CouponActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("05_CopyCouponActID.txt", str(CouponActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 优惠券活动(新建)ID 失败!")
|
||||
else:
|
||||
CouponActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("05_CreateCouponActID.txt", str(CouponActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 优惠券活动(草稿)ID 失败!")
|
||||
elif caseName_c == "修改并发布优惠券活动":
|
||||
ActIDList = (Txt().read_txt("05_CreateCouponActID.txt"))
|
||||
LOGGER.info(f"---新建并发布的 优惠券活动ID list为:{ActIDList}")
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{CouponID}", ActIDList[0])
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
else:
|
||||
if requestType_c == "PUT":
|
||||
ActIDList = (Txt().read_txt("05_CreateCouponActID.txt"))
|
||||
LOGGER.info(f"---新建并发布的 优惠券活动ID list为:{ActIDList}")
|
||||
else:
|
||||
ActIDList = (Txt().read_txt("05_CopyCouponActID.txt") +
|
||||
Txt().read_txt("05_CouponDrawID.txt"))
|
||||
LOGGER.info(f"---存为草稿&复制的 优惠券活动ID list为:{ActIDList}")
|
||||
for i in range(len(ActIDList)):
|
||||
# 暂停、重启、结束
|
||||
ActId = ActIDList[i]
|
||||
if ActId not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{CouponID}", str(ActId))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, AssertionError(f"---断言失败!")
|
||||
LOGGER.info(f">>> {caseModule_c}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
LOGGER.info(f">>> 优惠券活动模块接口自动化测试所有用例执行完毕 <<<\n")
|
||||
LOGGER.info(f">>> 开始执行清理-优惠券活动模块-测试数据 <<<\n")
|
||||
ActIDList = (Txt().read_txt("05_CreateCouponActID.txt") +
|
||||
Txt().read_txt("05_CouponDrawID.txt") +
|
||||
Txt().read_txt("05_CopyCouponActID.txt")) #
|
||||
LOGGER.info(f"---待删除的优惠券活动ID list为:{ActIDList}")
|
||||
res = PGSQL().del_coupon_activity_data(ActIDList) #
|
||||
LOGGER.info(f"---清除自动化测试数据执行结果为:{res}")
|
||||
LOGGER.info(f">>> 清理-优惠券活动模块-测试数据完毕 <<<\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
112
YiMao/scripts/test_06ADManagement.py
Normal file
112
YiMao/scripts/test_06ADManagement.py
Normal file
@ -0,0 +1,112 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests,datetime
|
||||
from datetime import datetime,timedelta
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='06-广告管理')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_ADManagement_Module(unittest.TestCase):
|
||||
@allure.story("管理后台:广告管理模块")
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_ad_management(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 广告管理模块接口
|
||||
'''
|
||||
''' step01- 前置数据、接口信息描述等 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:广告管理 模块接口自动化测试")
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口 '''
|
||||
if requestType_c == 'POST':
|
||||
# 新建、查询、复制
|
||||
timeStamp = str(int(time.time()))
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
if "查询广告" not in caseName_c:
|
||||
if "草稿" in caseName_c or "复制" in caseName_c:
|
||||
ActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("06_ADDrawID.txt", str(ActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 广告管理(新建)ID 失败!")
|
||||
else:
|
||||
ActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("06_CreateADID.txt", str(ActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 广告管理(草稿)ID 失败!")
|
||||
else:
|
||||
# 编辑、删除
|
||||
if "修改广告" in caseName_c:
|
||||
# 取一个已发布的广告ID
|
||||
ActIDList = Txt().read_txt("06_CreateADID.txt")
|
||||
ActID = ActIDList[0]
|
||||
LOGGER.info(f"---存为草稿的 广告管理ID 为:{ActID}")
|
||||
if ActID not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{ADsID}", ActID)
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
else:
|
||||
if requestType_c == "PUT":
|
||||
ActIDList = Txt().read_txt("06_CreateADID.txt")
|
||||
LOGGER.info(f"---新建并发布的 广告管理ID list为:{ActIDList}")
|
||||
else:
|
||||
ActIDList = (Txt().read_txt("06_CreateADID.txt") +
|
||||
Txt().read_txt("06_ADDrawID.txt"))
|
||||
LOGGER.info(f"---存为草稿&复制的 广告管理ID list为:{ActIDList}")
|
||||
for i in range(len(ActIDList)):
|
||||
# 暂停、重启、结束、删除
|
||||
ActId = ActIDList[i]
|
||||
if ActId not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{ADsID}", str(ActId))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(method=requestType_c, url=last_api_url, headers=HEADERS,
|
||||
data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
|
||||
''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, AssertionError(f"---断言失败!")
|
||||
LOGGER.info(f">>> {caseModule_c}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
100
YiMao/scripts/test_07VersionManagement.py
Normal file
100
YiMao/scripts/test_07VersionManagement.py
Normal file
@ -0,0 +1,100 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests,datetime
|
||||
from datetime import datetime,timedelta
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.AssertLib import _assert_result
|
||||
ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
ExcelContent = ReadExcel().get_data(FilePath=ExlFilePath, SheetName='07-版本管理')
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_VersionManagement_Module(unittest.TestCase):
|
||||
@allure.story("管理后台:版本管理模块")
|
||||
@ddt.data(*ExcelContent)
|
||||
def test_version_management(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 版本管理模块接口
|
||||
'''
|
||||
''' step01- 前置数据、接口信息描述等 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:版本管理 模块接口自动化测试")
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口 '''
|
||||
if requestType_c == 'POST':
|
||||
# 新建、查询
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
if "查询" not in caseName_c:
|
||||
ActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("07_CreateVersionManagementID.txt", str(ActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 版本管理(草稿)ID 失败!")
|
||||
else:
|
||||
if requestType_c == "PUT":
|
||||
ActIDList = Txt().read_txt("07_CreateVersionManagementID.txt")
|
||||
LOGGER.info(f"---新建并发布的 版本管理ID list为:{ActIDList}")
|
||||
ActID = ActIDList[0]
|
||||
if ActID not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{VersionID}", ActID)
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(
|
||||
method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
else:
|
||||
ActIDList = Txt().read_txt("07_CreateVersionManagementID.txt")
|
||||
LOGGER.info(f"---新建并发布的 版本管理ID list为:{ActIDList}")
|
||||
for i in range(len(ActIDList)):
|
||||
# 暂停、重启、结束、删除
|
||||
ActId = ActIDList[i]
|
||||
if ActId not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{VersionID}", str(ActId))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(
|
||||
method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
|
||||
# ''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, AssertionError(f"---断言失败!")
|
||||
LOGGER.info(f">>> {caseModule_c}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
106
YiMao/scripts/test_08UpgradeTask.py
Normal file
106
YiMao/scripts/test_08UpgradeTask.py
Normal file
@ -0,0 +1,106 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest,allure,ddt,time,json,requests,datetime
|
||||
from datetime import datetime,timedelta
|
||||
from configs.globalObj import LOGGER
|
||||
from configs.globalParams import *
|
||||
from YiMao.config.ApiInfo import *
|
||||
from commons.FileHandler import ReadExcel,Txt
|
||||
from commons.AssertLib import _assert_result
|
||||
# ExlFilePath = GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx'
|
||||
Content = ReadExcel().get_data(
|
||||
FilePath=GlobalPath['YMDataPath'] + '/YMHT_ApiTestCase_0.0.1.xlsx',
|
||||
SheetName='08-升级任务'
|
||||
)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class Test_UpgradeTask_Module(unittest.TestCase):
|
||||
@allure.story("管理后台:升级任务模块")
|
||||
@ddt.data(*Content)
|
||||
def test_upgrade_task(self, data):
|
||||
'''@Date:: 2024/5/20
|
||||
@Desc::
|
||||
管理后台 -> 升级任务模块接口
|
||||
'''
|
||||
''' step01- 前置数据、接口信息描述等 '''
|
||||
allure.dynamic.title(data['CaseName'])
|
||||
allure.dynamic.description("描述:升级任务 模块接口自动化测试")
|
||||
|
||||
caseModule_c = data['BusinessModule'] # 用例编号
|
||||
caseNO_c = data['NO.'] # 用例编号
|
||||
caseName_c = data['CaseName'] # 用例名称
|
||||
requestType_c = str(data['RequestType']) # 请求方式
|
||||
expStaCode_c = data['ExpStatusCode'] # 预期的状态码
|
||||
expRespJson_c = eval(data['RespJson']) # 预期的返回体
|
||||
LOGGER.info(f">>> 开始执行->{caseModule_c}接口自动化测试 <<<\n")
|
||||
LOGGER.info(f"---用例编号为:{caseNO_c}")
|
||||
LOGGER.info(f"---用例名称为:{caseName_c}")
|
||||
LOGGER.info(f"---请求方式为:{requestType_c}")
|
||||
# LOGGER.info(f"---请求Header为:{HEADERS}")
|
||||
LOGGER.info(f"---预期接口返回码为:{expStaCode_c}")
|
||||
LOGGER.info(f"---预期返回体为:{expRespJson_c}\n")
|
||||
|
||||
''' step02- 请求接口 '''
|
||||
if requestType_c == 'POST':
|
||||
# 新建、查询
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
LOGGER.info(f"---请求接口为:{api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
response = requests.request(method=requestType_c, url=api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
if "查询" not in caseName_c:
|
||||
ActID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("08_CreateUpgradeTaskID.txt", str(ActID))
|
||||
if not writeResult:
|
||||
LOGGER.error(f"---写入 升级任务(草稿)ID 失败!")
|
||||
else:
|
||||
if requestType_c == "PUT":
|
||||
# 编辑
|
||||
ActIDList = Txt().read_txt("08_CreateUpgradeTaskID.txt")
|
||||
LOGGER.info(f"---新建的 升级任务ID list为:{ActIDList}")
|
||||
ActID = ActIDList[0]
|
||||
if ActID not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{UpgradeID}", ActID)
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(
|
||||
method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
else:
|
||||
ActIDList = Txt().read_txt("08_CreateUpgradeTaskID.txt")
|
||||
LOGGER.info(f"---新建的 升级任务ID list为:{ActIDList}")
|
||||
for i in range(len(ActIDList)):
|
||||
# 启用、禁用、删除
|
||||
ActId = ActIDList[i]
|
||||
if ActId not in [None, '']:
|
||||
api_url = api_env[ProCfgData['ExecutionEnv']] + ManagementPlatformApi_zh[caseModule_c] # 请求地址
|
||||
last_api_url = api_url.replace("{UpgradeID}", str(ActId))
|
||||
LOGGER.info(f"---请求接口为:{last_api_url}")
|
||||
payload_c = json.dumps(eval(data['Payload']), indent=4, ensure_ascii=False) # 请求体为json格式
|
||||
LOGGER.info(f"---请求体为:{payload_c}\n")
|
||||
time.sleep(0.5)
|
||||
response = requests.request(
|
||||
method=requestType_c, url=last_api_url, headers=HEADERS, data=payload_c)
|
||||
rspJson = response.json()
|
||||
LOGGER.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
LOGGER.info(f"---接口返回体为:: {json.dumps(response.json(), indent=4, ensure_ascii=False)}\n")
|
||||
|
||||
|
||||
''' step03- 断言处理 '''
|
||||
assert _assert_result(rspJson, expRespJson_c, LOGGER) == True, AssertionError(f"---断言失败!")
|
||||
LOGGER.info(f">>> {caseModule_c}接口请求 & 断言执行结束 <<<\n\n")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
Reference in New Issue
Block a user