feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -0,0 +1,77 @@
|
||||
"""
|
||||
tests/test_shipping_notice_openapi_contract.py
|
||||
|
||||
用途:锁定发货通知订单行路由线索与库存连接器 OpenAPI 命名契约。
|
||||
依赖:Flask 测试 client、静态 Dify OpenAPI JSON。
|
||||
逻辑:分别校验动态 builder 输出与脚本生成的静态快照,防止两者发生漂移。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _assert_connector_contract(spec: dict[str, Any]) -> None:
|
||||
"""
|
||||
校验订单行与库存连接器的字段边界。
|
||||
|
||||
核心逻辑:订单行保留可选 source_type 且不暴露 hub_code;任务状态说明使用
|
||||
inventory_connector_type,并拒绝旧 inventory_source_type 命名。
|
||||
|
||||
Args:
|
||||
spec: 动态接口或静态快照读取出的 OpenAPI 对象。
|
||||
|
||||
Returns:
|
||||
None;契约不符时由 pytest assertion 报错。
|
||||
"""
|
||||
order_schema = spec["paths"]["/tools/submit_order_extraction"]["post"]["requestBody"]["content"][
|
||||
"application/json"
|
||||
]["schema"]["properties"]["orders"]["items"]
|
||||
line_properties = order_schema["properties"]["lines"]["items"]["properties"]
|
||||
assert set(line_properties) == {"sku", "qty", "reservation_id", "source_type"}
|
||||
assert "可选订单路由线索" in line_properties["source_type"]["description"]
|
||||
|
||||
status_description = spec["paths"]["/tools/get_task_status"]["post"]["description"]
|
||||
assert "inventory_connector_type" in status_description
|
||||
assert "inventory_source_type" not in status_description
|
||||
|
||||
confirm_description = spec["paths"]["/tools/confirm_inventory_source"]["post"]["description"]
|
||||
assert "connector_type" in confirm_description
|
||||
assert "source_code、source_type" not in confirm_description
|
||||
|
||||
|
||||
def test_dynamic_openapi_uses_connector_contract(app, client) -> None:
|
||||
"""
|
||||
校验公开 OpenAPI 接口使用新的连接器命名。
|
||||
|
||||
核心逻辑:通过 Flask 路由获取 builder 实时结果,再复用统一契约断言。
|
||||
|
||||
Args:
|
||||
app: pytest Flask 应用 fixture。
|
||||
client: pytest Flask 测试客户端 fixture。
|
||||
|
||||
Returns:
|
||||
None。
|
||||
"""
|
||||
app.config["HXOPS_TOOLS_API_BASE"] = "http://tool-api.example.com"
|
||||
response = client.get("/api/shipping-notice/tools/openapi.json")
|
||||
|
||||
assert response.status_code == 200
|
||||
_assert_connector_contract(response.get_json())
|
||||
|
||||
|
||||
def test_static_openapi_uses_connector_contract() -> None:
|
||||
"""
|
||||
校验仓库脚本生成的 Dify 静态快照与动态契约一致。
|
||||
|
||||
核心逻辑:读取 docs/openapi 下的 JSON,并复用统一契约断言。
|
||||
|
||||
Returns:
|
||||
None。
|
||||
"""
|
||||
spec_path = Path(__file__).resolve().parents[2] / "docs" / "openapi" / "shipping_notice_tools.dify.json"
|
||||
spec = json.loads(spec_path.read_text(encoding="utf-8"))
|
||||
|
||||
_assert_connector_contract(spec)
|
||||
Reference in new issue
Block a user