quick_test.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import urllib.request
  2. import urllib.error
  3. import json
  4. url = "http://localhost:8000/api/templates?machine_model=x11&device_type=wash&template_type=common"
  5. try:
  6. req = urllib.request.Request(url)
  7. with urllib.request.urlopen(req) as response:
  8. templates = json.loads(response.read().decode('utf-8'))
  9. print(f"获取到 {len(templates)} 个模板")
  10. if templates:
  11. tpl = templates[0]
  12. print(f"测试: {tpl['name']}")
  13. # 测试预览
  14. preview_url = "http://localhost:8000/api/templates/preview"
  15. payload = json.dumps({
  16. "template_body": tpl['template_body'],
  17. "parameters": {}
  18. }).encode('utf-8')
  19. req2 = urllib.request.Request(preview_url, data=payload, headers={'Content-Type': 'application/json'})
  20. with urllib.request.urlopen(req2) as response2:
  21. result = json.loads(response2.read().decode('utf-8'))
  22. text = result.get('rendered_text', '')
  23. print(f"✅ 预览成功: {len(text)}字")
  24. print(f"结果: {text[:200]}")
  25. except Exception as e:
  26. print(f"❌ 错误: {e}")