feat(settings): support gateway source switching
This commit is contained in:
@@ -149,6 +149,104 @@ class ImageStudioGenerationTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_direct_gateway_rejects_new_suite_job_before_creation(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, source = self._project_source(temp_dir)
|
||||
cfg["ai"]["backend"] = "direct"
|
||||
|
||||
with mock.patch("app.image_studio_generation.image_studio.create_job") as create_job:
|
||||
with self.assertRaises(image_studio_generation.ImageStudioGenerationError):
|
||||
image_studio_generation.create_generation_jobs(
|
||||
project.id,
|
||||
source.id,
|
||||
"不应提交",
|
||||
1,
|
||||
config=cfg,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
create_job.assert_not_called()
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_resume_rejects_non_default_gateway_task_without_reading_gateway_config(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, source = self._project_source(temp_dir)
|
||||
cfg["ai"]["backend"] = "direct"
|
||||
job = image_studio.create_job(
|
||||
project.id,
|
||||
source_asset_id=source.id,
|
||||
job_type="白底图",
|
||||
prompt="旧任务",
|
||||
generation_source="direct",
|
||||
provider="direct",
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
job = image_studio.set_job_submitted(
|
||||
job.id,
|
||||
"custom-task-1",
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
with mock.patch("app.image_studio_generation._runtime") as runtime:
|
||||
summary = image_studio_generation.run_jobs(
|
||||
[job],
|
||||
config=cfg,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
runtime.assert_not_called()
|
||||
self.assertEqual(1, summary["total"])
|
||||
self.assertEqual(1, summary["failed"])
|
||||
self.assertIn("不属于默认网关", summary["jobs"][0]["error"])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_direct_selection_still_resumes_submitted_default_gateway_task(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, source = self._project_source(temp_dir)
|
||||
cfg["ai"]["backend"] = "direct"
|
||||
job = image_studio.create_job(
|
||||
project.id,
|
||||
source_asset_id=source.id,
|
||||
job_type="白底图",
|
||||
prompt="已扣点图片",
|
||||
generation_source="cmhub",
|
||||
provider="cmhub",
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
job = image_studio.set_job_submitted(
|
||||
job.id,
|
||||
"cmhub-task-1",
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
with mock.patch(
|
||||
"app.image_studio_generation._runtime",
|
||||
return_value=self._runtime(),
|
||||
), mock.patch(
|
||||
"app.image_studio_generation.ai._cmhub_call_once",
|
||||
return_value={
|
||||
"task_id": "cmhub-task-1",
|
||||
"status": "succeeded",
|
||||
"result": {"image_url": "https://cdn.example.com/result.png"},
|
||||
},
|
||||
) as poll, mock.patch(
|
||||
"app.image_studio_generation.ai._download_cmhub_image_with_retry",
|
||||
return_value=(self._png_bytes(), 0.1),
|
||||
):
|
||||
summary = image_studio_generation.run_jobs(
|
||||
[job],
|
||||
config=cfg,
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
poll.assert_called_once()
|
||||
self.assertEqual(1, summary["success"])
|
||||
self.assertEqual("succeeded", image_studio.get_job(job.id, path=cfg["db_path"]).status)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_generate_image_jobs_sends_selected_aspect_ratio(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, project, source = self._project_source(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user