refactor(in-transit-transfer): 行归属解耦、按行执行三层门禁并重构术语为匹配
- 行不迁移:匹配记录降级为评估留痕(scope/counts/hash 留痕不拦执行), 匹配/重查原地刷新行并续行级新鲜度(updated_at) - 执行改按行:POST /items/execute 三层门禁(行级新鲜度 TTL/文件版本对账/写前复查), Run 留痕不绑匹配记录;消失行 blocked_file_removed fail-closed 入异常池 - 恢复处理收敛为行级重查(batch-resume 删除);待处理池补齐匹配窗口字段, 排序改业务稳定键(收料日期→Invoice→created_at,操作不再引起跳位) - 首页待办看板四队列:可调拨明细/待恢复异常/已人工关闭/结果未知;「最近预检」移除; 收料日期默认 T-1 并加输入期限制;「重新查询 ERP」更名「重查」 - 术语重构 precheck→match:表 transfer_matchings、列 matching_id/matching_no/matching_hash、 API /matchings、单号前缀 MTG、状态值 prechecking→matching(迁移 rn1a2b3c4d5e6,模块未上线无兼容层) - 修复 integration_connector mapping 扇出嵌套丢行缺陷;对账结论:0 vs 30/40/36 系收料仓库映射曾指向错误账套 TGHX(已改 TGHX1),探针留档 backend/tmp - 测试:后端 in_transit_transfer+api+connector 393 passed;前端 chat 713 passed;build ✓
This commit is contained in:
1 parent
f9f5053f0b
commit
0cf3c24119
108 files changed
+3660
-2356
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""在途调拨预检 API 契约测试(L2,Flask test client)。
|
||||
"""在途调拨匹配 API 契约测试(L2,Flask test client)。
|
||||
|
||||
用途:验证 POST /prechecks 创建(含 envelope/权限/参数校验)与
|
||||
GET /prechecks/{id} 进度恢复;无权限 403、未认证 401。
|
||||
用途:验证 POST /matchings 创建(含 envelope/权限/参数校验)与
|
||||
GET /matchings/{id} 进度恢复;无权限 403、未认证 401。
|
||||
依赖:app fixture、client、issue_local_access_token、fakes/repo_fakes。
|
||||
逻辑:API 依赖经 deps._override 注入 Fake 替身;权限按 admin 放行或
|
||||
in_transit_transfer Agent 授权校验。
|
||||
@@ -27,11 +27,19 @@ def _jwt_headers(user: User) -> dict:
|
||||
|
||||
@pytest.fixture
|
||||
def transfer_deps(monkeypatch, dbs_ready_file):
|
||||
"""注入 Fake 预检依赖,并预置可执行库存。"""
|
||||
"""注入 Fake 匹配依赖,预置可执行库存,并把执行文件对账投影替换为 ready(sha=夹具 checksum)。"""
|
||||
deps, erp, _ = make_transfer_deps(dbs_ready_file)
|
||||
erp.seed_stock("MAT-001", "DBS-TRANSIT", "LOT-10", "1200")
|
||||
erp.seed_stock("MAT-002", "DBS-TRANSIT", "LOT-20", "1200")
|
||||
monkeypatch.setattr("app.services.in_transit_transfer.deps._override", deps)
|
||||
|
||||
def _resolve(*, source_code: str) -> dict:
|
||||
# 执行门禁③(文件版本对账)替身:来源恒 ready 且 sha 与夹具行版本戳同源。
|
||||
return {"file_status": "ready", "has_ready_file": True, "file_no": "REC-TEST", "file_sha256": "d" * 64}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.services.in_transit_transfer.execution_service.resolve_source_file_status", _resolve,
|
||||
)
|
||||
return deps
|
||||
|
||||
|
||||
@@ -87,9 +95,9 @@ def unauthorized_headers(app):
|
||||
return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||
|
||||
|
||||
def test_create_precheck_returns_envelope_with_precheck_id(app, client, admin_headers, transfer_deps):
|
||||
"""POST /prechecks → 201 envelope,data 含 precheck_id/hash/计数。"""
|
||||
response = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
def test_create_matching_returns_envelope_with_matching_id(app, client, admin_headers, transfer_deps):
|
||||
"""POST /matchings → 201 envelope,data 含 matching_id/hash/计数。"""
|
||||
response = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
})
|
||||
@@ -97,48 +105,48 @@ def test_create_precheck_returns_envelope_with_precheck_id(app, client, admin_he
|
||||
body = response.get_json()
|
||||
assert body["success"] is True
|
||||
data = body["data"]
|
||||
assert data["precheck_id"].startswith("TPC-")
|
||||
assert data["precheck_hash"].startswith("sha256:")
|
||||
assert data["matching_id"].startswith("MTG-")
|
||||
assert data["matching_hash"].startswith("sha256:")
|
||||
assert data["estimated_external_write_count"] == 2
|
||||
assert body.get("request_id")
|
||||
|
||||
|
||||
def test_create_precheck_requires_authentication(client):
|
||||
def test_create_matching_requires_authentication(client):
|
||||
"""未认证 → 401(envelope error)。"""
|
||||
response = client.post(f"{API_PREFIX}/prechecks", json={"source_codes": ["DBS-AWSBI"]})
|
||||
response = client.post(f"{API_PREFIX}/matchings", json={"source_codes": ["DBS-AWSBI"]})
|
||||
assert response.status_code == 401
|
||||
assert response.get_json()["success"] is False
|
||||
|
||||
|
||||
def test_create_precheck_forbidden_without_agent_permission(client, unauthorized_headers):
|
||||
def test_create_matching_forbidden_without_agent_permission(client, unauthorized_headers):
|
||||
"""无 in_transit_transfer Agent 权限 → 403。"""
|
||||
response = client.post(f"{API_PREFIX}/prechecks", headers=unauthorized_headers, json={
|
||||
response = client.post(f"{API_PREFIX}/matchings", headers=unauthorized_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
})
|
||||
assert response.status_code == 403
|
||||
assert response.get_json()["error"]["code"] == "AUTH.FORBIDDEN"
|
||||
|
||||
|
||||
def test_create_precheck_warehouse_manager_allowed(app, client, warehouse_headers, transfer_deps):
|
||||
"""持有 Agent 权限的仓库管理员可创建预检。"""
|
||||
response = client.post(f"{API_PREFIX}/prechecks", headers=warehouse_headers, json={
|
||||
def test_create_matching_warehouse_manager_allowed(app, client, warehouse_headers, transfer_deps):
|
||||
"""持有 Agent 权限的仓库管理员可创建匹配。"""
|
||||
response = client.post(f"{API_PREFIX}/matchings", headers=warehouse_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
})
|
||||
assert response.status_code == 201
|
||||
assert response.get_json()["data"]["precheck_id"]
|
||||
assert response.get_json()["data"]["matching_id"]
|
||||
|
||||
|
||||
def test_create_precheck_validates_source_codes(app, client, admin_headers, transfer_deps):
|
||||
def test_create_matching_validates_source_codes(app, client, admin_headers, transfer_deps):
|
||||
"""缺少 source_codes → 400 参数错误。"""
|
||||
response = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={"business_date": "2026-08-06"})
|
||||
response = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={"business_date": "2026-08-06"})
|
||||
assert response.status_code == 400
|
||||
assert response.get_json()["success"] is False
|
||||
|
||||
|
||||
def test_create_precheck_accepts_transfer_type_and_rejects_placeholder(app, client, admin_headers, transfer_deps):
|
||||
def test_create_matching_accepts_transfer_type_and_rejects_placeholder(app, client, admin_headers, transfer_deps):
|
||||
"""transfer_type 合法值放行;占位类型(类型2/3)与非法值 → 400 fail-closed。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
"transfer_type": "in_transit_to_hub",
|
||||
@@ -146,7 +154,7 @@ def test_create_precheck_accepts_transfer_type_and_rejects_placeholder(app, clie
|
||||
assert created.status_code == 201
|
||||
|
||||
for bad_type in ("hub_repair_out", "hub_to_hub", "bogus_type"):
|
||||
response = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
response = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
"transfer_type": bad_type,
|
||||
@@ -155,36 +163,88 @@ def test_create_precheck_accepts_transfer_type_and_rejects_placeholder(app, clie
|
||||
assert response.get_json()["success"] is False
|
||||
|
||||
|
||||
def test_restore_precheck_progress(app, client, admin_headers, transfer_deps):
|
||||
"""GET /prechecks/{id} 恢复预检进度(Hash/明细一致)。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
def test_restore_matching_progress(app, client, admin_headers, transfer_deps):
|
||||
"""GET /matchings/{id} 恢复匹配进度(Hash/明细一致)。"""
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
restored = client.get(f"{API_PREFIX}/prechecks/{created['precheck_id']}", headers=admin_headers)
|
||||
restored = client.get(f"{API_PREFIX}/matchings/{created['matching_id']}", headers=admin_headers)
|
||||
assert restored.status_code == 200
|
||||
body = restored.get_json()["data"]
|
||||
assert body["summary"]["precheck_hash"] == created["precheck_hash"]
|
||||
assert body["summary"]["matching_hash"] == created["matching_hash"]
|
||||
assert {item["invoice_no"] for item in body["items"]} == {"HOM-001", "HOX-002"}
|
||||
|
||||
|
||||
def test_restore_unknown_precheck_404(app, client, admin_headers, transfer_deps):
|
||||
"""未知 precheck → 404。"""
|
||||
response = client.get(f"{API_PREFIX}/prechecks/TPC-NOT-EXIST", headers=admin_headers)
|
||||
def test_restore_unknown_matching_404(app, client, admin_headers, transfer_deps):
|
||||
"""未知 matching → 404。"""
|
||||
response = client.get(f"{API_PREFIX}/matchings/MTG-NOT-EXIST", headers=admin_headers)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_execute_precheck_creates_run_and_projects_documents(app, client, admin_headers, transfer_deps):
|
||||
"""执行预检 → 201 run_no;GET run 返回 外部系统 单号聚合结果。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
def test_executable_items_lists_ready_rows_with_decoration(
|
||||
app, client, admin_headers, transfer_deps, monkeypatch
|
||||
):
|
||||
"""可调拨明细:只返回全局 ready 行,行带 item_id/checked_at/stale/file_current。"""
|
||||
# 行装饰的文件对账在 matching_service 命名空间——与执行门禁③同口径替身。
|
||||
monkeypatch.setattr(
|
||||
"app.services.in_transit_transfer.matching_service.resolve_source_file_status",
|
||||
lambda *, source_code: {"file_status": "ready", "has_ready_file": True,
|
||||
"file_no": "REC-TEST", "file_sha256": "d" * 64},
|
||||
)
|
||||
_create_matching(client, admin_headers)
|
||||
response = client.get(f"{API_PREFIX}/items/executable", headers=admin_headers)
|
||||
assert response.status_code == 200
|
||||
body = response.get_json()["data"]
|
||||
assert body["counts"]["executable_count"] == 2
|
||||
assert {item["invoice_no"] for item in body["items"]} == {"HOM-001", "HOX-002"}
|
||||
for item in body["items"]:
|
||||
assert item["item_id"] > 0
|
||||
assert item["stale"] is False
|
||||
assert item["file_current"] is True
|
||||
assert item["checked_at"]
|
||||
|
||||
|
||||
def test_executable_items_requires_authentication(client):
|
||||
"""未认证 → 401(与模块其余端点同口径)。"""
|
||||
assert client.get(f"{API_PREFIX}/items/executable").status_code == 401
|
||||
|
||||
|
||||
def _create_matching(client, admin_headers) -> str:
|
||||
"""创建匹配并返回 matching_no。"""
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={"invoice_nos": ["HOM-001", "HOX-002"]},
|
||||
)
|
||||
assert executed.status_code == 201
|
||||
})
|
||||
assert created.status_code == 201
|
||||
return created.get_json()["data"]["matching_id"]
|
||||
|
||||
|
||||
def _ready_item_ids(app) -> list[int]:
|
||||
"""按行执行入参:ready_to_execute 行的真实 item_id(restore 视图同源)。"""
|
||||
with app.app_context():
|
||||
from app.models import TransferInvoiceItem
|
||||
|
||||
rows = (
|
||||
TransferInvoiceItem.query.filter_by(status="ready_to_execute")
|
||||
.order_by(TransferInvoiceItem.id)
|
||||
.all()
|
||||
)
|
||||
return [row.id for row in rows]
|
||||
|
||||
|
||||
def _execute_ready_items(app, client, admin_headers, item_ids=None):
|
||||
"""POST /items/execute 执行 ready 行(缺省全部)。"""
|
||||
ids = _ready_item_ids(app) if item_ids is None else item_ids
|
||||
return client.post(f"{API_PREFIX}/items/execute", headers=admin_headers, json={"item_ids": ids})
|
||||
|
||||
|
||||
def test_execute_items_creates_run_and_projects_documents(app, client, admin_headers, transfer_deps):
|
||||
"""按行执行 → 200 run_no;GET run 返回 外部系统 单号聚合结果。"""
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
assert executed.status_code == 200
|
||||
assert executed.get_json()["success"] is True
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
assert run_no.startswith("RUN-")
|
||||
|
||||
@@ -195,36 +255,27 @@ def test_execute_precheck_creates_run_and_projects_documents(app, client, admin_
|
||||
assert result["exceptions"] == []
|
||||
|
||||
|
||||
def test_execute_unconfirmed_precheck_rejected(app, client, admin_headers, transfer_deps):
|
||||
"""预检未就绪时执行 → 400 领域错误,不产生 Run。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
with app.app_context():
|
||||
from app.models import TransferPrecheck
|
||||
|
||||
precheck = TransferPrecheck.query.filter_by(precheck_no=created["precheck_id"]).first()
|
||||
precheck.status = "prechecking"
|
||||
db.session.commit()
|
||||
response = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={"invoice_nos": ["HOM-001"]},
|
||||
)
|
||||
def test_execute_items_rejects_invalid_ids(app, client, admin_headers, transfer_deps):
|
||||
"""门禁①:不存在/非可执行行 → 400 EXECUTE_ITEMS_INVALID(details 列出 id),不产生 Run。"""
|
||||
_create_matching(client, admin_headers)
|
||||
response = _execute_ready_items(app, client, admin_headers, item_ids=[99999])
|
||||
assert response.status_code == 400
|
||||
assert response.get_json()["error"]["code"] == "TRANSFER_CONFIRMATION_REQUIRED"
|
||||
body = response.get_json()
|
||||
assert body["error"]["code"] == "TRANSFER.EXECUTE_ITEMS_INVALID"
|
||||
assert body["error"]["details"]["invalid_item_ids"] == [99999]
|
||||
|
||||
|
||||
def test_execute_items_requires_item_ids(app, client, admin_headers, transfer_deps):
|
||||
"""缺少 item_ids → 400 参数错误(复用批量操作校验)。"""
|
||||
response = client.post(f"{API_PREFIX}/items/execute", headers=admin_headers, json={})
|
||||
assert response.status_code == 400
|
||||
assert response.get_json()["success"] is False
|
||||
|
||||
|
||||
def test_cancel_run_requires_reason(app, client, admin_headers, transfer_deps):
|
||||
"""取消缺少原因 → 400。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={},
|
||||
)
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
response = client.post(f"{API_PREFIX}/runs/{run_no}/cancel", headers=admin_headers, json={"reason": ""})
|
||||
assert response.status_code == 400
|
||||
@@ -232,14 +283,8 @@ def test_cancel_run_requires_reason(app, client, admin_headers, transfer_deps):
|
||||
|
||||
def test_cancel_run_marks_remaining_cancelled(app, client, admin_headers, transfer_deps):
|
||||
"""取消未开始项并保留成功单据。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={"invoice_nos": ["HOM-001", "HOX-002"]},
|
||||
)
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
# 模拟执行中状态:Run 回退 executing,INV-002 尚未开始
|
||||
with app.app_context():
|
||||
@@ -260,7 +305,7 @@ def test_cancel_run_marks_remaining_cancelled(app, client, admin_headers, transf
|
||||
|
||||
def test_manual_close_item_requires_reason(app, client, admin_headers, transfer_deps):
|
||||
"""人工关闭缺少原因 → 400。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
@@ -278,7 +323,7 @@ def test_manual_close_item_requires_reason(app, client, admin_headers, transfer_
|
||||
|
||||
def test_manual_close_item_success(app, client, admin_headers, transfer_deps):
|
||||
"""人工关闭成功 → 状态 manually_closed。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
@@ -299,14 +344,8 @@ def test_manual_close_item_success(app, client, admin_headers, transfer_deps):
|
||||
|
||||
def test_exceptions_excel_download(app, transfer_db, client, admin_headers, transfer_deps):
|
||||
"""下载异常 Excel → 200 xlsx,且记录访问审计。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={"invoice_nos": ["HOM-001", "HOX-002"]},
|
||||
)
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
response = client.get(f"{API_PREFIX}/runs/{run_no}/exceptions.xlsx", headers=admin_headers)
|
||||
assert response.status_code == 200
|
||||
@@ -321,14 +360,8 @@ def test_exceptions_excel_download(app, transfer_db, client, admin_headers, tran
|
||||
|
||||
def test_receipt_files_download_records_access_audit(app, transfer_db, client, admin_headers, transfer_deps):
|
||||
"""下载收料来源文件 → 200(zip),记录访问审计。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={"invoice_nos": ["HOM-001", "HOX-002"]},
|
||||
)
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
response = client.get(f"{API_PREFIX}/runs/{run_no}/receipt-files", headers=admin_headers)
|
||||
assert response.status_code == 200
|
||||
@@ -341,15 +374,9 @@ def test_receipt_files_download_records_access_audit(app, transfer_db, client, a
|
||||
|
||||
|
||||
def test_erp_inventory_download_records_access_audit(app, transfer_db, client, admin_headers, transfer_deps):
|
||||
"""下载预检冻结的 外部系统 库存表 → 200(csv),记录访问审计。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={"invoice_nos": ["HOM-001", "HOX-002"]},
|
||||
)
|
||||
"""下载匹配冻结的 外部系统 库存表 → 200(csv),记录访问审计。"""
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
response = client.get(f"{API_PREFIX}/runs/{run_no}/external-inventory", headers=admin_headers)
|
||||
assert response.status_code == 200
|
||||
@@ -364,14 +391,8 @@ def test_erp_inventory_download_records_access_audit(app, transfer_db, client, a
|
||||
|
||||
def test_downloads_forbidden_without_permission(app, transfer_db, client, admin_headers, unauthorized_headers, transfer_deps):
|
||||
"""无权限下载 → 403(越权检查)。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={},
|
||||
)
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers)
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
for path in (f"{API_PREFIX}/runs/{run_no}/receipt-files",
|
||||
f"{API_PREFIX}/runs/{run_no}/external-inventory",
|
||||
@@ -380,34 +401,23 @@ def test_downloads_forbidden_without_permission(app, transfer_db, client, admin_
|
||||
assert response.status_code == 403, path
|
||||
|
||||
|
||||
def test_execute_ignores_forged_warehouse_and_quantity(app, transfer_db, client, admin_headers, transfer_deps):
|
||||
"""前端伪造来源仓/目标仓/数量 → 服务端忽略,使用冻结快照值(防篡改)。"""
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
executed = client.post(
|
||||
f"{API_PREFIX}/prechecks/{created['precheck_id']}/execute",
|
||||
headers=admin_headers, json={
|
||||
"invoice_nos": ["HOM-001"],
|
||||
"from_warehouse": "FAKE-TRANSIT",
|
||||
"to_warehouse": "FAKE-HUB",
|
||||
"quantity": "1",
|
||||
},
|
||||
)
|
||||
assert executed.status_code == 201
|
||||
def test_execute_items_uses_frozen_snapshot_values(app, transfer_db, client, admin_headers, transfer_deps):
|
||||
"""按行执行只接受 item_ids:来源仓/目标仓/数量一律取服务端冻结快照值(防篡改)。"""
|
||||
_create_matching(client, admin_headers)
|
||||
executed = _execute_ready_items(app, client, admin_headers, item_ids=_ready_item_ids(app)[:1])
|
||||
assert executed.status_code == 200
|
||||
run_no = executed.get_json()["data"]["run_no"]
|
||||
run = client.get(f"{API_PREFIX}/runs/{run_no}", headers=admin_headers).get_json()["data"]
|
||||
documents = run["result"]["external_documents"]
|
||||
assert documents[0]["from_warehouse"] == "DBS-TRANSIT" # 冻结值,非伪造值
|
||||
assert documents[0]["from_warehouse"] == "DBS-TRANSIT" # 冻结值,非前端可指定值
|
||||
assert documents[0]["to_warehouse"] == "HUB-CN01"
|
||||
assert documents[0]["total_quantity"] == "1200"
|
||||
|
||||
|
||||
def test_backlog_list_and_summary(app, transfer_db, client, admin_headers, transfer_deps):
|
||||
"""待处理异常列表/汇总 API:收纳 blocked 项、排除 success、含老化等级。"""
|
||||
# 预检含 1 个数量不一致(blocked)项
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
# 匹配含 1 个数量不一致(blocked)项
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
}).get_json()["data"]
|
||||
@@ -468,7 +478,7 @@ def test_metrics_endpoint(app, transfer_db, client, admin_headers, transfer_deps
|
||||
|
||||
|
||||
def test_requery_items_returns_envelope(app, client, admin_headers, monkeypatch, dbs_ready_file):
|
||||
"""POST /prechecks/{no}/items/requery → 200 envelope,逐票返回重查结果。
|
||||
"""POST /matchings/{no}/items/requery → 200 envelope,逐票返回重查结果。
|
||||
|
||||
[断言意图] 回归防线(2026-09-21):该端点曾引用未定义的 _actor_id 导致
|
||||
500/SYSTEM.INTERNAL_ERROR;本用例锁定端点在真实鉴权链路下可完整执行,
|
||||
@@ -479,14 +489,14 @@ def test_requery_items_returns_envelope(app, client, admin_headers, monkeypatch,
|
||||
erp.seed_stock("MAT-002", "DBS-TRANSIT", "LOT-20", "1200")
|
||||
monkeypatch.setattr("app.services.in_transit_transfer.deps._override", deps)
|
||||
|
||||
created = client.post(f"{API_PREFIX}/prechecks", headers=admin_headers, json={
|
||||
created = client.post(f"{API_PREFIX}/matchings", headers=admin_headers, json={
|
||||
"source_codes": ["DBS-AWSBI"],
|
||||
"business_date": "2026-08-06",
|
||||
})
|
||||
precheck_no = created.get_json()["data"]["precheck_id"]
|
||||
matching_no = created.get_json()["data"]["matching_id"]
|
||||
|
||||
response = client.post(
|
||||
f"{API_PREFIX}/prechecks/{precheck_no}/items/requery",
|
||||
f"{API_PREFIX}/matchings/{matching_no}/items/requery",
|
||||
headers=admin_headers,
|
||||
json={"invoice_nos": ["HOM-001"]},
|
||||
)
|
||||
@@ -494,7 +504,7 @@ def test_requery_items_returns_envelope(app, client, admin_headers, monkeypatch,
|
||||
body = response.get_json()
|
||||
assert body["success"] is True
|
||||
data = body["data"]
|
||||
assert data["precheck_no"] == precheck_no
|
||||
assert data["matching_no"] == matching_no
|
||||
assert data["total"] == 1
|
||||
result = data["results"][0]
|
||||
assert result["invoice_no"] == "HOM-001"
|
||||
|
||||
Reference in new issue
Block a user