feat: 完成Tab①任务导入列表
实现 CollectTab 与 TaskTableModel,Tab① 接入导入 Excel 按钮、QTableView 任务列表和未匹配别名略过标记。 新增 GUI 测试覆盖 Tab① 接入、任务展示、未匹配标记和导入刷新;同步任务状态、API 合约、当前状态与 progress。 加入标准空模板 shopee待处理任务模板.xlsx,并更新 ignore/文档规则:模板可提交,运营填写后的 Excel 业务文件默认忽略。
This commit is contained in:
+100
-3
@@ -9,14 +9,21 @@ sys.path.insert(0, os.path.dirname(__file__))
|
||||
from _helpers import TempDirMixin
|
||||
|
||||
from app import gui
|
||||
from app import accounts
|
||||
from app import accounts, db
|
||||
|
||||
if gui.QT_IMPORT_ERROR is not None:
|
||||
raise unittest.SkipTest("PySide6 未安装")
|
||||
|
||||
from PySide6.QtWidgets import QApplication, QLineEdit
|
||||
from PySide6.QtWidgets import QApplication, QLineEdit, QTableView
|
||||
|
||||
from app.gui import AccountDialog, AccountsTab, MainWindow, TAB_STYLE, TAB_TITLES
|
||||
from app.gui import (
|
||||
AccountDialog,
|
||||
AccountsTab,
|
||||
CollectTab,
|
||||
MainWindow,
|
||||
TAB_STYLE,
|
||||
TAB_TITLES,
|
||||
)
|
||||
|
||||
|
||||
class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
@@ -47,6 +54,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertIn("min-width: 128px", window.tabs.styleSheet())
|
||||
self.assertIn("padding: 8px 18px", window.tabs.styleSheet())
|
||||
self.assertIn("margin-right: 8px", window.tabs.styleSheet())
|
||||
self.assertIsInstance(window.tabs.widget(0), CollectTab)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
@@ -149,6 +157,95 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_collect_tab_lists_tasks_with_unmatched_alias_as_skipped(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)
|
||||
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": "51100639510",
|
||||
},
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 3,
|
||||
"account_name": "Excel副店",
|
||||
"alias": "missing",
|
||||
"item_id": "51100639511",
|
||||
},
|
||||
],
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
tab = CollectTab(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
|
||||
self.assertIsInstance(tab.table, QTableView)
|
||||
self.assertEqual(2, tab.model.rowCount())
|
||||
self.assertEqual("主店", tab.model.index(0, 0).data())
|
||||
self.assertEqual("alias-a", tab.model.index(0, 1).data())
|
||||
self.assertEqual("51100639510", tab.model.index(0, 2).data())
|
||||
self.assertEqual("待采集", tab.model.index(0, 3).data())
|
||||
self.assertEqual("Excel副店", tab.model.index(1, 0).data())
|
||||
self.assertEqual("missing", tab.model.index(1, 1).data())
|
||||
self.assertEqual("略过", tab.model.index(1, 3).data())
|
||||
self.assertIn("未匹配", tab.empty_label.text())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_collect_tab_import_button_imports_excel_and_refreshes_tasks(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)
|
||||
excel_path = os.path.join(temp_dir, "input.xlsx")
|
||||
statuses = []
|
||||
tab = CollectTab(config=cfg, status_callback=statuses.append)
|
||||
self.addCleanup(tab.close)
|
||||
|
||||
def fake_import(file_paths, path=None):
|
||||
batch_id = db.create_batch(file_paths, path=path)
|
||||
db.insert_tasks(
|
||||
batch_id,
|
||||
[
|
||||
{
|
||||
"source_file_abs": excel_path,
|
||||
"source_sheet": "商品",
|
||||
"source_row": 2,
|
||||
"account_name": "Excel主店",
|
||||
"alias": "alias-a",
|
||||
"item_id": "51100639510",
|
||||
}
|
||||
],
|
||||
path=path,
|
||||
)
|
||||
return {
|
||||
"batch_id": batch_id,
|
||||
"rows": [],
|
||||
"stats": {"valid": 1, "invalid": 0, "inserted": 1},
|
||||
}
|
||||
|
||||
with mock.patch.object(
|
||||
tab,
|
||||
"_choose_excel_files",
|
||||
return_value=[excel_path],
|
||||
), mock.patch("app.gui.excel.import_tasks", side_effect=fake_import) as import_tasks:
|
||||
tab.import_excel()
|
||||
|
||||
import_tasks.assert_called_once_with([excel_path], path=cfg["db_path"])
|
||||
self.assertEqual(1, tab.model.rowCount())
|
||||
self.assertEqual("alias-a", tab.model.index(0, 1).data())
|
||||
self.assertIn("入库1", statuses[-1])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user