| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import requests
- import json
- BASE_URL = "http://localhost:8448"
- CREATE_API_URL = f"{BASE_URL}/watershed/model"
- LIST_API_URL = f"{BASE_URL}/watershed/model/list/test"
- def test_create_model():
- print("开始测试创建模型接口...")
- try:
- # 创建模型的测试数据
- test_data = {
- "name": "测试模型",
- "type": "RESERVOIR",
- "format": "OBJ",
- "uploadUnit": "测试单位",
- "status": "NORMAL",
- "coordinates": "116.403874,39.915168"
- }
-
- print(f"请求 URL: {CREATE_API_URL}")
- print(f"请求数据: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
-
- # 发送 POST 请求
- response = requests.post(CREATE_API_URL, json=test_data)
- print(f"响应状态码: {response.status_code}")
- print(f"响应内容:\n{response.text}")
-
- if response.status_code == 200:
- data = response.json()
- print("\n✅ 创建成功")
- print(f"响应数据结构: {json.dumps(data, indent=2, ensure_ascii=False)}")
-
- if 'data' in data and data['data']:
- model = data['data']
- print("\n创建的模型信息:")
- for key in model.keys():
- print(f" {key}: {model[key]}")
-
- # 检查创建时间和更新时间是否已设置
- if 'created_at' in model and model['created_at']:
- print("\n✅ 创建时间已正确设置")
- else:
- print("\n❌ 创建时间未设置")
-
- if 'updated_at' in model and model['updated_at']:
- print("✅ 更新时间已正确设置")
- else:
- print("❌ 更新时间未设置")
-
- # 查询模型列表,检查是否包含刚刚创建的模型
- print("\n\n查询模型列表:")
- list_response = requests.get(LIST_API_URL, params={'page': 1, 'size': 10})
- print(f"列表查询响应状态码: {list_response.status_code}")
-
- if list_response.status_code == 200:
- list_data = list_response.json()
- print(f"列表查询成功,共找到 {list_data['total']} 个模型")
-
- if list_data['rows']:
- print("\n第一个模型的字段:")
- first_model = list_data['rows'][0]
- for key in first_model.keys():
- print(f" {key}: {first_model[key]}")
-
- else:
- print(f"\n❌ 请求失败: {response.text}")
-
- except Exception as e:
- print(f"\n❌ 请求发生异常: {e}")
- if __name__ == "__main__":
- test_create_model()
|