feat: use images payload for product suite generation
This commit is contained in:
@@ -187,6 +187,62 @@ class ImageStudioGenerationTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assertEqual(1, summary["success"])
|
||||
self.assertEqual("3:4", submitted_payloads[0]["aspect_ratio"])
|
||||
self.assertEqual(1, len(submitted_payloads[0]["images"]))
|
||||
self.assertIn("image_base64", submitted_payloads[0]["images"][0])
|
||||
self.assertNotIn("image_base64", submitted_payloads[0])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_build_cmhub_images_keeps_order_and_limits_to_eight_inputs(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, source = self._project_source(temp_dir)
|
||||
references = []
|
||||
for index in range(2, 10):
|
||||
path = os.path.join(temp_dir, "source-%d.png" % index)
|
||||
with open(path, "wb") as fh:
|
||||
fh.write(self._png_bytes())
|
||||
references.append(
|
||||
image_studio.add_asset(
|
||||
project.id,
|
||||
image_studio.ASSET_KIND_ORIGINAL,
|
||||
local_path=path,
|
||||
source_order=index,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
)
|
||||
|
||||
with mock.patch(
|
||||
"app.image_studio_generation.ai._image_data_url",
|
||||
side_effect=lambda path: "data:image/png;base64,%s" % os.path.basename(path),
|
||||
):
|
||||
images, omitted_count = image_studio_generation._build_cmhub_images(
|
||||
source,
|
||||
references,
|
||||
)
|
||||
|
||||
self.assertEqual(8, len(images))
|
||||
self.assertEqual(1, omitted_count)
|
||||
self.assertTrue(images[0]["image_base64"].endswith("source.png"))
|
||||
self.assertTrue(images[-1]["image_base64"].endswith("source-8.png"))
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_build_cmhub_images_rejects_oversized_total_payload(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
_, _, source = self._project_source(temp_dir)
|
||||
with mock.patch(
|
||||
"app.image_studio_generation.ai._image_data_url",
|
||||
return_value="x" * 32,
|
||||
), mock.patch.object(
|
||||
image_studio_generation,
|
||||
"CMHUB_IMAGE_STUDIO_MAX_TOTAL_INPUT_BYTES",
|
||||
16,
|
||||
):
|
||||
with self.assertRaisesRegex(
|
||||
image_studio_generation.ImageStudioGenerationError,
|
||||
"总大小超过32MiB",
|
||||
):
|
||||
image_studio_generation._build_cmhub_images(source)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user