test_webhook_reprint_slicer_mapping.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """A webhook reprint keeps the slicer's AMS slots, as a reprint from the UI does (F9).
  2. An archive printed through the virtual printer remembers which AMS slots the
  3. slicer picked on its printer. Queued again for that printer from the UI, the
  4. job reuses them; queued through the webhook it did not, and the scheduler
  5. matched slots by colour and type again, possibly other spools.
  6. """
  7. import pytest
  8. from sqlalchemy import select
  9. from backend.app.models.print_queue import PrintQueueItem
  10. from backend.tests.integration.test_queue_creation_paths_c4 import _webhook_key
  11. pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
  12. async def _archive(db_session, archive_factory, printer_id: int):
  13. archive = await archive_factory(printer_id)
  14. archive.extra_data = {"slicer_ams_mapping": {"printer_id": printer_id, "mapping": [2, 0]}}
  15. await db_session.commit()
  16. return archive
  17. @pytest.mark.parametrize("for_its_printer", [True, False])
  18. async def test_the_webhook_reuses_the_slots_for_the_printer_they_were_picked_on(
  19. async_client, db_session, printer_factory, archive_factory, for_its_printer
  20. ):
  21. printer = await printer_factory()
  22. other = await printer_factory(name="Other")
  23. archive = await _archive(db_session, archive_factory, printer.id)
  24. response = await async_client.post(
  25. "/api/v1/webhook/queue/add",
  26. json={"printer_id": printer.id if for_its_printer else other.id, "archive_id": archive.id},
  27. headers=await _webhook_key(db_session),
  28. )
  29. assert response.status_code == 200, response.text
  30. item = await db_session.scalar(select(PrintQueueItem).where(PrintQueueItem.id == response.json()["id"]))
  31. # Slot numbers only mean something on the printer they were picked on
  32. assert item.ams_mapping == ("[2, 0]" if for_its_printer else None)