格式:整理主数据批次代码
This commit is contained in:
@@ -379,7 +379,9 @@ class MasterDao:
|
||||
return await cls._find(db, BizWarehouse, BizWarehouse.warehouse_code, warehouse_code)
|
||||
|
||||
@classmethod
|
||||
async def add_warehouse(cls, db: AsyncSession, warehouse: WarehouseModel, test_batch_id: int | None) -> BizWarehouse:
|
||||
async def add_warehouse(
|
||||
cls, db: AsyncSession, warehouse: WarehouseModel, test_batch_id: int | None
|
||||
) -> BizWarehouse:
|
||||
return await cls._add(db, BizWarehouse, 'warehouse_id', warehouse, test_batch_id)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -203,9 +203,7 @@ class PalletService:
|
||||
assert_record_in_scope(record, scope, _ASSIGNMENT_LABELS[resource])
|
||||
|
||||
users = await MasterDao.list_assignable_users(db)
|
||||
assigned_user_ids = set(
|
||||
await getattr(MasterDao, f'list_{resource}_assigned_user_ids')(db, resource_id, scope)
|
||||
)
|
||||
assigned_user_ids = set(await getattr(MasterDao, f'list_{resource}_assigned_user_ids')(db, resource_id, scope))
|
||||
return [
|
||||
BusinessUserOptionModel(
|
||||
user_id=user.user_id,
|
||||
|
||||
@@ -378,9 +378,7 @@ class TestMasterBatchScopeService(unittest.IsolatedAsyncioTestCase):
|
||||
for resource, model in make_models().items():
|
||||
events: list[str] = []
|
||||
lock_batch = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('lock-batch'))
|
||||
find_duplicate = AsyncMock(
|
||||
side_effect=lambda *_args, _events=events: _events.append('find-duplicate')
|
||||
)
|
||||
find_duplicate = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('find-duplicate'))
|
||||
add_record = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('add-record'))
|
||||
parent_method = None
|
||||
parent_lookup = None
|
||||
@@ -390,18 +388,13 @@ class TestMasterBatchScopeService(unittest.IsolatedAsyncioTestCase):
|
||||
parent_method = 'get_site'
|
||||
with self.subTest(resource=resource), ExitStack() as stack:
|
||||
self.db.reset_mock()
|
||||
stack.enter_context(
|
||||
patch.object(TestBatchAccessService, 'lock_active_batch', new=lock_batch)
|
||||
)
|
||||
stack.enter_context(
|
||||
patch.object(MasterDao, f'find_{resource}_by_code', new=find_duplicate)
|
||||
)
|
||||
stack.enter_context(patch.object(TestBatchAccessService, 'lock_active_batch', new=lock_batch))
|
||||
stack.enter_context(patch.object(MasterDao, f'find_{resource}_by_code', new=find_duplicate))
|
||||
stack.enter_context(patch.object(MasterDao, f'add_{resource}', new=add_record))
|
||||
if parent_method is not None:
|
||||
parent_lookup = AsyncMock(
|
||||
side_effect=lambda *_args, _events=events: (
|
||||
_events.append('get-parent')
|
||||
or SimpleNamespace(status='0', test_batch_id=9)
|
||||
_events.append('get-parent') or SimpleNamespace(status='0', test_batch_id=9)
|
||||
)
|
||||
)
|
||||
stack.enter_context(patch.object(MasterDao, parent_method, new=parent_lookup))
|
||||
@@ -430,14 +423,10 @@ class TestMasterBatchScopeService(unittest.IsolatedAsyncioTestCase):
|
||||
_events.append('get-current') or _current
|
||||
)
|
||||
)
|
||||
update_record = AsyncMock(
|
||||
side_effect=lambda *_args, _events=events: _events.append('update-record')
|
||||
)
|
||||
update_record = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('update-record'))
|
||||
with self.subTest(resource=resource), ExitStack() as stack:
|
||||
self.db.reset_mock()
|
||||
stack.enter_context(
|
||||
patch.object(TestBatchAccessService, 'lock_active_batch', new=lock_batch)
|
||||
)
|
||||
stack.enter_context(patch.object(TestBatchAccessService, 'lock_active_batch', new=lock_batch))
|
||||
stack.enter_context(patch.object(MasterDao, f'get_{resource}', new=get_current))
|
||||
stack.enter_context(
|
||||
patch.object(MasterDao, f'find_{resource}_by_code', new=AsyncMock(return_value=current))
|
||||
@@ -528,16 +517,12 @@ class TestMasterBatchScopeService(unittest.IsolatedAsyncioTestCase):
|
||||
)
|
||||
for resource, parent_method, scope, parent_batch_id in cases:
|
||||
with self.subTest(resource=resource, scope=scope, parent_batch_id=parent_batch_id), ExitStack() as stack:
|
||||
stack.enter_context(
|
||||
patch.object(TestBatchAccessService, 'lock_active_batch', new=AsyncMock())
|
||||
)
|
||||
stack.enter_context(patch.object(TestBatchAccessService, 'lock_active_batch', new=AsyncMock()))
|
||||
stack.enter_context(
|
||||
patch.object(
|
||||
MasterDao,
|
||||
parent_method,
|
||||
new=AsyncMock(
|
||||
return_value=SimpleNamespace(status='0', test_batch_id=parent_batch_id)
|
||||
),
|
||||
new=AsyncMock(return_value=SimpleNamespace(status='0', test_batch_id=parent_batch_id)),
|
||||
)
|
||||
)
|
||||
stack.enter_context(
|
||||
@@ -609,9 +594,7 @@ class TestMasterBatchScopeService(unittest.IsolatedAsyncioTestCase):
|
||||
patch.object(
|
||||
MasterDao,
|
||||
'get_strain',
|
||||
new=AsyncMock(
|
||||
return_value=SimpleNamespace(strain_id=7, test_batch_id=None)
|
||||
),
|
||||
new=AsyncMock(return_value=SimpleNamespace(strain_id=7, test_batch_id=None)),
|
||||
)
|
||||
)
|
||||
stack.enter_context(
|
||||
@@ -873,6 +856,7 @@ class TestMasterDao(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertNotIn('create_time', update_sql)
|
||||
self.db.commit.assert_not_awaited()
|
||||
|
||||
|
||||
class TestMasterDaoBatchScope(unittest.IsolatedAsyncioTestCase):
|
||||
TABLES = {
|
||||
'strain': ('biz_strain', 'strain_id'),
|
||||
|
||||
@@ -1106,16 +1106,11 @@ class TestPalletBatchScopeService(unittest.IsolatedAsyncioTestCase):
|
||||
lock_batch = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('lock-batch'))
|
||||
get_resource = AsyncMock(
|
||||
side_effect=lambda *_args, _events=events, **_kwargs: (
|
||||
_events.append('get-resource')
|
||||
or SimpleNamespace(test_batch_id=9)
|
||||
_events.append('get-resource') or SimpleNamespace(test_batch_id=9)
|
||||
)
|
||||
)
|
||||
list_users = AsyncMock(
|
||||
side_effect=lambda *_args, _events=events: _events.append('list-users') or []
|
||||
)
|
||||
replace_users = AsyncMock(
|
||||
side_effect=lambda *_args, _events=events: _events.append('replace-users')
|
||||
)
|
||||
list_users = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('list-users') or [])
|
||||
replace_users = AsyncMock(side_effect=lambda *_args, _events=events: _events.append('replace-users'))
|
||||
with (
|
||||
self.subTest(resource=resource, operation='write'),
|
||||
patch.object(TestBatchAccessService, 'lock_active_batch', new=lock_batch),
|
||||
|
||||
Reference in New Issue
Block a user