fix(status): ignore promotion edit warnings
This commit is contained in:
+143
-1
@@ -7,7 +7,7 @@ sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from _helpers import TempDirMixin
|
||||
|
||||
from app import db
|
||||
from app import db, product_status
|
||||
|
||||
|
||||
class DbTests(TempDirMixin, unittest.TestCase):
|
||||
@@ -259,6 +259,148 @@ class DbTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_init_db_repairs_only_legacy_promotion_status_misclassification(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
db_path = os.path.join(temp_dir, "cmshopee.db")
|
||||
db.init_db(db_path)
|
||||
batch_ids = {}
|
||||
for index, name in enumerate(
|
||||
(
|
||||
"legacy-promotion",
|
||||
"legacy-unknown",
|
||||
"after-promotion",
|
||||
"legacy-unlisted",
|
||||
"deleted-promotion",
|
||||
),
|
||||
start=1,
|
||||
):
|
||||
batch_id = db.create_batch([f"{name}.xlsx"], path=db_path)
|
||||
batch_ids[name] = batch_id
|
||||
db.insert_tasks(
|
||||
batch_id,
|
||||
[
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, f"{name}.xlsx"),
|
||||
"source_sheet": "Sheet1",
|
||||
"source_row": 2,
|
||||
"account_name": "店铺",
|
||||
"alias": "alias",
|
||||
"item_id": str(51100639800 + index),
|
||||
}
|
||||
],
|
||||
path=db_path,
|
||||
)
|
||||
|
||||
promotion_note = (
|
||||
"标题:由於正在進行促銷,以下一些欄位無法進行編輯,"
|
||||
"數值將顯示為灰色。"
|
||||
)
|
||||
conn = db.connect(db_path)
|
||||
try:
|
||||
with conn:
|
||||
legacy_ids = [
|
||||
batch_ids["legacy-promotion"],
|
||||
batch_ids["legacy-unknown"],
|
||||
batch_ids["legacy-unlisted"],
|
||||
batch_ids["deleted-promotion"],
|
||||
]
|
||||
placeholders = ", ".join("?" for _batch_id in legacy_ids)
|
||||
conn.execute(
|
||||
f"UPDATE batches SET created_at = ? WHERE id IN ({placeholders})",
|
||||
("2026-07-18T16:34:36", *legacy_ids),
|
||||
)
|
||||
task_by_batch = {
|
||||
batch_id: db.list_tasks(batch_id=batch_id, conn=conn)[0]
|
||||
for batch_id in batch_ids.values()
|
||||
}
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE tasks
|
||||
SET product_status = 'unknown', product_status_note = ?,
|
||||
product_status_at = ?, new_cover_path = ?,
|
||||
stage = 'generated', status = 'success'
|
||||
WHERE id = ?
|
||||
""",
|
||||
(
|
||||
promotion_note,
|
||||
"2026-07-20T09:18:10",
|
||||
"new.jpg",
|
||||
task_by_batch[batch_ids["legacy-promotion"]].id,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE tasks SET product_status = 'unknown', product_status_note = ? WHERE id = ?",
|
||||
(
|
||||
"其他未知状态提示",
|
||||
task_by_batch[batch_ids["legacy-unknown"]].id,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE tasks SET product_status = 'unknown', product_status_note = ? WHERE id = ?",
|
||||
(
|
||||
promotion_note,
|
||||
task_by_batch[batch_ids["after-promotion"]].id,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE tasks SET product_status = 'unlisted', product_status_note = ? WHERE id = ?",
|
||||
(
|
||||
promotion_note,
|
||||
task_by_batch[batch_ids["legacy-unlisted"]].id,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE tasks SET product_status = 'unknown', product_status_note = ? WHERE id = ?",
|
||||
(
|
||||
promotion_note,
|
||||
task_by_batch[batch_ids["deleted-promotion"]].id,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE batches SET deleted_at = ? WHERE id = ?",
|
||||
("2026-07-19T00:00:00", batch_ids["deleted-promotion"]),
|
||||
)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
db.init_db(db_path)
|
||||
legacy_promotion = db.list_tasks(
|
||||
batch_id=batch_ids["legacy-promotion"], path=db_path
|
||||
)[0]
|
||||
legacy_unknown = db.list_tasks(
|
||||
batch_id=batch_ids["legacy-unknown"], path=db_path
|
||||
)[0]
|
||||
after_promotion = db.list_tasks(
|
||||
batch_id=batch_ids["after-promotion"], path=db_path
|
||||
)[0]
|
||||
legacy_unlisted = db.list_tasks(
|
||||
batch_id=batch_ids["legacy-unlisted"], path=db_path
|
||||
)[0]
|
||||
deleted_promotion = db.list_tasks(
|
||||
batch_id=batch_ids["deleted-promotion"],
|
||||
include_deleted=True,
|
||||
path=db_path,
|
||||
)[0]
|
||||
|
||||
self.assertEqual("normal", legacy_promotion.product_status)
|
||||
self.assertEqual(db.LEGACY_PROMOTION_STATUS_REPAIR_NOTE, legacy_promotion.product_status_note)
|
||||
self.assertEqual("2026-07-20T09:18:10", legacy_promotion.product_status_at)
|
||||
cover_plan = product_status.build_apply_plan([legacy_promotion], "cover")
|
||||
self.assertEqual([legacy_promotion.id], [task.id for task in cover_plan["executable"]])
|
||||
self.assertEqual("unknown", legacy_unknown.product_status)
|
||||
self.assertEqual("unknown", after_promotion.product_status)
|
||||
self.assertEqual("unlisted", legacy_unlisted.product_status)
|
||||
self.assertEqual("unknown", deleted_promotion.product_status)
|
||||
|
||||
first_updated_at = legacy_promotion.updated_at
|
||||
db.init_db(db_path)
|
||||
self.assertEqual(
|
||||
first_updated_at,
|
||||
db.get_task(legacy_promotion.id, path=db_path).updated_at,
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_account_batch_task_lifecycle(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
db_path = os.path.join(temp_dir, "cmshopee.db")
|
||||
|
||||
@@ -7253,6 +7253,8 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertIn("审核中:1 条", message)
|
||||
self.assertIn("状态未知:1 条", message)
|
||||
self.assertNotIn("缺少新标题", message)
|
||||
self.assertIn("为安全起见不会更新", message)
|
||||
self.assertNotIn("重新确认商品状态", message)
|
||||
question.assert_not_called()
|
||||
run_worker.assert_not_called()
|
||||
self.assertIn("状态正常且可更新", states[-1])
|
||||
|
||||
@@ -53,6 +53,35 @@ class ProductStatusTests(unittest.TestCase):
|
||||
self.assertEqual(product_status.STATUS_UNLISTED, result["product_status"])
|
||||
self.assertIn("您的商品未上架", result["product_status_note"])
|
||||
|
||||
def test_promotion_edit_restriction_is_not_a_product_status_alert(self):
|
||||
traditional = {
|
||||
"title": "由於正在進行促銷,以下一些欄位無法進行編輯,數值將顯示為灰色。",
|
||||
"description": "",
|
||||
}
|
||||
simplified = {
|
||||
"title": "由于正在进行促销,以下一些字段无法进行编辑,数值将显示为灰色。",
|
||||
"description": "",
|
||||
}
|
||||
|
||||
for alert in (traditional, simplified):
|
||||
result = product_status.classify_alerts([alert])
|
||||
self.assertEqual(product_status.STATUS_NORMAL, result["product_status"])
|
||||
self.assertIsNone(result["product_status_note"])
|
||||
self.assertTrue(
|
||||
product_status.is_promotion_edit_restriction_note(
|
||||
f"标题:{alert['title']}"
|
||||
)
|
||||
)
|
||||
|
||||
reviewing = product_status.classify_alerts(
|
||||
[traditional, {"title": "审核中", "description": "等待审核"}]
|
||||
)
|
||||
unlisted = product_status.classify_alerts(
|
||||
[simplified, {"title": "您的商品未上架", "description": "已下架"}]
|
||||
)
|
||||
self.assertEqual(product_status.STATUS_REVIEWING, reviewing["product_status"])
|
||||
self.assertEqual(product_status.STATUS_UNLISTED, unlisted["product_status"])
|
||||
|
||||
def test_invalid_values_are_unknown_and_partitioning_is_consistent(self):
|
||||
tasks = [
|
||||
SimpleNamespace(product_status="normal"),
|
||||
|
||||
Reference in New Issue
Block a user