feat(collect): add product status recheck
This commit is contained in:
+70
-1
@@ -7079,7 +7079,8 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
message = warning.call_args[0][2]
|
||||
self.assertIn("未上架:1 条", message)
|
||||
self.assertIn("审核中:1 条", message)
|
||||
self.assertIn("状态未知:1 条", message)
|
||||
self.assertIn("尚未检测商品状态:1 条", message)
|
||||
self.assertIn("点击「重新检测商品状态」", message)
|
||||
self.assertNotIn("缺少新标题", message)
|
||||
question.assert_not_called()
|
||||
run_worker.assert_not_called()
|
||||
@@ -8374,6 +8375,74 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_status_recheck_uses_current_generated_filter_without_changing_task_fields(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
db.init_db(cfg["db_path"])
|
||||
batch_id = db.create_batch(["input.xlsx"], path=cfg["db_path"])
|
||||
db.insert_tasks(
|
||||
batch_id,
|
||||
[
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 2,
|
||||
"alias": "alias-a",
|
||||
"item_id": "51100639510",
|
||||
},
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 3,
|
||||
"alias": "alias-a",
|
||||
"item_id": "51100639511",
|
||||
},
|
||||
],
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
tasks = db.list_tasks(batch_id=batch_id, path=cfg["db_path"])
|
||||
for task in tasks:
|
||||
db.set_collected(task.id, "旧标题", "old.jpg", path=cfg["db_path"])
|
||||
db.set_generated(task.id, "新标题", "new.jpg", path=cfg["db_path"])
|
||||
tab = CollectTab(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
tab.status_filter.setCurrentIndex(tab.status_filter.findData("generated"))
|
||||
|
||||
class FakeWorker:
|
||||
def __init__(self, worker_tasks, **kwargs):
|
||||
self.tasks = list(worker_tasks)
|
||||
self.kwargs = kwargs
|
||||
self.progress = DummySignal()
|
||||
self.row_updated = DummySignal()
|
||||
self.log = DummySignal()
|
||||
self.failed = DummySignal()
|
||||
self.finished = DummySignal()
|
||||
self.cancelled = DummySignal()
|
||||
|
||||
def cancel(self):
|
||||
pass
|
||||
|
||||
thread = FakeThread()
|
||||
with mock.patch(
|
||||
"app.gui.QMessageBox.question",
|
||||
return_value=gui.QMessageBox.Yes,
|
||||
) as question, mock.patch(
|
||||
"app.gui.StatusRecheckWorker", FakeWorker
|
||||
), mock.patch("app.gui.run_worker", return_value=thread):
|
||||
tab.recheck_product_status()
|
||||
|
||||
self.assertTrue(thread.started)
|
||||
self.assertEqual([task.id for task in tasks], [task.id for task in tab.status_recheck_worker.tasks])
|
||||
self.assertEqual(cfg["db_path"], tab.status_recheck_worker.kwargs["db_path"])
|
||||
self.assertIn("不会读取或覆盖旧标题", question.call_args[0][2])
|
||||
self.assertFalse(tab.collect_button.isEnabled())
|
||||
self.assertFalse(tab.status_recheck_button.isEnabled())
|
||||
unchanged = db.list_tasks(batch_id=batch_id, path=cfg["db_path"])
|
||||
self.assertTrue(all(task.stage == "generated" for task in unchanged))
|
||||
self.assertTrue(all(task.product_status is None for task in unchanged))
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_collect_scope_dialog_uses_safe_default_and_warning_all_status_choice(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
tab = CollectTab(config=self.make_config(temp_dir))
|
||||
|
||||
Reference in New Issue
Block a user