test_chamber_temp_ceiling.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """The chamber-temperature ceiling is shared by every surface that accepts one.
  2. Reported on Discord: the preheat & heat-soak inputs capped at 60 °C, which put
  3. the top of the H2 series' range (65 °C) out of reach. The ceiling now lives in
  4. one place — ``MAX_CHAMBER_TEMP_C`` — and these tests pin both its value and the
  5. fact that each schema actually derives its bound from it rather than carrying a
  6. private literal that could drift back to 60.
  7. """
  8. import pytest
  9. from pydantic import ValidationError
  10. from backend.app.schemas.print_queue import (
  11. PrintQueueBulkUpdate,
  12. PrintQueueItemCreate,
  13. PrintQueueItemUpdate,
  14. )
  15. from backend.app.schemas.settings import AppSettingsUpdate
  16. from backend.app.utils.printer_models import MAX_CHAMBER_TEMP_C
  17. # The H2 series (H2C / H2D / H2D Pro / H2S) and X2D heat the chamber to 65 °C.
  18. # X1E stops at 60 and clamps in firmware. Hard-coded here on purpose: if the
  19. # constant moves, that should be a deliberate edit, not a silent one.
  20. EXPECTED_CEILING = 65
  21. # (schema, kwargs the schema requires beyond the field under test)
  22. OVERRIDE_SCHEMAS = [
  23. (PrintQueueItemCreate, {}),
  24. (PrintQueueItemUpdate, {}),
  25. (PrintQueueBulkUpdate, {"item_ids": [1]}),
  26. ]
  27. def test_ceiling_is_65():
  28. assert MAX_CHAMBER_TEMP_C == EXPECTED_CEILING
  29. @pytest.mark.parametrize("schema,required", OVERRIDE_SCHEMAS)
  30. def test_override_accepts_the_ceiling(schema, required):
  31. model = schema(preheat_chamber_target_override=MAX_CHAMBER_TEMP_C, **required)
  32. assert model.preheat_chamber_target_override == MAX_CHAMBER_TEMP_C
  33. @pytest.mark.parametrize("schema,required", OVERRIDE_SCHEMAS)
  34. def test_override_rejects_above_the_ceiling(schema, required):
  35. with pytest.raises(ValidationError):
  36. schema(preheat_chamber_target_override=MAX_CHAMBER_TEMP_C + 1, **required)
  37. @pytest.mark.parametrize("schema,required", OVERRIDE_SCHEMAS)
  38. def test_override_still_accepts_zero(schema, required):
  39. """0 is "no chamber phase, even if the filament map wants one" — raising
  40. the ceiling must not disturb the low end."""
  41. model = schema(preheat_chamber_target_override=0, **required)
  42. assert model.preheat_chamber_target_override == 0
  43. def test_chamber_presets_accept_the_ceiling():
  44. payload = f"[35, 45, {MAX_CHAMBER_TEMP_C}]"
  45. assert AppSettingsUpdate(chamber_temp_presets=payload).chamber_temp_presets == payload
  46. def test_chamber_presets_reject_above_the_ceiling():
  47. with pytest.raises(ValidationError) as exc:
  48. AppSettingsUpdate(chamber_temp_presets=f"[35, 45, {MAX_CHAMBER_TEMP_C + 1}]")
  49. assert f"[0, {MAX_CHAMBER_TEMP_C}]" in str(exc.value)