test_bid_review2.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import requests, json, time
  2. BASE = 'http://localhost:8000/api/v1'
  3. # 1. 登录
  4. r = requests.post(f'{BASE}/auth/login', json={'username': 'bidder01', 'password': 'Bidder@123456'})
  5. bidder_token = r.json()['access_token']
  6. bidder_headers = {'Authorization': f'Bearer {bidder_token}'}
  7. r = requests.post(f'{BASE}/auth/login', json={'username': 'expert01', 'password': 'Expert@123456'})
  8. expert_token = r.json()['access_token']
  9. expert_headers = {'Authorization': f'Bearer {expert_token}', 'Content-Type': 'application/json'}
  10. print('✅ 登录成功(投标人+评审专家)')
  11. # 2. 提交投标文件
  12. print('\n=== 提交投标文件 ===')
  13. with open('/Users/ligang/Desktop/TenderAgent/tests/fixtures/test_bid_review_answer.docx', 'rb') as f:
  14. r = requests.post(f'{BASE}/bid_review/submit',
  15. headers=bidder_headers,
  16. data={'bid_review_id': 'aaaaaaaa-0000-0000-0000-000000000001'},
  17. files={'file': ('test_bid_review_answer.docx', f,
  18. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')})
  19. print(f'状态码: {r.status_code}')
  20. if r.status_code != 202:
  21. print(f'错误: {r.text}')
  22. exit(1)
  23. submission_id = r.json()['submission_id']
  24. print(f'submission_id: {submission_id}')
  25. # 3. 轮询,最多等4分钟
  26. print('\n等待 AI 评分完成(最多4分钟)...')
  27. for i in range(48):
  28. time.sleep(5)
  29. r = requests.get(f'{BASE}/bid_review/pending-reviews', headers=expert_headers)
  30. if r.status_code == 200:
  31. items = r.json().get('items', [])
  32. sub = next((x for x in items if x['submission_id'] == submission_id), None)
  33. if sub:
  34. print(f'\n [{(i+1)*5}s] ✅ 进入待确认列表!')
  35. pr = sub['pre_review']
  36. print(f' AI预评分得分: {pr["total_score"]}/{pr["full_score"]}')
  37. print(f' 需复核题数: {pr["needs_review_count"]}')
  38. if sub.get('weak_points'):
  39. wp_tags = [wp.get('tag', '?') for wp in sub['weak_points'][:3]]
  40. print(f' 前3个薄弱点: {wp_tags}')
  41. break
  42. if (i+1) % 6 == 0:
  43. print(f' [{(i+1)*5}s] 仍在处理中...')
  44. else:
  45. print('❌ 超时,处理未完成')
  46. exit(1)
  47. # 4. 评审专家获取详情
  48. print('\n=== 获取预评分详情 ===')
  49. r = requests.get(f'{BASE}/bid_review/submissions/{submission_id}/review', headers=expert_headers)
  50. print(f'状态码: {r.status_code}')
  51. if r.status_code == 200:
  52. d = r.json()
  53. s = d['pre_review_summary']
  54. print(f'总分: {s["total_score"]}/{s["full_score"]} ({s["score_rate"]*100:.1f}%)')
  55. for q in s.get('by_question', [])[:4]:
  56. print(f' Q{q["question_no"]} ({q["question_type"]}): {q.get("score",0)}/{q.get("full_score",0)}分, 需复核={q.get("needs_review",False)}')
  57. print(f'薄弱点数: {len(d.get("weak_points", []))}')
  58. if d.get('weak_points_summary'):
  59. print(f'薄弱点摘要: {d["weak_points_summary"][:150]}')
  60. # 5. 专家确认
  61. print('\n=== 专家确认发布 ===')
  62. r = requests.post(f'{BASE}/bid_review/submissions/{submission_id}/confirm',
  63. headers=expert_headers,
  64. json={'action': 'approve', 'modifications': []})
  65. print(f'状态码: {r.status_code}')
  66. if r.status_code == 200:
  67. result = r.json()
  68. print(f'✅ 发布成功!')
  69. print(f'最终得分: {result["final_score"]}/{result["full_score"]} ({result["score_rate"]*100:.1f}%)')
  70. print(f'薄弱点数: {len(result["weak_points"])}')
  71. if result.get("weak_points_summary"):
  72. print(f'摘要: {result["weak_points_summary"][:200]}')
  73. else:
  74. print(f'错误: {r.text[:200]}')