48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
|
|
import sys
|
||
|
|
import os
|
||
|
|
import logging
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
# 添加项目根目录到系统路径,以便导入模块
|
||
|
|
project_root = str(Path(__file__).parent.parent)
|
||
|
|
sys.path.insert(0, project_root)
|
||
|
|
|
||
|
|
# 配置日志
|
||
|
|
logging.basicConfig(level=logging.INFO,
|
||
|
|
format='%(asctime)s - %(levelname)s - %(name)s - [%(funcName)s:%(lineno)d] - %(message)s')
|
||
|
|
|
||
|
|
# 导入需要测试的模块
|
||
|
|
from apis.gc_api import GcApi
|
||
|
|
|
||
|
|
def test_gc_api():
|
||
|
|
"""测试 GcApi 的 get_gc_info 方法是否能正确处理 form-data 格式的请求"""
|
||
|
|
print("开始测试 GcApi.get_gc_info 方法...")
|
||
|
|
|
||
|
|
# 创建 GcApi 实例
|
||
|
|
gc_api = GcApi()
|
||
|
|
|
||
|
|
# 测试工程号
|
||
|
|
test_gc_code = "JTPD25060003"
|
||
|
|
|
||
|
|
# 调用方法
|
||
|
|
print(f"使用工程号 {test_gc_code} 调用 get_gc_info...")
|
||
|
|
response = gc_api.get_gc_info(test_gc_code)
|
||
|
|
|
||
|
|
# 打印结果
|
||
|
|
print(f"API 响应: {response}")
|
||
|
|
|
||
|
|
if response:
|
||
|
|
print("测试成功: API 返回了有效响应")
|
||
|
|
else:
|
||
|
|
print("测试失败: API 返回了空响应")
|
||
|
|
|
||
|
|
# 检查响应格式
|
||
|
|
if isinstance(response, dict) and "status" in response:
|
||
|
|
print(f"响应状态: {response.get('status', False)}")
|
||
|
|
print(f"响应消息: {response.get('message', '')}")
|
||
|
|
print(f"响应数据: {response.get('data', None)}")
|
||
|
|
else:
|
||
|
|
print(f"响应格式不符合预期: {response}")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
test_gc_api()
|