| 307 | |
| 308 | |
| 309 | class RouteNormalizationTests(unittest.IsolatedAsyncioTestCase): |
| 310 | async def asyncSetUp(self): |
| 311 | self.client = FlowClient(proxy_manager=None) |
| 312 | self.client._acquire_video_launch_gate = AsyncMock(return_value=(True, None, None)) |
| 313 | self.client._release_video_launch_gate = AsyncMock() |
| 314 | self.client._get_recaptcha_token = AsyncMock(return_value=("recaptcha-token", "browser-1")) |
| 315 | self.client._notify_browser_captcha_request_finished = AsyncMock() |
| 316 | |
| 317 | async def test_openai_history_reference_image_can_drive_aspect_ratio(self): |
| 318 | portrait_image = _make_image_bytes((900, 1600)) |
| 319 | request = ChatCompletionRequest( |
| 320 | model="gemini-3.0-pro-image", |
| 321 | messages=[ |
| 322 | ChatMessage(role="user", content="先生成一张图"), |
| 323 | ChatMessage( |
| 324 | role="assistant", |
| 325 | content="", |
| 326 | ), |
| 327 | ChatMessage(role="user", content="基于上一张图继续编辑"), |
| 328 | ], |
| 329 | ) |
| 330 | |
| 331 | with patch( |
| 332 | "src.api.routes.retrieve_image_data", |
| 333 | new=AsyncMock(return_value=portrait_image), |
| 334 | ): |
| 335 | normalized = await _normalize_openai_request(request) |
| 336 | |
| 337 | self.assertEqual(normalized.model, "gemini-3.0-pro-image-portrait") |
| 338 | self.assertEqual(len(normalized.images), 1) |
| 339 | |
| 340 | async def test_check_video_status_uses_media_payload_and_normalizes_response(self): |
| 341 | captured = {} |
| 342 | |
| 343 | async def fake_make_request(method, url, json_data, use_at, at_token, **kwargs): |
| 344 | captured["json_data"] = json_data |
| 345 | return { |
| 346 | "media": [ |
| 347 | { |
| 348 | "name": "media-1", |
| 349 | "projectId": "project-1", |
| 350 | "mediaMetadata": { |
| 351 | "mediaStatus": { |
| 352 | "mediaGenerationStatus": "MEDIA_GENERATION_STATUS_SUCCESSFUL" |
| 353 | } |
| 354 | }, |
| 355 | "video": { |
| 356 | "fifeUrl": "https://flow-content.google/video/11111111-1111-1111-1111-111111111111?token=abc", |
| 357 | "generatedVideo": { |
| 358 | "aspectRatio": "VIDEO_ASPECT_RATIO_LANDSCAPE" |
| 359 | }, |
| 360 | }, |
| 361 | } |
| 362 | ] |
| 363 | } |
| 364 | |
| 365 | self.client._make_request = AsyncMock(side_effect=fake_make_request) |
| 366 |
nothing calls this directly
no outgoing calls
no test coverage detected