test_model_assign_drops_nozzle_mapping.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """An "Any <model>" job does not carry a nozzle mapping onto the printer it gets.
  2. Every move from one printer to another resets the printer-specific settings
  3. (drop_printer_resolved), but the model-based assignment dropped only the AMS
  4. mapping. A nozzle mapping on a model job (set through the API, a variant or an
  5. order's plate spec) was then sent as-is and skipped the rack resolve for the
  6. printer actually picked.
  7. """
  8. import pytest
  9. from backend.app.models.library import LibraryFile
  10. from backend.app.models.print_queue import PrintQueueItem
  11. from backend.app.services.print_scheduler import PrintScheduler
  12. from backend.tests.unit.test_scheduler_pinned_waiting_reason_3074 import (
  13. _add_item,
  14. _item,
  15. _run,
  16. ctx, # noqa: F401 - fixture
  17. )
  18. @pytest.mark.asyncio
  19. async def test_the_picked_printer_works_its_own_mapping_out(ctx):
  20. """On a nozzle-rack printer (H2C) the mapping names rack positions."""
  21. from backend.app.models.printer import Printer
  22. async with ctx.session_maker() as db:
  23. printer = await db.get(Printer, 1)
  24. printer.model = "H2C"
  25. await db.commit()
  26. item_id = await _add_item(ctx, printer_id=None, target_model="H2C")
  27. async with ctx.session_maker() as db:
  28. item = await db.get(PrintQueueItem, item_id)
  29. item.nozzle_mapping = "[16, 17]"
  30. library_file = await db.get(LibraryFile, item.library_file_id)
  31. library_file.file_metadata = {"sliced_for_model": "H2C"} # else the cross-model gate holds it
  32. await db.commit()
  33. launched = await _run(ctx, PrintScheduler(), idle=True)
  34. launched.assert_called_once()
  35. item = await _item(ctx, item_id)
  36. assert item.printer_id == 1
  37. assert item.nozzle_mapping is None
  38. @pytest.mark.asyncio
  39. async def test_on_a_dual_nozzle_printer_without_a_rack_the_mapping_stays(ctx):
  40. """An H2D's nozzle mapping holds extruder indices, the same on every H2D:
  41. the slicer's pick from an "any printer" VP must survive assignment."""
  42. from backend.app.models.printer import Printer
  43. async with ctx.session_maker() as db:
  44. printer = await db.get(Printer, 1)
  45. printer.model = "H2D"
  46. await db.commit()
  47. item_id = await _add_item(ctx, printer_id=None, target_model="H2D")
  48. async with ctx.session_maker() as db:
  49. item = await db.get(PrintQueueItem, item_id)
  50. item.nozzle_mapping = "[0, 1]"
  51. library_file = await db.get(LibraryFile, item.library_file_id)
  52. library_file.file_metadata = {"sliced_for_model": "H2D"}
  53. await db.commit()
  54. launched = await _run(ctx, PrintScheduler(), idle=True)
  55. launched.assert_called_once()
  56. assert (await _item(ctx, item_id)).nozzle_mapping == "[0, 1]"