(
app: FastAPIAppAdapter,
authenticated_header: dict,
monkeypatch,
)
| 3379 | |
| 3380 | @pytest.mark.asyncio |
| 3381 | async def test_batch_upload_skills_partial_success( |
| 3382 | app: FastAPIAppAdapter, |
| 3383 | authenticated_header: dict, |
| 3384 | monkeypatch, |
| 3385 | ): |
| 3386 | async def _fake_sync_skills_to_active_sandboxes(): |
| 3387 | return |
| 3388 | |
| 3389 | def _fake_install_skill_from_zip( |
| 3390 | self, |
| 3391 | zip_path: str, |
| 3392 | *, |
| 3393 | overwrite: bool = True, |
| 3394 | ): |
| 3395 | _ = self, overwrite |
| 3396 | if "ok_skill" in zip_path: |
| 3397 | return "ok_skill" |
| 3398 | raise RuntimeError("install failed") |
| 3399 | |
| 3400 | monkeypatch.setattr( |
| 3401 | "astrbot.dashboard.services.skills_service.sync_skills_to_active_sandboxes", |
| 3402 | _fake_sync_skills_to_active_sandboxes, |
| 3403 | ) |
| 3404 | monkeypatch.setattr( |
| 3405 | "astrbot.dashboard.services.skills_service.SkillManager.install_skill_from_zip", |
| 3406 | _fake_install_skill_from_zip, |
| 3407 | ) |
| 3408 | |
| 3409 | test_client = app.test_client() |
| 3410 | |
| 3411 | boundary = "----AstrBotBatchBoundary" |
| 3412 | body = ( |
| 3413 | ( |
| 3414 | f"--{boundary}\r\n" |
| 3415 | 'Content-Disposition: form-data; name="files"; filename="ok_skill.zip"\r\n' |
| 3416 | "Content-Type: application/zip\r\n\r\n" |
| 3417 | ).encode() |
| 3418 | + b"fake-zip-1\r\n" |
| 3419 | + ( |
| 3420 | f"--{boundary}\r\n" |
| 3421 | 'Content-Disposition: form-data; name="files"; filename="bad_skill.zip"\r\n' |
| 3422 | "Content-Type: application/zip\r\n\r\n" |
| 3423 | ).encode() |
| 3424 | + b"fake-zip-2\r\n" |
| 3425 | + f"--{boundary}--\r\n".encode() |
| 3426 | ) |
| 3427 | headers = dict(authenticated_header) |
| 3428 | headers["Content-Type"] = f"multipart/form-data; boundary={boundary}" |
| 3429 | |
| 3430 | response = await test_client.post( |
| 3431 | "/api/skills/batch-upload", |
| 3432 | headers=headers, |
| 3433 | data=body, |
| 3434 | ) |
| 3435 | |
| 3436 | assert response.status_code == 200 |
| 3437 | data = await response.get_json() |
| 3438 | assert data["status"] == "ok" |
nothing calls this directly
no test coverage detected