2 Commits
Author SHA1 Message Date
John Lancaster 34468c521f debug tweaks 2026-06-28 13:42:44 -05:00
John Lancaster b682e092ea test_upload_page 2026-06-28 13:42:05 -05:00
2 changed files with 31 additions and 42 deletions
+2 -1
View File
@@ -12,7 +12,8 @@
"transcription.app:create_app", "transcription.app:create_app",
"--factory", "--factory",
"--host", "--host",
"127.0.0.1", // "127.0.0.1",
"0.0.0.0",
"--port", "--port",
"8080" "8080"
], ],
+28 -40
View File
@@ -1,53 +1,41 @@
"""Tests for transcription.ui.upload_page.""" """Tests for the upload page route."""
from pathlib import Path from pathlib import Path
from uuid import uuid4
import pytest import pytest
from fastapi.testclient import TestClient
from transcription.services.upload import UploadError, UploadJobResult from transcription.app import create_app
from transcription.ui import upload_page from transcription.config import Settings
from transcription.config import _settings
@pytest.mark.unit @pytest.fixture
class TestUploadPageBehavior: def client(tmp_path: Path):
"""Verify upload page helper and submission behavior.""" """Provide a real app client backed by in-memory SQLite."""
settings = Settings(
def test_accepted_upload_types_contains_supported_extensions(self): openrouter_api_key="test-key",
"""accepted_upload_types includes all MVP-supported upload extensions.""" database_url="sqlite:///:memory:",
accepted = upload_page.accepted_upload_types() environment="test",
assert ".jpg" in accepted upload_dir=tmp_path / "uploads",
assert ".jpeg" in accepted prompt_dir=tmp_path / "prompts",
assert ".png" in accepted
assert ".tif" in accepted
assert ".tiff" in accepted
assert ".pdf" in accepted
def test_submit_upload_calls_upload_service(self, monkeypatch):
"""submit_upload delegates file persistence and job creation to upload service."""
expected = UploadJobResult(
document_id=uuid4(),
job_id=uuid4(),
stored_path=Path("uploads/mock.jpg"),
original_filename="mock.jpg",
) )
_settings.set(settings)
def fake_create_upload_job(*, filename: str, file_bytes: bytes): app = create_app()
assert filename == "mock.jpg" with TestClient(app) as test_client:
assert file_bytes == b"bytes" yield test_client
return expected
monkeypatch.setattr(upload_page, "create_upload_job", fake_create_upload_job)
result = upload_page.submit_upload(filename="mock.jpg", file_bytes=b"bytes") @pytest.mark.integration
assert result == expected class TestPageRendering:
"""Verify the upload page is available and includes the main controls."""
def test_submit_upload_surfaces_upload_error(self, monkeypatch): def test_upload_page_renders_expected_controls(self, client):
"""submit_upload raises UploadError for invalid upload payloads.""" """GET /ui/upload returns the page shell and upload controls."""
def fake_create_upload_job(*, filename: str, file_bytes: bytes): response = client.get("/ui/upload")
raise UploadError("invalid payload")
monkeypatch.setattr(upload_page, "create_upload_job", fake_create_upload_job) assert response.status_code == 200
assert "Upload Document" in response.text
with pytest.raises(UploadError): assert "Select document file" in response.text
upload_page.submit_upload(filename="bad.jpg", file_bytes=b"") assert "View jobs" in response.text