简单SQL测试.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import requests
  4. import time
  5. import json
  6. def test_sql_fix():
  7. """测试SQL修复是否成功"""
  8. print("=== 学生信息管理SQL修复测试 ===")
  9. # 等待服务启动
  10. print("等待服务启动...")
  11. time.sleep(60)
  12. base_url = "http://localhost:8080"
  13. # 登录
  14. print("1. 尝试登录...")
  15. login_data = {
  16. "username": "admin",
  17. "password": "admin123"
  18. }
  19. try:
  20. response = requests.post(f"{base_url}/login", json=login_data, timeout=10)
  21. if response.status_code == 200:
  22. result = response.json()
  23. if result.get('code') == 200:
  24. token = result.get('data', {}).get('access_token')
  25. print("✅ 登录成功")
  26. # 测试查询
  27. print("2. 测试学生信息查询...")
  28. headers = {
  29. 'Authorization': f'Bearer {token}',
  30. 'Content-Type': 'application/json'
  31. }
  32. # 基础查询
  33. response = requests.get(f"{base_url}/xg/studentInfo/list",
  34. params={'pageNum': 1, 'pageSize': 10},
  35. headers=headers, timeout=10)
  36. if response.status_code == 200:
  37. result = response.json()
  38. if result.get('code') == 200:
  39. print("✅ 基础查询成功")
  40. # 性别查询(之前报错的查询)
  41. print("3. 测试性别查询...")
  42. response = requests.get(f"{base_url}/xg/studentInfo/list",
  43. params={'pageNum': 1, 'pageSize': 10, 'gender': 'M'},
  44. headers=headers, timeout=10)
  45. if response.status_code == 200:
  46. result = response.json()
  47. if result.get('code') == 200:
  48. print("🎉 性别查询成功!SQL修复生效!")
  49. return True
  50. else:
  51. print(f"❌ 性别查询失败: {result.get('msg')}")
  52. else:
  53. print(f"❌ 性别查询请求失败: {response.status_code}")
  54. else:
  55. print(f"❌ 基础查询失败: {result.get('msg')}")
  56. else:
  57. print(f"❌ 基础查询请求失败: {response.status_code}")
  58. else:
  59. print(f"❌ 登录失败: {result.get('msg')}")
  60. else:
  61. print(f"❌ 登录请求失败: {response.status_code}")
  62. except Exception as e:
  63. print(f"❌ 测试异常: {str(e)}")
  64. return False
  65. if __name__ == "__main__":
  66. success = test_sql_fix()
  67. if success:
  68. print("\n🎉 SQL修复测试通过!")
  69. else:
  70. print("\n❌ SQL修复测试失败,请检查服务状态")