Implement image upload functionality with metadata storage; update frontend to display uploaded images
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -148,9 +148,10 @@ def test_dashboard_requires_login(client):
|
||||
|
||||
def test_dashboard_renders_user_info(client):
|
||||
_set_auth(client)
|
||||
mock = _mock_response(
|
||||
me_mock = _mock_response(
|
||||
200, {"id": "1", "email": "u@example.com", "role": "user"})
|
||||
with patch("frontend.app.main.httpx.request", return_value=mock):
|
||||
images_mock = _mock_response(200, [])
|
||||
with patch("frontend.app.main.httpx.request", side_effect=[me_mock, images_mock]):
|
||||
resp = client.get("/dashboard")
|
||||
assert resp.status_code == 200
|
||||
assert b"u@example.com" in resp.data
|
||||
@@ -418,4 +419,77 @@ def test_video_generate_renders_polling_ui(client):
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert b"video-poll-status" in resp.data
|
||||
assert b"openrouter.ai/api/v1/videos/v1" in resp.data
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Image upload — frontend proxy + dashboard
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_dashboard_shows_uploaded_images(client):
|
||||
_set_auth(client)
|
||||
me_mock = _mock_response(
|
||||
200, {"id": "1", "email": "u@example.com", "role": "user"})
|
||||
images_mock = _mock_response(200, [
|
||||
{"id": "img-1", "filename": "cat.png", "content_type": "image/png",
|
||||
"size_bytes": 1024, "created_at": "2026-04-29T10:00:00"},
|
||||
])
|
||||
with patch("frontend.app.main.httpx.request", side_effect=[me_mock, images_mock]):
|
||||
resp = client.get("/dashboard")
|
||||
assert resp.status_code == 200
|
||||
assert b"cat.png" in resp.data
|
||||
assert b"img-1" in resp.data
|
||||
|
||||
|
||||
def test_dashboard_no_images_section_when_empty(client):
|
||||
_set_auth(client)
|
||||
me_mock = _mock_response(
|
||||
200, {"id": "1", "email": "u@example.com", "role": "user"})
|
||||
images_mock = _mock_response(200, [])
|
||||
with patch("frontend.app.main.httpx.request", side_effect=[me_mock, images_mock]):
|
||||
resp = client.get("/dashboard")
|
||||
assert resp.status_code == 200
|
||||
assert b"Uploaded reference images" not in resp.data
|
||||
|
||||
|
||||
def test_serve_uploaded_image_proxy(client):
|
||||
_set_auth(client)
|
||||
img_bytes = b"\x89PNG\r\n\x1a\n"
|
||||
mock = MagicMock()
|
||||
mock.status_code = 200
|
||||
mock.content = img_bytes
|
||||
mock.headers = {"content-type": "image/png"}
|
||||
with patch("frontend.app.main.httpx.request", return_value=mock):
|
||||
resp = client.get("/images/img-1/file")
|
||||
assert resp.status_code == 200
|
||||
assert resp.content_type == "image/png"
|
||||
assert resp.data == img_bytes
|
||||
|
||||
|
||||
def test_serve_uploaded_image_requires_login(client):
|
||||
resp = client.get("/images/img-1/file")
|
||||
assert resp.status_code == 302
|
||||
assert "/login" in resp.headers["Location"]
|
||||
|
||||
|
||||
def test_serve_uploaded_image_not_found_proxied(client):
|
||||
_set_auth(client)
|
||||
mock = _mock_response(404, {"detail": "Image not found."})
|
||||
mock.content = b""
|
||||
with patch("frontend.app.main.httpx.request", return_value=mock):
|
||||
resp = client.get("/images/bad-id/file")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_generate_image_uploads_reference_then_generates(client):
|
||||
_set_auth(client)
|
||||
gen_mock = _mock_response(200, {
|
||||
"id": "g2", "model": "openai/dall-e-3",
|
||||
"images": [{"url": "https://example.com/out.png", "revised_prompt": None, "b64_json": None}]
|
||||
})
|
||||
# No file field → upload branch skipped; only generate call is made
|
||||
with patch("frontend.app.main.httpx.request", return_value=gen_mock):
|
||||
resp = client.post("/generate/image", data={
|
||||
"model": "openai/dall-e-3", "prompt": "A cat", "n": "1", "size": "1024x1024",
|
||||
}, content_type="multipart/form-data")
|
||||
assert resp.status_code == 200
|
||||
assert b"example.com/out.png" in resp.data
|
||||
|
||||
Reference in New Issue
Block a user