test_archive_edit_status_words.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """The statuses an archive can be given by hand.
  2. The finished outcomes only: completed, failed, aborted and cancelled. An
  3. archive set to 'printing' by hand is closed again at the next reconnect as a
  4. missed completion, with notifications and a Print History entry of its own.
  5. """
  6. import pytest
  7. from httpx import AsyncClient
  8. from sqlalchemy import select
  9. from backend.app.models.print_log import PrintLogEntry
  10. @pytest.mark.asyncio
  11. @pytest.mark.integration
  12. @pytest.mark.parametrize("status", ["completed", "failed", "aborted", "cancelled"])
  13. async def test_a_finished_outcome_is_set_and_mirrored(
  14. async_client: AsyncClient, archive_factory, printer_factory, db_session, status
  15. ):
  16. printer = await printer_factory()
  17. archive = await archive_factory(printer.id, status="completed" if status != "completed" else "failed")
  18. response = await async_client.patch(f"/api/v1/archives/{archive.id}", json={"status": status})
  19. assert response.status_code == 200
  20. assert response.json()["status"] == status
  21. run = await db_session.scalar(select(PrintLogEntry).where(PrintLogEntry.archive_id == archive.id))
  22. await db_session.refresh(run)
  23. assert run.status == status
  24. @pytest.mark.asyncio
  25. @pytest.mark.integration
  26. @pytest.mark.parametrize("status", ["printing", "archived", "stopped", "bogus"])
  27. async def test_any_other_status_is_refused(
  28. async_client: AsyncClient, archive_factory, printer_factory, db_session, status
  29. ):
  30. printer = await printer_factory()
  31. archive = await archive_factory(printer.id, status="completed")
  32. response = await async_client.patch(f"/api/v1/archives/{archive.id}", json={"status": status})
  33. assert response.status_code == 422
  34. run = await db_session.scalar(select(PrintLogEntry).where(PrintLogEntry.archive_id == archive.id))
  35. await db_session.refresh(run)
  36. assert run.status == "completed"