锁定缴费校验失败时整单回滚,避免样本半成功落库;前端禁止删除锁定缴费样本,改码走更正编码。同步落地样本更正、采集微信通知、OA提及未读、细胞产品套餐与相关迁移文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
"""已落库样本编码在协议编辑中不可修改。"""
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from app.crud.collection_protocol import validate_persisted_sample_codes_immutable
|
|
|
|
|
|
def _row(*, sid="ps-1", code="OLD-001", code_id="pool-1"):
|
|
return SimpleNamespace(id=sid, sample_code=code, sample_code_id=code_id)
|
|
|
|
|
|
def test_rejects_code_change_when_persisted_id_present():
|
|
existing = [_row()]
|
|
with pytest.raises(ValueError, match="更正编码"):
|
|
validate_persisted_sample_codes_immutable(
|
|
existing,
|
|
[{"id": "ps-1", "sampleCode": "NEW-001", "sampleCodeId": "pool-1"}],
|
|
)
|
|
|
|
|
|
def test_rejects_code_id_change_when_persisted_id_present():
|
|
existing = [_row()]
|
|
with pytest.raises(ValueError, match="更正编码"):
|
|
validate_persisted_sample_codes_immutable(
|
|
existing,
|
|
[{"id": "ps-1", "sampleCode": "OLD-001", "sampleCodeId": "pool-other"}],
|
|
)
|
|
|
|
|
|
def test_allows_same_code_for_persisted_sample():
|
|
existing = [_row()]
|
|
validate_persisted_sample_codes_immutable(
|
|
existing,
|
|
[{"id": "ps-1", "sampleCode": "OLD-001", "sampleCodeId": "pool-1"}],
|
|
)
|
|
|
|
|
|
def test_allows_new_sample_without_id():
|
|
existing = [_row()]
|
|
validate_persisted_sample_codes_immutable(
|
|
existing,
|
|
[
|
|
{"id": "ps-1", "sampleCode": "OLD-001", "sampleCodeId": "pool-1"},
|
|
{"sampleCode": "NEW-002", "sampleCodeId": "pool-2"},
|
|
],
|
|
)
|
|
|
|
|
|
def test_ignores_unknown_id_as_new_sample():
|
|
existing = [_row()]
|
|
validate_persisted_sample_codes_immutable(
|
|
existing,
|
|
[{"id": "ps-unknown", "sampleCode": "ANY", "sampleCodeId": "x"}],
|
|
)
|
|
|
|
|
|
def test_trims_before_compare():
|
|
existing = [_row(code="OLD-001", code_id="pool-1")]
|
|
validate_persisted_sample_codes_immutable(
|
|
existing,
|
|
[{"id": "ps-1", "sample_code": " OLD-001 ", "sample_code_id": " pool-1 "}],
|
|
)
|