test_active_print_binding_names.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """Every path that binds a running print registers the same names (AP-3).
  2. A restart resume registered only the archive's file name; the new-archive,
  3. expected and fallback paths each registered a different mix. When MQTT
  4. reported a name the binding path had left out, completion still found the
  5. archive by a name search but lost the binding, and with it the plate restore's
  6. height (#3240).
  7. """
  8. from types import SimpleNamespace
  9. import pytest
  10. from backend.app import main as main_module
  11. from backend.app.models.archive import PrintArchive
  12. from backend.tests.integration.test_external_print_confirmation_1898 import ( # noqa: F401
  13. DISPATCH,
  14. SUBTASK,
  15. _clear_print_state,
  16. _drive_print_start,
  17. )
  18. pytestmark = pytest.mark.integration
  19. @pytest.mark.asyncio
  20. async def test_a_print_resumed_after_a_restart_is_bound_under_the_printers_names(
  21. test_engine, db_session, printer_factory
  22. ):
  23. printer_id = (await printer_factory()).id
  24. archive = PrintArchive(
  25. printer_id=printer_id,
  26. filename="My Part.gcode.3mf",
  27. file_path="archives/test/My Part.gcode.3mf",
  28. file_size=1,
  29. print_name=SUBTASK,
  30. status="printing",
  31. )
  32. db_session.add(archive)
  33. await db_session.commit()
  34. await _drive_print_start(
  35. test_engine, SimpleNamespace(id=printer_id), download_ok=False, state_fields={"progress": 40}
  36. )
  37. bound = {
  38. name
  39. for (pid, name), archive_id in main_module._active_prints.items()
  40. if pid == printer_id and archive_id == archive.id
  41. }
  42. assert {"My Part.gcode.3mf", SUBTASK, f"{SUBTASK}.3mf", DISPATCH} <= bound
  43. def test_the_binding_names_are_one_set():
  44. main_module._active_prints.clear()
  45. main_module._bind_active_print(3, 9, "a.gcode.3mf", "/data/Metadata/plate_1.gcode", "a")
  46. assert {name for (_pid, name) in main_module._active_prints} == {
  47. "a.gcode.3mf",
  48. "/data/Metadata/plate_1.gcode",
  49. "a.3mf",
  50. "a",
  51. }
  52. main_module._active_prints.clear()