fix(training): 修复出国培训规则培训bug
This commit is contained in:
1 parent
683f602475
commit
258098ea7b
13 files changed
+280
-26
No files matched your search
@@ -18,7 +18,7 @@ import pytest
|
||||
from app import db
|
||||
from app.core.errors import ValidationError
|
||||
from app.models import Agent, AgentGuide, TrainingConfig, TrainingConfigResource, TrainingRecord, User
|
||||
from app.services import training_config_service, training_service
|
||||
from app.services import lean_training_service, training_config_service, training_service
|
||||
from app.services.training_service import _grade_answer_details, _normalize_question_bank
|
||||
from app.api.chat import preview_support
|
||||
|
||||
@@ -236,6 +236,38 @@ def test_training_user_progress_round_trip_and_completion(client, app):
|
||||
assert record.completion_time is not None
|
||||
|
||||
|
||||
def test_overseas_regulations_video_completion_creates_passed_result(client, app):
|
||||
"""关键断言:自定义编码的出国规章培训完整观看视频后无需题库作答,也必须落库为一次完成。"""
|
||||
with app.app_context():
|
||||
user = _create_user(username="overseas_video_completion")
|
||||
agent = _create_training_agent(name="overseas_video_agent")
|
||||
db.session.add(TrainingConfig(
|
||||
training_type="overseas_policy_v2",
|
||||
name="出国规章培训",
|
||||
version="v1",
|
||||
status="published",
|
||||
))
|
||||
db.session.commit()
|
||||
|
||||
response = client.put("/api/user/training-record/progress", headers=_auth_headers(user), json={
|
||||
"agent_id": agent.id,
|
||||
"type": "overseas_policy_v2",
|
||||
"stage": "result",
|
||||
"score": 100,
|
||||
"passed": True,
|
||||
"attempt_count": 0,
|
||||
"answer_details": [],
|
||||
})
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.get_json()
|
||||
assert body["training_type"] == "overseas_policy_v2"
|
||||
assert body["stage"] == "result"
|
||||
assert body["passed"] is True
|
||||
assert body["status"] == "passed"
|
||||
assert isinstance(body["completion_time"], str) and body["completion_time"]
|
||||
|
||||
|
||||
def test_safety_training_progress_round_trip(client, app):
|
||||
"""安全培训应持久化培训版本、考试模式、三级状态和级别进度。"""
|
||||
with app.app_context():
|
||||
@@ -583,11 +615,34 @@ def test_training_admin_list_stats_and_export_share_one_fact_source(client, app)
|
||||
workbook = load_workbook(BytesIO(export_res.data))
|
||||
sheet = workbook.active
|
||||
rows = list(sheet.iter_rows(values_only=True))
|
||||
assert rows[0] == ("入职日期", "完成日期", "部门", "姓名", "工号", "分数", "考试次数", "状态")
|
||||
assert rows[0] == ("入职日期", "完成日期", "培训类型", "部门", "姓名", "工号", "分数", "考试次数", "状态")
|
||||
assert len(rows) == 3
|
||||
assert rows[1][2] == "生产一部"
|
||||
assert rows[2][2] == "生产一部"
|
||||
assert {rows[1][7], rows[2][7]} == {"passed", "failed"}
|
||||
assert rows[1][3] == "生产一部"
|
||||
assert rows[2][3] == "生产一部"
|
||||
assert {rows[1][8], rows[2][8]} == {"已通过", "未通过"}
|
||||
|
||||
|
||||
def test_lean_dashboard_export_uses_page_time_and_status_labels(monkeypatch):
|
||||
"""精益看板 Excel 必须复用页面的分钟级时间格式与中文状态文案。"""
|
||||
monkeypatch.setattr(
|
||||
lean_training_service,
|
||||
"list_dashboard",
|
||||
lambda task_id: {
|
||||
"task": {"week_index": 2, "week_key": "2026-09-14", "due_at": "2026-09-20T23:59:59"},
|
||||
"completed": [{"employee_id": "EMP-001", "name": "张三", "department": "生产部", "videos": [{"name": "精益视频", "watched_at": "2026-09-15T08:30:45"}], "status": "completed", "summary_text": "已完成学习", "completed_at": "2026-09-15T09:00:12"}],
|
||||
"incomplete": [{"employee_id": "EMP-002", "name": "李四", "department": "品质部", "videos": [], "status": "overdue", "summary_text": None, "completed_at": None}],
|
||||
"periods": [],
|
||||
},
|
||||
)
|
||||
|
||||
file_data, _ = lean_training_service.export_dashboard_excel(1)
|
||||
rows = list(load_workbook(BytesIO(file_data)).active.iter_rows(values_only=True))
|
||||
|
||||
assert rows[1][2] == "2026-09-20 23:59"
|
||||
assert rows[1][7] == "2026-09-15 08:30"
|
||||
assert rows[1][8] == "已完成"
|
||||
assert rows[1][10] == "2026-09-15 09:00"
|
||||
assert rows[2][8] == "已延期"
|
||||
|
||||
|
||||
def test_training_preview_proxy_reads_kb_storage_without_http_callback(monkeypatch, tmp_path, app):
|
||||
|
||||
Reference in new issue
Block a user