fix(fc5): ruff (E712, ASYNC230/240, I001) + Credential.credential_type + FileStorage in api_migrate test
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+25
-17
@@ -3,15 +3,23 @@ import io
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
import backend.app.tasks.migration # noqa: F401 — register celery task
|
||||
|
||||
from backend.app import create_app
|
||||
from backend.app.celery_app import celery
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
def _file_storage(payload: dict, filename: str = "export.json") -> FileStorage:
|
||||
return FileStorage(
|
||||
stream=io.BytesIO(json.dumps(payload).encode("utf-8")),
|
||||
filename=filename,
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def app():
|
||||
return create_app()
|
||||
@@ -46,7 +54,7 @@ async def test_post_rejects_unknown_kind(client):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_post_ingest_rejects_missing_file(client):
|
||||
resp = await client.post("/api/migrate/gs_ingest", data={})
|
||||
resp = await client.post("/api/migrate/gs_ingest", form={})
|
||||
assert resp.status_code == 400
|
||||
body = await resp.get_json()
|
||||
assert body["error"] == "missing_export_file"
|
||||
@@ -67,11 +75,11 @@ async def test_post_ingest_accepts_multipart_file(client, monkeypatch):
|
||||
"source_app": "gallerysubscriber", "schema_version": 1,
|
||||
"subscriptions": [], "credentials": [],
|
||||
}
|
||||
data = {
|
||||
"export_file": (io.BytesIO(json.dumps(export).encode()), "gs-export.json"),
|
||||
"dry_run": "false",
|
||||
}
|
||||
resp = await client.post("/api/migrate/gs_ingest", files=data)
|
||||
resp = await client.post(
|
||||
"/api/migrate/gs_ingest",
|
||||
form={"dry_run": "false"},
|
||||
files={"export_file": _file_storage(export, "gs-export.json")},
|
||||
)
|
||||
assert resp.status_code == 202
|
||||
|
||||
|
||||
@@ -85,11 +93,11 @@ async def test_post_apply_without_backup_rejected(client, monkeypatch):
|
||||
"source_app": "gallerysubscriber", "schema_version": 1,
|
||||
"subscriptions": [], "credentials": [],
|
||||
}
|
||||
data = {
|
||||
"export_file": (io.BytesIO(json.dumps(export).encode()), "gs-export.json"),
|
||||
"dry_run": "false",
|
||||
}
|
||||
resp = await client.post("/api/migrate/gs_ingest", files=data)
|
||||
resp = await client.post(
|
||||
"/api/migrate/gs_ingest",
|
||||
form={"dry_run": "false"},
|
||||
files={"export_file": _file_storage(export, "gs-export.json")},
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
body = await resp.get_json()
|
||||
assert body["error"] == "no_backup"
|
||||
@@ -109,11 +117,11 @@ async def test_post_dry_run_allowed_without_backup(client, monkeypatch):
|
||||
"source_app": "gallerysubscriber", "schema_version": 1,
|
||||
"subscriptions": [], "credentials": [],
|
||||
}
|
||||
data = {
|
||||
"export_file": (io.BytesIO(json.dumps(export).encode()), "gs-export.json"),
|
||||
"dry_run": "true",
|
||||
}
|
||||
resp = await client.post("/api/migrate/gs_ingest", files=data)
|
||||
resp = await client.post(
|
||||
"/api/migrate/gs_ingest",
|
||||
form={"dry_run": "true"},
|
||||
files={"export_file": _file_storage(export, "gs-export.json")},
|
||||
)
|
||||
assert resp.status_code == 202
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user