feat(ai): generate covers without new titles
This commit is contained in:
@@ -217,6 +217,49 @@ class DbTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_set_generated_cover_preserves_title_and_records_ai_success(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": row,
|
||||
"account_name": "shop",
|
||||
"alias": "alias",
|
||||
"item_id": str(51100639510 + row),
|
||||
}
|
||||
for row in (2, 3)
|
||||
],
|
||||
path=db_path,
|
||||
)
|
||||
tasks = db.list_tasks(batch_id=batch_id, path=db_path)
|
||||
for task in tasks:
|
||||
db.set_collected(task.id, "旧标题", "old.jpg", path=db_path)
|
||||
db.set_generated(tasks[1].id, "已有新标题", None, path=db_path)
|
||||
before_with_title = db.get_task(tasks[1].id, path=db_path)
|
||||
|
||||
db.set_generated_cover(tasks[0].id, "cover-a.jpg", path=db_path)
|
||||
db.set_generated_cover(tasks[1].id, "cover-b.jpg", path=db_path)
|
||||
|
||||
without_title = db.get_task(tasks[0].id, path=db_path)
|
||||
with_title = db.get_task(tasks[1].id, path=db_path)
|
||||
self.assertIsNone(without_title.new_title)
|
||||
self.assertEqual("cover-a.jpg", without_title.new_cover_path)
|
||||
self.assertEqual("generated", without_title.stage)
|
||||
self.assertEqual("success", without_title.status)
|
||||
self.assertEqual(1, without_title.generate_attempts)
|
||||
self.assertIsNotNone(without_title.generated_at)
|
||||
self.assertEqual("已有新标题", with_title.new_title)
|
||||
self.assertEqual("cover-b.jpg", with_title.new_cover_path)
|
||||
self.assertEqual(before_with_title.generate_attempts + 1, with_title.generate_attempts)
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user