修复:补充发货草稿当前余量
This commit is contained in:
@@ -10,6 +10,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.routing import APIRoute
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -251,6 +252,49 @@ class ShipmentInfrastructureContractTest(unittest.TestCase):
|
||||
self.assertIs(False, parameter.default)
|
||||
|
||||
|
||||
class ShipmentDetailDaoTest(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_detail_loads_each_current_remaining_quantity_with_one_left_join(self) -> None:
|
||||
db = MagicMock(spec=AsyncSession)
|
||||
shipment = make_shipment(pallet_ids=(5, 2, 8))
|
||||
order_result = MagicMock()
|
||||
order_result.scalar_one_or_none.return_value = shipment
|
||||
item_result = MagicMock()
|
||||
item_result.all.return_value = [
|
||||
(shipment.items[0], 13),
|
||||
(shipment.items[1], 6),
|
||||
(shipment.items[2], None),
|
||||
]
|
||||
db.execute.side_effect = [order_result, item_result]
|
||||
|
||||
actual = await OperationDao.get_shipment_by_id(
|
||||
db,
|
||||
12,
|
||||
warehouse_ids=[7],
|
||||
site_ids=[9],
|
||||
)
|
||||
|
||||
self.assertIs(shipment, actual)
|
||||
self.assertEqual(2, db.execute.await_count)
|
||||
self.assertEqual([13, 6, None], [item.remaining_packages for item in shipment.items])
|
||||
self.assertEqual([None, None, None], [item.package_qty for item in shipment.items])
|
||||
item_statement = db.execute.await_args_list[1].args[0]
|
||||
item_sql = ' '.join(
|
||||
str(
|
||||
item_statement.compile(
|
||||
dialect=postgresql.dialect(),
|
||||
compile_kwargs={'literal_binds': True},
|
||||
)
|
||||
).split()
|
||||
)
|
||||
self.assertIn(
|
||||
'LEFT OUTER JOIN biz_pallet_inventory '
|
||||
'ON biz_pallet_inventory.pallet_id = biz_shipment_item.pallet_id',
|
||||
item_sql,
|
||||
)
|
||||
self.assertIn('WHERE biz_shipment_item.shipment_id = 12', item_sql)
|
||||
self.assertIn('ORDER BY biz_shipment_item.shipment_item_id', item_sql)
|
||||
|
||||
|
||||
class ShipmentControllerBootstrapTest(unittest.TestCase):
|
||||
def test_shipment_controller_module_exists(self) -> None:
|
||||
spec = importlib.util.find_spec('module_business.controller.shipment_controller')
|
||||
|
||||
Reference in New Issue
Block a user