41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""resolve_crm_product:运输联动场景允许已下架产品。"""
|
|
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
from app.services.db.product_helpers import resolve_crm_product
|
|
|
|
|
|
def _product(**kwargs):
|
|
base = dict(
|
|
id="p1",
|
|
tenant_no="shanxia2.0",
|
|
product_name="98% 工业硫酸",
|
|
model="98%",
|
|
status="off",
|
|
)
|
|
base.update(kwargs)
|
|
return SimpleNamespace(**base)
|
|
|
|
|
|
def test_resolve_rejects_off_shelf_by_default():
|
|
db = MagicMock()
|
|
with patch("app.services.db.product_helpers.get_product", return_value=_product()):
|
|
with pytest.raises(HTTPException) as exc:
|
|
resolve_crm_product(db, "shanxia2.0", "p1")
|
|
assert exc.value.status_code == 400
|
|
assert "下架" in str(exc.value.detail)
|
|
|
|
|
|
def test_resolve_allows_off_shelf_when_not_required():
|
|
db = MagicMock()
|
|
with patch("app.services.db.product_helpers.get_product", return_value=_product()):
|
|
snap = resolve_crm_product(db, "shanxia2.0", "p1", require_on_shelf=False)
|
|
assert snap.product_id == "p1"
|
|
assert snap.product_name == "98% 工业硫酸"
|
|
assert snap.specification == "98%"
|