feat: align collect filters with workflow tabs
This commit is contained in:
@@ -2313,6 +2313,149 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_collect_tab_filters_by_shop_item_status_and_collect_scope(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
accounts.create_account("主店", "alias-a", debug_port=9222, config=cfg)
|
||||
accounts.create_account("副店", "alias-b", debug_port=9223, config=cfg)
|
||||
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,
|
||||
"account_name": "Excel主店",
|
||||
"alias": "alias-a",
|
||||
"item_id": "1001",
|
||||
},
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 3,
|
||||
"account_name": "Excel主店",
|
||||
"alias": "alias-a",
|
||||
"item_id": "1002",
|
||||
},
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 4,
|
||||
"account_name": "Excel副店",
|
||||
"alias": "alias-b",
|
||||
"item_id": "2001",
|
||||
},
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 5,
|
||||
"account_name": "Excel副店",
|
||||
"alias": "alias-b",
|
||||
"item_id": "2002",
|
||||
},
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 6,
|
||||
"account_name": "Excel未知",
|
||||
"alias": "missing",
|
||||
"item_id": "3001",
|
||||
},
|
||||
],
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
tasks = {task.item_id: task for task in db.list_tasks(batch_id=batch_id, path=cfg["db_path"])}
|
||||
db.set_collected(tasks["1002"].id, "旧标题", os.path.join(temp_dir, "old.jpg"), path=cfg["db_path"])
|
||||
db.mark_failed(tasks["2002"].id, "collect", "采集失败", path=cfg["db_path"])
|
||||
|
||||
tab = CollectTab(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
|
||||
self.assertEqual("collectShopFilter", tab.shop_filter.objectName())
|
||||
self.assertEqual("collectItemFilter", tab.item_filter.objectName())
|
||||
self.assertEqual("collectStatusFilter", tab.status_filter.objectName())
|
||||
self.assertEqual(5, tab.model.rowCount())
|
||||
self.assertIn("5 行", tab.summary_label.text())
|
||||
self.assertEqual("未匹配(1)", tab.show_unmatched_button.text())
|
||||
self.assertIn("总数5", tab.batch_progress_label.text())
|
||||
|
||||
tab.shop_filter.setCurrentIndex(tab.shop_filter.findData("alias-a"))
|
||||
self.assertEqual(2, tab.model.rowCount())
|
||||
self.assertEqual(["1001", "1002"], [tab.model.index(row, 2).data() for row in range(tab.model.rowCount())])
|
||||
self.assertIn("5 行", tab.summary_label.text())
|
||||
self.assertEqual("未匹配(1)", tab.show_unmatched_button.text())
|
||||
|
||||
tab.item_filter.setText("1002")
|
||||
self.assertEqual(1, tab.model.rowCount())
|
||||
self.assertEqual("1002", tab.model.index(0, 2).data())
|
||||
|
||||
tab.status_filter.setCurrentIndex(tab.status_filter.findData("collected"))
|
||||
self.assertEqual(1, tab.model.rowCount())
|
||||
self.assertEqual("已采集", tab.model.index(0, 3).data())
|
||||
|
||||
tab.shop_filter.setCurrentIndex(tab.shop_filter.findData(None))
|
||||
tab.item_filter.clear()
|
||||
tab.status_filter.setCurrentIndex(tab.status_filter.findData("skipped"))
|
||||
self.assertEqual(1, tab.model.rowCount())
|
||||
self.assertEqual("missing", tab.model.index(0, 1).data())
|
||||
self.assertEqual("略过", tab.model.index(0, 3).data())
|
||||
|
||||
tab.item_filter.setText("no-match")
|
||||
self.assertEqual(0, tab.model.rowCount())
|
||||
self.assertIn("当前筛选没有匹配任务", tab.empty_label.text())
|
||||
|
||||
tab.shop_filter.setCurrentIndex(tab.shop_filter.findData("alias-a"))
|
||||
tab.item_filter.setText("1001")
|
||||
tab.status_filter.setCurrentIndex(tab.status_filter.findData("to_collect"))
|
||||
tab.show_all_tasks()
|
||||
self.assertEqual(1, tab.model.rowCount())
|
||||
self.assertEqual("1001", tab.model.index(0, 2).data())
|
||||
|
||||
class FakeSignal:
|
||||
def __init__(self):
|
||||
self.callbacks = []
|
||||
|
||||
def connect(self, callback):
|
||||
self.callbacks.append(callback)
|
||||
|
||||
class FakeWorker:
|
||||
def __init__(self, tasks, **kwargs):
|
||||
captured["tasks"] = tasks
|
||||
captured["kwargs"] = kwargs
|
||||
self.progress = FakeSignal()
|
||||
self.row_updated = FakeSignal()
|
||||
self.log = FakeSignal()
|
||||
self.failed = FakeSignal()
|
||||
self.finished = FakeSignal()
|
||||
self.cancelled = FakeSignal()
|
||||
|
||||
def cancel(self):
|
||||
captured["cancelled"] = True
|
||||
|
||||
class FakeThread:
|
||||
def __init__(self):
|
||||
self.finished = FakeSignal()
|
||||
|
||||
def start(self):
|
||||
captured["started"] = True
|
||||
|
||||
captured = {}
|
||||
with mock.patch("app.gui.CollectWorker", FakeWorker), mock.patch(
|
||||
"app.gui.run_worker",
|
||||
return_value=FakeThread(),
|
||||
):
|
||||
tab.collect_old_data()
|
||||
|
||||
self.assertTrue(captured["started"])
|
||||
self.assertEqual(["1001"], [task.item_id for task in captured["tasks"]])
|
||||
self.assertEqual(cfg["db_path"], captured["kwargs"]["db_path"])
|
||||
self.assertFalse(tab.shop_filter.isEnabled())
|
||||
self.assertFalse(tab.item_filter.isEnabled())
|
||||
self.assertFalse(tab.status_filter.isEnabled())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_collect_tab_soft_deletes_batch_and_refreshes_workflow_tabs(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user