test_expected_print_creator_cleared.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """A matched expected print takes its creator record with it (EP-2).
  2. A queued print registers who started it under every name variant. The start
  3. handler removed that record only when the print's archive was still there
  4. and no start notification had gone out; the 2-hour expiry sweeps by the
  5. expected-print entries, which the match had already removed. A leftover
  6. record then named -- and emailed -- that user for an unrelated later print
  7. of the same name on that printer.
  8. """
  9. import pytest
  10. from backend.app import main
  11. from backend.tests.unit import test_plate_check_chamber_light as harness
  12. pytestmark = pytest.mark.asyncio
  13. # The harness's own autouse fixtures (dict clearing, light count) are not
  14. # collected here, so take them explicitly.
  15. _clear_dicts = harness._clear_dicts
  16. _light_count = harness._light_count
  17. async def test_a_print_whose_archive_is_gone_leaves_no_creator(_clear_dicts, _light_count):
  18. # The harness's session finds no archive: it was deleted mid-dispatch.
  19. main.register_expected_print(1, "Benchy.3mf", 999, created_by_id=7)
  20. assert main._expected_print_creators
  21. await harness._run_print_start([], check_plate_empty=harness._objects_on_plate())
  22. # The match took the expected print, and no creator record outlives the
  23. # entries the expiry sweeps by (a name variant the match did not try
  24. # keeps both, and the sweep takes them together).
  25. assert 999 not in {main._expected_prints.get(k) for k in [(1, "Benchy.3mf"), (1, "Benchy")]}
  26. orphaned = set(main._expected_print_creators) - set(main._expected_print_registered_at)
  27. assert not orphaned