feat(product-suite): add global generation history
This commit is contained in:
@@ -53,6 +53,122 @@ class ImageStudioExportTests(TempDirMixin, unittest.TestCase):
|
||||
image_studio.replace_selections(project.id, "detail", [detail.id], path=cfg["db_path"])
|
||||
return cfg, project, main, detail
|
||||
|
||||
def test_export_generation_round_copies_successes_and_uses_new_directory_on_repeat(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, _main, _detail = self._project_with_assets(temp_dir)
|
||||
source = image_studio.add_asset(
|
||||
project.id,
|
||||
image_studio.ASSET_KIND_ORIGINAL,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
first_source = self._write_image(os.path.join(temp_dir, "round-first.png"))
|
||||
first_asset = image_studio.add_asset(
|
||||
project.id,
|
||||
"generated_main",
|
||||
local_path=first_source,
|
||||
parent_asset_id=source.id,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
first_job = image_studio.create_job(
|
||||
project.id,
|
||||
source_asset_id=source.id,
|
||||
job_type="白底图",
|
||||
task_key="round-export-first",
|
||||
generation_round_key="round-export",
|
||||
generation_slot_index=0,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
image_studio.update_job_status(
|
||||
first_job.id,
|
||||
"succeeded",
|
||||
output_asset_id=first_asset.id,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
missing_asset = image_studio.add_asset(
|
||||
project.id,
|
||||
"generated_main",
|
||||
local_path=os.path.join(temp_dir, "missing-round.png"),
|
||||
parent_asset_id=source.id,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
missing_job = image_studio.create_job(
|
||||
project.id,
|
||||
source_asset_id=source.id,
|
||||
job_type="场景图",
|
||||
task_key="round-export-missing",
|
||||
generation_round_key="round-export",
|
||||
generation_slot_index=1,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
image_studio.update_job_status(
|
||||
missing_job.id,
|
||||
"succeeded",
|
||||
output_asset_id=missing_asset.id,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
second_source = self._write_image(
|
||||
os.path.join(temp_dir, "round-second.png"),
|
||||
color=(220, 80, 40, 255),
|
||||
)
|
||||
second_asset = image_studio.add_asset(
|
||||
project.id,
|
||||
"generated_main",
|
||||
local_path=second_source,
|
||||
parent_asset_id=source.id,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
second_job = image_studio.create_job(
|
||||
project.id,
|
||||
source_asset_id=source.id,
|
||||
job_type="卖点图",
|
||||
task_key="round-export-second",
|
||||
generation_round_key="round-export",
|
||||
generation_slot_index=2,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
image_studio.update_job_status(
|
||||
second_job.id,
|
||||
"succeeded",
|
||||
output_asset_id=second_asset.id,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
parent = os.path.join(temp_dir, "exports")
|
||||
os.makedirs(parent)
|
||||
|
||||
result = image_studio_export.export_generation_round(
|
||||
project.id,
|
||||
"round-export",
|
||||
parent,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
self.assertEqual(2, len(result.files))
|
||||
self.assertEqual(1, result.skipped_count)
|
||||
self.assertFalse(result.cancelled)
|
||||
self.assertTrue(os.path.isdir(result.target_dir))
|
||||
self.assertEqual(
|
||||
["01_白底图.png", "03_卖点图.png"],
|
||||
sorted(os.path.basename(item.output_path) for item in result.files),
|
||||
)
|
||||
self.assertTrue(os.path.isfile(first_source))
|
||||
self.assertTrue(os.path.isfile(second_source))
|
||||
with open(first_source, "rb") as source_file, open(
|
||||
result.files[0].output_path,
|
||||
"rb",
|
||||
) as exported_file:
|
||||
self.assertEqual(source_file.read(), exported_file.read())
|
||||
|
||||
second_result = image_studio_export.export_generation_round(
|
||||
project.id,
|
||||
"round-export",
|
||||
parent,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
self.assertNotEqual(result.target_dir, second_result.target_dir)
|
||||
self.assertTrue(second_result.target_dir.endswith("_2"))
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_export_partial_selection_outputs_ordered_jpegs(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, _main, _detail = self._project_with_assets(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user