- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
专门测试课程ID 7的考试设置
|
|
"""
|
|
import asyncio
|
|
import json
|
|
import httpx
|
|
from datetime import datetime
|
|
|
|
BASE_URL = "http://localhost:8000"
|
|
|
|
async def main():
|
|
async with httpx.AsyncClient() as client:
|
|
# 1. 登录获取token
|
|
print("1. 登录管理员账号...")
|
|
login_resp = await client.post(
|
|
f"{BASE_URL}/api/v1/auth/login",
|
|
json={"username": "admin", "password": "Admin123!"}
|
|
)
|
|
token = login_resp.json()["data"]["token"]["access_token"]
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
|
|
# 2. 获取当前考试设置
|
|
print("\n2. 获取课程7的当前考试设置...")
|
|
get_resp = await client.get(
|
|
f"{BASE_URL}/api/v1/courses/7/exam-settings",
|
|
headers=headers
|
|
)
|
|
current_settings = get_resp.json()
|
|
print(f"当前设置: {json.dumps(current_settings['data'], indent=2, ensure_ascii=False)}")
|
|
|
|
# 3. 修改考试设置
|
|
print("\n3. 修改考试设置...")
|
|
new_settings = {
|
|
"single_choice_count": 30,
|
|
"multiple_choice_count": 15,
|
|
"true_false_count": 12,
|
|
"fill_blank_count": 8,
|
|
"duration_minutes": 150,
|
|
"difficulty_level": 4,
|
|
"is_enabled": True
|
|
}
|
|
save_resp = await client.post(
|
|
f"{BASE_URL}/api/v1/courses/7/exam-settings",
|
|
json=new_settings,
|
|
headers=headers
|
|
)
|
|
print(f"保存响应: {save_resp.json()}")
|
|
|
|
# 4. 再次获取验证
|
|
print("\n4. 再次获取考试设置验证保存...")
|
|
verify_resp = await client.get(
|
|
f"{BASE_URL}/api/v1/courses/7/exam-settings",
|
|
headers=headers
|
|
)
|
|
updated_settings = verify_resp.json()
|
|
print(f"更新后的设置: {json.dumps(updated_settings['data'], indent=2, ensure_ascii=False)}")
|
|
|
|
# 5. 验证数据
|
|
saved_data = updated_settings['data']
|
|
all_correct = (
|
|
saved_data['single_choice_count'] == 30 and
|
|
saved_data['multiple_choice_count'] == 15 and
|
|
saved_data['true_false_count'] == 12 and
|
|
saved_data['fill_blank_count'] == 8 and
|
|
saved_data['duration_minutes'] == 150 and
|
|
saved_data['difficulty_level'] == 4
|
|
)
|
|
|
|
if all_correct:
|
|
print("\n✅ 测试通过!考试设置保存和读取功能正常。")
|
|
else:
|
|
print("\n❌ 测试失败!数据未正确保存。")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|