-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_edit_function.py
More file actions
141 lines (125 loc) · 4.47 KB
/
test_edit_function.py
File metadata and controls
141 lines (125 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试病历编辑功能
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import requests
import json
BASE_URL = "http://localhost:8000"
def test_edit_functionality():
"""测试病历编辑功能"""
print("测试病历编辑功能...")
# 1. 管理员登录
print("1. 管理员登录...")
login_data = {
"username": "admin",
"password": "admin123"
}
try:
response = requests.post(f"{BASE_URL}/api/v1/auth/login", json=login_data)
if response.status_code == 200:
token = response.json()['token']
print("✅ 登录成功")
else:
print("❌ 登录失败")
return False
except Exception as e:
print(f"❌ 登录请求失败: {e}")
return False
# 2. 创建一个测试病历
print("2. 创建测试病历...")
headers = {"Authorization": f"Bearer {token}"}
record_data = {
"patient_id": 1,
"record_type": "门诊",
"title": "测试病历",
"visit_date": "2024-01-15",
"symptoms": "头痛、发热",
"diagnosis": "普通感冒",
"treatment": "多休息、多喝水",
"prescription": "感冒药",
"notes": "测试病历"
}
try:
response = requests.post(f"{BASE_URL}/api/v1/medical-records", json=record_data, headers=headers)
if response.status_code == 200:
record_id = response.json()['record_id']
print(f"✅ 病历创建成功,ID: {record_id}")
else:
print("❌ 病历创建失败")
return False
except Exception as e:
print(f"❌ 创建病历请求失败: {e}")
return False
# 3. 获取病历用于编辑
print("3. 获取病历用于编辑...")
try:
response = requests.get(f"{BASE_URL}/api/v1/medical-records/1/{record_id}/edit", headers=headers)
if response.status_code == 200:
record = response.json()['record']
print("✅ 获取病历成功")
print(f" 原标题: {record['title']}")
else:
print("❌ 获取病历失败")
return False
except Exception as e:
print(f"❌ 获取病历请求失败: {e}")
return False
# 4. 更新病历
print("4. 更新病历...")
update_data = {
"record_type": "门诊",
"title": "更新后的测试病历",
"visit_date": "2024-01-16",
"symptoms": "头痛、发热(已好转)",
"diagnosis": "感冒恢复期",
"treatment": "继续休息、加强营养",
"prescription": "维生素补充剂",
"notes": "更新后的测试病历"
}
try:
response = requests.put(f"{BASE_URL}/api/v1/medical-records/1/{record_id}", json=update_data, headers=headers)
if response.status_code == 200:
print("✅ 病历更新成功")
print(f" 新标题: {update_data['title']}")
else:
print("❌ 病历更新失败")
print(f" 错误信息: {response.json().get('message', '未知错误')}")
return False
except Exception as e:
print(f"❌ 更新病历请求失败: {e}")
return False
# 5. 验证更新结果
print("5. 验证更新结果...")
try:
response = requests.get(f"{BASE_URL}/api/v1/medical-records/1/{record_id}/edit", headers=headers)
if response.status_code == 200:
updated_record = response.json()['record']
if updated_record['title'] == update_data['title']:
print("✅ 病历标题已更新")
print(f" 验证标题: {updated_record['title']}")
else:
print("❌ 病历标题未更新")
return False
else:
print("❌ 验证失败")
return False
except Exception as e:
print(f"❌ 验证请求失败: {e}")
return False
print("\n🎉 所有编辑功能测试通过!")
return True
if __name__ == "__main__":
print("病历编辑功能测试")
print("==================")
print("请确保系统正在运行在 http://localhost:8000")
print("按回车键开始测试...")
input()
success = test_edit_functionality()
if success:
print("\n✅ 测试完成,编辑功能正常工作")
else:
print("\n❌ 测试失败,请检查系统日志")