T-564 async cmhub image tasks
This commit is contained in:
@@ -29,6 +29,11 @@ class DbTests(TempDirMixin, unittest.TestCase):
|
||||
).fetchall()
|
||||
}
|
||||
self.assertTrue({"batches", "accounts", "tasks"}.issubset(tables))
|
||||
task_columns = {
|
||||
row["name"]
|
||||
for row in conn.execute("PRAGMA table_info(tasks)").fetchall()
|
||||
}
|
||||
self.assertTrue({"image_task_id", "image_task_key"}.issubset(task_columns))
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -79,6 +84,8 @@ class DbTests(TempDirMixin, unittest.TestCase):
|
||||
task = db.list_tasks(batch_id=batch_id, alias="alias", path=db_path)[0]
|
||||
self.assertEqual("imported", task.stage)
|
||||
self.assertEqual("pending", task.status)
|
||||
self.assertIsNone(task.image_task_id)
|
||||
self.assertIsNone(task.image_task_key)
|
||||
|
||||
db.mark_running(task.id, "collect", path=db_path)
|
||||
self.assertEqual("running", db.list_tasks(path=db_path)[0].status)
|
||||
@@ -126,6 +133,65 @@ class DbTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_image_task_helpers_and_reset_lifecycle(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
db_path = os.path.join(temp_dir, "cmshopee.db")
|
||||
db.init_db(db_path)
|
||||
batch_id = db.create_batch(["input.xlsx"], path=db_path)
|
||||
db.insert_tasks(
|
||||
batch_id,
|
||||
[
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, "input.xlsx"),
|
||||
"source_sheet": "Sheet1",
|
||||
"source_row": 2,
|
||||
"account_name": "shop",
|
||||
"alias": "alias",
|
||||
"item_id": "51100639510",
|
||||
}
|
||||
],
|
||||
path=db_path,
|
||||
)
|
||||
task = db.list_tasks(batch_id=batch_id, path=db_path)[0]
|
||||
db.set_collected(task.id, "旧标题", "old.jpg", path=db_path)
|
||||
db.set_generated(task.id, "新标题", "new.jpg", path=db_path)
|
||||
|
||||
key = db.ensure_image_task_key(task.id, path=db_path)
|
||||
self.assertTrue(key.startswith(f"cmshopee-task-{task.id}-"))
|
||||
self.assertEqual(key, db.ensure_image_task_key(task.id, path=db_path))
|
||||
|
||||
db.set_image_task_submitted(task.id, "cmhub-task-1", key, path=db_path)
|
||||
submitted = db.get_task(task.id, path=db_path)
|
||||
self.assertEqual("cmhub-task-1", submitted.image_task_id)
|
||||
self.assertEqual(key, submitted.image_task_key)
|
||||
|
||||
title_only = db.reset_generated(
|
||||
task.id,
|
||||
reset_title=True,
|
||||
reset_cover=False,
|
||||
path=db_path,
|
||||
)["after"]
|
||||
self.assertEqual("cmhub-task-1", title_only.image_task_id)
|
||||
self.assertEqual(key, title_only.image_task_key)
|
||||
|
||||
cover_reset = db.reset_generated(
|
||||
task.id,
|
||||
reset_title=False,
|
||||
reset_cover=True,
|
||||
path=db_path,
|
||||
)["after"]
|
||||
self.assertIsNone(cover_reset.image_task_id)
|
||||
self.assertIsNone(cover_reset.image_task_key)
|
||||
|
||||
new_key = db.ensure_image_task_key(task.id, path=db_path)
|
||||
self.assertNotEqual(key, new_key)
|
||||
db.clear_image_task(task.id, path=db_path)
|
||||
cleared = db.get_task(task.id, path=db_path)
|
||||
self.assertIsNone(cleared.image_task_id)
|
||||
self.assertIsNone(cleared.image_task_key)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_mark_failed_prepends_chinese_step_without_duplicate_prefix(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
db_path = os.path.join(temp_dir, "cmshopee.db")
|
||||
|
||||
Reference in New Issue
Block a user