修复:拒绝纳入不存在的数据

This commit is contained in:
焦龙言
2026-09-24 09:22:15 +08:00
parent 02b87c9399
commit 886a4479c4
2 changed files with 31 additions and 0 deletions
@@ -362,6 +362,23 @@ class TestBatchAdoptionServiceTest(unittest.IsolatedAsyncioTestCase):
self.db.rollback.assert_awaited_once_with()
self.db.commit.assert_not_awaited()
async def test_preview_rejects_when_any_requested_root_does_not_exist(self) -> None:
batch = make_batch()
command = AdoptionPreviewRequestModel(roots=[AdoptionRootModel(resourceType='pallet', resourceIds=[10, 999])])
with (
self._preview_stack(batch),
self.assertRaisesRegex(ServiceWarning, '指定的旧数据不存在'),
):
await TestBatchAdoptionService.preview(self.db, 7, command, make_admin())
self.assertIsNone(batch.preview_action)
self.assertIsNone(batch.preview_token_hash)
self.assertIsNone(batch.preview_scope_hash)
self.assertIsNone(batch.preview_expires_at)
self.db.rollback.assert_awaited_once_with()
self.db.commit.assert_not_awaited()
async def test_regular_user_is_rejected_before_locking_batch(self) -> None:
lock_batch = AsyncMock()
with (