Add tests, docs, and changelog for #920 + #932

Audit PRs #920 (printers search/filter) and #932 (print from project
  view) for regressions, i18n coverage, test gaps, and docs.

  No regressions found: existing callers of the changed signatures
  (archive_print, getLibraryFiles, filteredPrinters chain) are unaffected;
  i18n is complete in all 7 locales for both features.

  Backend tests (4 new, all passing):
  - test_list_files_by_project_id — bulk JOIN returns files across all
    linked folders, excludes unlinked ones
  - test_list_files_folder_id_takes_precedence_over_project_id — guards
    the documented precedence folder_id > project_id > include_root
  - test_add_to_queue_with_project_id — project_id is persisted on the
    queue row for later archive linkage
  - test_add_to_queue_invalid_project_id_returns_404 — regression guard
    for the validation pre-check on the queue path (mirrors the one on
    the direct-print path in library.py)
This commit is contained in:
maziggy
2026-04-10 13:09:21 +02:00
parent f95b2acd7d
commit b01b5e05fd
8 changed files with 590 additions and 469 deletions
@@ -147,6 +147,62 @@ class TestPrintQueueAPI:
assert result["status"] == "pending"
assert result["manual_start"] is True
@pytest.mark.asyncio
@pytest.mark.integration
async def test_add_to_queue_with_project_id(
self, async_client: AsyncClient, printer_factory, archive_factory, db_session
):
"""#932: queue items created from the project view carry project_id forward."""
from backend.app.models.project import Project
printer = await printer_factory()
archive = await archive_factory()
project = Project(name="Queue Project")
db_session.add(project)
await db_session.commit()
await db_session.refresh(project)
data = {
"printer_id": printer.id,
"archive_id": archive.id,
"project_id": project.id,
}
response = await async_client.post("/api/v1/queue/", json=data)
assert response.status_code == 200
result = response.json()
# The response schema may or may not echo project_id; the stored row is
# what matters, so verify via DB.
from sqlalchemy import select
from backend.app.models.print_queue import PrintQueueItem
row = (await db_session.execute(select(PrintQueueItem).where(PrintQueueItem.id == result["id"]))).scalar_one()
assert row.project_id == project.id
@pytest.mark.asyncio
@pytest.mark.integration
async def test_add_to_queue_invalid_project_id_returns_404(
self, async_client: AsyncClient, printer_factory, archive_factory, db_session
):
"""#932: bogus project_id must be rejected before the FK constraint fires.
Regression guard for the pre-check added to add_to_queue. Without the
validation, a nonexistent project_id would reach db.commit() and raise
an IntegrityError → 500. The pre-check must convert that to a 404 so
the UI gets a clean error it can surface.
"""
printer = await printer_factory()
archive = await archive_factory()
data = {
"printer_id": printer.id,
"archive_id": archive.id,
"project_id": 999999, # nonexistent
}
response = await async_client.post("/api/v1/queue/", json=data)
assert response.status_code == 404
assert "project" in response.json()["detail"].lower()
@pytest.mark.asyncio
@pytest.mark.integration
async def test_add_to_queue_with_ams_mapping(