This commit is contained in:
Your Name
2026-11-26 17:17:43 +08:00
parent be79e09c83
commit 301c04ca90
8 changed files with 515 additions and 125 deletions
+59
View File
@@ -318,6 +318,65 @@ def test_doctor_enrollment_binds_explicitly_after_provider_confirmation(
dialog.close()
def test_doctor_enrollment_rejection_reason_is_forwarded_without_identifiers() -> None:
reasons = iter([
"e签宝 startDoctorIdentity 失败(PROVIDER_30500121):开方医生姓名未通过核身校验",
"手机号 13800138000 未通过校验",
])
def post(endpoint: str, payload: dict[str, Any], **_kwargs: Any) -> dict[str, Any]:
raise ApiBusinessError(next(reasons), data=payload)
repository = RemoteDoctorRepository(SimpleNamespace(get=None, post=post))
with pytest.raises(ApiBusinessError, match="开方医生姓名未通过核身校验") as raised:
repository.start_esign_doctor("13800138000")
assert raised.value.data is None and raised.value.__context__ is None
with pytest.raises(ApiBusinessError, match="^医生人脸认证启动状态待确认$"):
repository.start_esign_doctor("13800138000")
def test_doctor_enrollment_start_failure_keeps_mobile_form(immediate: None) -> None:
attempts: list[str] = []
result: dict[str, Any] = {"enabled": True, "status": "unbound"}
def start(mobile: str) -> dict[str, Any]:
attempts.append(mobile)
if len(attempts) == 1:
raise ApiBusinessError("开方医生姓名未通过核身校验")
return {**result, "status": "authenticating", "auth_url": "https://smlt.esign.cn/doctor"}
repository = SimpleNamespace(get_esign_doctor_status=lambda: result, start_esign_doctor=start)
dialog = doctor_module.EsignDoctorDialog(repository)
dialog.show()
dialog.mobile_input.setText("13800138000")
dialog.start_button.click()
assert "开方医生姓名未通过核身校验" in dialog.banner.label.text()
assert dialog.identity_view is None and dialog.mobile_form.isVisible()
assert dialog.mobile_input.text() == "" and dialog.start_button.isEnabled()
dialog.mobile_input.setText("13800138000")
dialog.start_button.click()
assert attempts == ["13800138000", "13800138000"]
assert dialog.identity_view.urls == ["https://smlt.esign.cn/doctor"]
dialog.close()
def test_doctor_retry_mobile_failure_does_not_reopen_previous_flow(immediate: None) -> None:
result = {"enabled": True, "status": "authenticating", "auth_url": "https://smlt.esign.cn/old"}
def start(_mobile: str) -> dict[str, Any]:
raise ApiBusinessError("医师认证暂不可用,请稍后重试")
repository = SimpleNamespace(get_esign_doctor_status=lambda: result, start_esign_doctor=start)
dialog = doctor_module.EsignDoctorDialog(repository)
dialog.show()
dialog.change_mobile_button.click()
dialog.mobile_input.setText("13800138000")
dialog.start_button.click()
assert dialog.identity_view is None and dialog.mobile_form.isVisible()
assert "暂不可用" in dialog.banner.label.text()
dialog.close()
def test_enrolled_doctor_authorizes_quicksign_without_reentering_identity(immediate: None) -> None:
calls: list[str] = []
result = {"enabled": True, "status": "ready", "cert_expires_at": 2_000_000_000,
+58 -3
View File
@@ -758,9 +758,11 @@ def test_signing_preview_uses_full_seed_and_updates_visible_signatures(
})
preview = PrescriptionSigningPreview(SimpleNamespace(get_prescription=unexpected_detail), prescription)
assert preview.paper is not None and preview.paper.isReadOnly()
assert preview.paper._watermark_text == "处方联"
document = preview.paper.document()
for text in ("虚构患者", "测试诊断", "白术 (6克)", "18克", "一次20ml"):
for text in ("虚构患者", "测试诊断", "白术", "6克", "天数"):
assert text in document.toPlainText()
assert "药房联" not in document.toPlainText() and "18克" not in document.toPlainText()
revision = document.revision()
preview.set_esign_state({"status": "pending", "message": "等待核验"})
@@ -772,7 +774,7 @@ def test_signing_preview_uses_full_seed_and_updates_visible_signatures(
"review_signature_time": 1795000017,
}
preview.set_esign_state(signed)
for text in ("签名医生", "审核药师姓名", "白术 (6克)"):
for text in ("签名医生", "审核药师姓名", "白术"):
assert text in document.toPlainText()
revision = document.revision()
preview.set_esign_state(signed | {"review_signature_time": 1795000020})
@@ -807,7 +809,60 @@ def test_signing_preview_retries_wrong_detail_and_ignores_stale_response(
requests[1][1](seed | {"patient_name": "当前患者", "herbs": herbs})
assert preview.paper is not None
text = preview.paper.toPlainText()
assert "当前患者" in text and "甘草 (3克)" in text and "签名医生" in text
assert "当前患者" in text and "甘草\n3克" in text and "签名医生" in text
def test_signing_preview_edits_prescription_until_signing_starts(
application: QApplication,
immediate_async: None,
monkeypatch: pytest.MonkeyPatch,
) -> None:
herbs = [{"name": "白术", "dosage": 6}]
detail = {"id": 74, "patient_name": "原患者", "audit_status": 0, "herbs": herbs}
updates: list[tuple[int, dict[str, Any]]] = []
editors: list[dict[str, Any]] = []
def update(prescription_id: int, *, changes: dict[str, Any]) -> dict[str, Any]:
updates.append((prescription_id, changes))
detail["patient_name"] = changes["patient_name"]
return {"id": prescription_id, **changes}
class FakeEditor:
def __init__(self, _repository: Any, prescription: Any, *, mode: str, save_draft: Any, **_kwargs: Any) -> None:
assert mode == "edit"
editors.append(prescription)
self.save_draft = save_draft
self.saved_draft = None
def exec(self) -> QDialog.DialogCode:
self.saved_draft = self.save_draft({"patient_name": "修改后患者"})
return QDialog.DialogCode.Accepted
def payload(self) -> dict[str, Any]:
return {}
def deleteLater(self) -> None: # noqa: N802 - Qt compatibility
pass
monkeypatch.setattr(dialog_module, "PrescriptionEditorDialog", FakeEditor)
repository = SimpleNamespace(get_prescription=lambda _id: dict(detail), update_prescription=update)
preview = PrescriptionSigningPreview(repository, {"id": 74, "esign": {"required": True, "status": "pending"}})
saved: list[Any] = []
preview.prescription_saved.connect(saved.append)
assert not preview.edit_button.isHidden() and not preview.edit_button.isEnabled()
preview.set_edit_allowed(True)
assert preview.edit_button.isEnabled()
preview.edit_button.click()
assert updates == [(74, {"patient_name": "修改后患者"})]
assert editors[0]["patient_name"] == "原患者" and editors[0]["esign"]["status"] == "pending"
assert saved and "修改后患者" in preview.paper.toPlainText()
preview.set_esign_state({"required": True, "status": "authenticating"})
assert preview.edit_button.isHidden()
preview.set_esign_state({"required": True, "status": "pending"})
preview.set_edit_allowed(False)
assert not preview.edit_button.isHidden() and not preview.edit_button.isEnabled()
def test_signing_preview_renders_an_intentionally_empty_saved_prescription(