# Py_study **Repository Path**: every-years/py_study ## Basic Information - **Project Name**: Py_study - **Description**: python学习专用 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-01 - **Last Updated**: 2025-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # API测试框架 一个可扩展的Python API测试框架,支持签名生成、RSA加密、接口测试等功能。 ## 项目结构 api_test_framework/ ├── config/ # 配置文件 │ ├── settings.py # 主配置 │ ├── endpoints.py # 接口端点 │ └── test_data.py # 测试数据 ├── core/ # 核心模块 │ ├── signer.py # 签名加密 │ ├── client.py # 请求客户端 │ └── utils.py # 工具函数 ├── apis/ # 接口模块 │ ├── base_api.py # 接口基类 │ ├── user_api.py # 用户接口 │ └── (新增接口文件) # 后续新增 ├── tests/ # 测试用例 │ ├── test_user.py # 用户测试 │ └── (新增测试文件) # 后续新增 ├── run_tests.py # 测试执行入口 ├── api_runner.py # API执行器 └── requirements.txt # 依赖包 2. 配置 修改 config/settings.py 中的配置: BASE_URL: 你的API基础地址 RSA_PUBLIC_KEY: 你的RSA公钥 SECRET_KEY: 你的通用密钥 在 config/endpoints.py 中添加新的接口路径 3. 运行测试 运行所有测试 python run_tests.py --all 运行API功能测试 bash python run_tests.py --api 运行特定测试 bash python run_tests.py --test tests.test_user 4. 使用API执行器 列出所有API bash python api_runner.py --list 测试签名功能 bash python api_runner.py --test-sign 执行API调用 bash # 发送短信 python api_runner.py --module user --action send_sms # 手机号登录(带参数) python api_runner.py --module user --action phone_login --params '{"phone":"15190478078","code":"1234"}' 添加新接口 1. 添加接口端点 在 config/endpoints.py 的对应模块中添加新的接口路径: python # 例如,在USER模块中添加 USER = { "send_sms": "/user/pb/api/app/user/v1/sendSms", "phone_login": "/user/pb/api/app/user/v1/phoneLogin", # 新增接口 "new_api": "/user/pb/api/app/user/v1/newApi" } 2. 添加测试数据(可选) 在 config/test_data.py 中添加测试数据: python USER = { # ... 已有数据 "new_api": { "param1": "value1", "param2": "value2" } } 3. 创建接口类 在 apis/ 目录下创建新的接口文件或扩展现有文件: python # 在 user_api.py 中添加新方法 def new_api(self, param1=None, param2=None, **kwargs): """新接口""" params = TestData.get_test_data('USER', 'new_api') # 更新参数 if param1: params['param1'] = param1 if param2: params['param2'] = param2 params.update(kwargs) return self.request('POST', 'new_api', data=params) 4. 添加测试用例 在 tests/ 目录下创建新的测试文件或扩展现有文件: python def test_new_api(self): """测试新接口""" result = self.api.new_api(param1="test1", param2="test2") self.assertTrue(result['success']) self.assertEqual(result['status_code'], 200)