import os from time import sleep from common.myddt import ddt, data from common.handel_excel import HandleExcel from common.handle_db import HandleDB from common.handle_path import datadir from common.handle_requests import HandleRequests from common.handle_log import logger from common.handle_phone import get_new_phone from common.handle_conf import conf from common.handle_assert import HandleAssert from common.handle_data import replace_case_with_re # 获取用例数据 excel_path = os.path.join(datadir, "api_cases.xlsx") he = HandleExcel(excel_path, "register") cases = he.read_all_data() # print(cases) @ddt class TestRegisterApi(unittest.TestCase): @classmethod def setUp(cls) -> None: cls.hr = HandleRequests() cls.hd = HandleDB() @classmethod def tearDownClass(cls) -> None: cls.hd.close()
import unittest import os from jsonpath import jsonpath from common.myddt import ddt, data from common.handel_excel import HandleExcel from common.handle_path import datadir from common.handle_log import logger from common.handle_requests import HandleRequests from common.handle_data import Data, set_dataclass_attr_from_resp, replace_case_with_re from common.handle_assert import HandleAssert excel_path = os.path.join(datadir, "api_cases.xlsx") he = HandleExcel(excel_path, "recharge") cases = he.read_all_data() # print(cases) @ddt class TestRechargeApi(unittest.TestCase): @classmethod def setUpClass(cls) -> None: # 实例化HandleRequests类 cls.hr = HandleRequests() # 调用登录接口,从响应结果中获取token member_id # resp = cls.hr.send_requests("post", # "member/login", # {"mobile_phone": "13770830372", "pwd": "1234567890"}) # # 转换成字典,提取 # resp_dict = resp.json() # # cls.member_id = resp_dict["data"]["id"]
import os import unittest from common.handel_excel import HandleExcel from common.handle_path import datadir from common.handle_requests import HandleRequests from common.handle_log import logger from common.myddt import ddt, data from common.handle_data import replace_case_with_re, Data, set_dataclass_attr_from_resp excel_path = os.path.join(datadir, "api_cases.xlsx") he = HandleExcel(excel_path, "business") cases = he.read_all_data() @ddt class TestBusinessApi(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.hr = HandleRequests() @data(*cases) def test_business_flow_api(self, case): logger.info("#################开始执行业务流接口#######################") # 替换 case = replace_case_with_re(case) # 请求 # 判断是否要添加token if hasattr(Data, "token"): resp = self.hr.send_requests(case["method"], case["url"], case["request_data"], token=getattr(Data, "token"))
import os import unittest from common.handel_excel import HandleExcel from common.handle_log import logger from common.myddt import ddt, data from common.handle_path import datadir from common.handle_data import Data, replace_case_with_re, set_dataclass_attr_from_resp from common.handle_requests import HandleRequests excel_path = os.path.join(datadir, "api_cases.xlsx") he = HandleExcel(excel_path, "add") cases = he.read_all_data() @ddt class TestAddBidApi(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.hr = HandleRequests() @data(*cases) def test_add_bid_api(self, case): logger.info( "########################开始执行添加项目接口#########################") # 替换 case = replace_case_with_re(case) logger.info("当前执行用例为:\n {}".format(case)) # 请求 # 判断是否需要传递token
import unittest import os from common.myddt import ddt, data from common.handel_excel import HandleExcel from common.handle_path import datadir from common.handle_log import logger from common.handle_requests import HandleRequests from common.handle_data import replace_case_with_re from common.handle_conf import conf excel_path = os.path.join(datadir, "api_cases.xlsx") he = HandleExcel(excel_path, "login") cases = he.read_all_data() # print(cases) @ddt class TestLoginApi(unittest.TestCase): @classmethod def setUpClass(cls) -> None: # 实例化HandleRequests类 cls.hr = HandleRequests() @data(*cases) def testLogin(self, case): logger.info("*****************开始执行登录接口用例**************************") # 替换需要替换的未注册的手机号 case = replace_case_with_re(case) # 替换需要替换的--系统中已存在的手机号--从配置文件读取 if case["request_data"].find("*phone*") != -1:
import os import unittest from common.handel_excel import HandleExcel from common.handle_path import datadir from common.handle_requests import HandleRequests from common.handle_log import logger from common.myddt import ddt, data from common.handle_data import replace_case_with_re, Data, set_dataclass_attr_from_resp excel_path = os.path.join(datadir, "api_cases.xlsx") he = HandleExcel(excel_path, "invest") cases = he.read_all_data() @ddt class TestInvestApi(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.hr = HandleRequests() @data(*cases) def test_invest_api(self, case): logger.info("#################开始执行投资接口#######################") # 替换 case = replace_case_with_re(case) # 请求 # 判断是否要添加token if hasattr(Data, "token"): resp = self.hr.send_requests(case["method"],