| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- # 完整测试预览功能
- import requests
- import json
- API_BASE = "http://localhost:8000/api"
- print("=" * 80)
- print("测试1: Common模板 - PIN_CONSECUTIVE分支")
- print("=" * 80)
- # 获取common模板
- resp = requests.get(f"{API_BASE}/templates/x11_wash_common")
- common_tpl = resp.json()
- body = common_tpl['template_body']
- # 添加输出语句
- body_with_output = body + "\n\n{{ prefix_message }}"
- # 测试PIN_CONSECUTIVE分支
- resp = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": body_with_output,
- "parameters": {
- "rerank_reason": "PIN_CONSECUTIVE",
- "program_id": "1",
- "period": "早上",
- "changed_params": {
- "setTemp": 40,
- "speed": 12,
- "spinTime": 3,
- "washTime": 45
- }
- }
- })
- result = resp.json()
- print(f"Success: {result['success']}")
- print(f"Result: {result['result'][:200]}")
- print(f"Error: {result['error']}")
- print(f"Condition vars count: {len(result['condition_vars'])}")
- print(f"Data vars count: {len(result['data_vars'])}")
- print("\n" + "=" * 80)
- print("测试2: Common模板 - POPULAR分支")
- print("=" * 80)
- resp = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": body_with_output,
- "parameters": {
- "rerank_reason": "",
- "recommend_type": "POPULAR",
- "program_id": "15",
- "city": "青岛市",
- "period": "早上"
- }
- })
- result = resp.json()
- print(f"Success: {result['success']}")
- print(f"Result: {result['result'][:200]}")
- print(f"Error: {result['error']}")
- print("\n" + "=" * 80)
- print("测试3: 重新生成应该随机不同(连续5次)")
- print("=" * 80)
- results = []
- for i in range(5):
- resp = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": body_with_output,
- "parameters": {
- "rerank_reason": "PIN_CONSECUTIVE",
- "program_id": "1",
- "period": "早上"
- }
- })
- result = resp.json()
- results.append(result['result'])
- print(f"第{i+1}次: {result['result'][:100]}")
- # 检查是否有不同
- unique_results = set(results)
- print(f"\n5次生成中有 {len(unique_results)} 种不同结果")
- if len(unique_results) > 1:
- print("✅ 随机功能正常!")
- else:
- print("❌ 随机功能可能有问题")
- print("\n" + "=" * 80)
- print("测试4: 天气模板预览")
- print("=" * 80)
- # 获取天气模板
- resp = requests.get(f"{API_BASE}/templates/x11_wash_weather")
- weather_tpl = resp.json()
- weather_body = weather_tpl['template_body']
- print(f"Weather template length: {len(weather_body)}")
- if weather_body:
- resp = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": weather_body,
- "parameters": {
- "weather": "小雪",
- "city": "青岛市",
- "period": "早上"
- }
- })
-
- result = resp.json()
- print(f"Success: {result['success']}")
- print(f"Result: {result['result'][:200]}")
- print(f"Error: {result['error']}")
- else:
- print("天气模板为空")
- print("\n" + "=" * 80)
- print("测试完成")
- print("=" * 80)
|