test_printer_models.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. """Unit tests for printer model utilities."""
  2. import pytest
  3. from backend.app.services.camera import get_camera_port, supports_rtsp
  4. from backend.app.utils.printer_models import (
  5. CARBON_ROD_MODELS,
  6. STEEL_ROD_MODELS,
  7. get_rod_type,
  8. has_ethernet,
  9. normalize_printer_model,
  10. normalize_printer_model_id,
  11. )
  12. class TestGetRodType:
  13. """Tests for get_rod_type() rod/rail classification."""
  14. @pytest.mark.parametrize("model", ["X1C", "X1", "X1E", "P1P", "P1S"])
  15. def test_carbon_rod_models(self, model: str):
  16. assert get_rod_type(model) == "carbon"
  17. @pytest.mark.parametrize("model", ["C11", "C12", "C13"])
  18. def test_carbon_rod_internal_codes(self, model: str):
  19. assert get_rod_type(model) == "carbon"
  20. def test_p2s_is_steel_rod(self):
  21. """P2S uses hardened steel rods, not carbon rods (#640)."""
  22. assert get_rod_type("P2S") == "steel_rod"
  23. def test_p2s_internal_code_is_steel_rod(self):
  24. """N7 (P2S internal code) uses steel rods."""
  25. assert get_rod_type("N7") == "steel_rod"
  26. @pytest.mark.parametrize("model", ["A1", "A1 Mini", "H2D", "H2D Pro", "H2C", "H2S"])
  27. def test_linear_rail_models(self, model: str):
  28. assert get_rod_type(model) == "linear_rail"
  29. @pytest.mark.parametrize("model", ["N1", "N2S", "A11", "A12", "O1D", "O1E", "O2D", "O1C", "O1C2", "O1S"])
  30. def test_linear_rail_internal_codes(self, model: str):
  31. assert get_rod_type(model) == "linear_rail"
  32. def test_unknown_model_returns_none(self):
  33. assert get_rod_type("UNKNOWN") is None
  34. def test_none_returns_none(self):
  35. assert get_rod_type(None) is None
  36. def test_case_insensitive(self):
  37. assert get_rod_type("p2s") == "steel_rod"
  38. assert get_rod_type("x1c") == "carbon"
  39. assert get_rod_type("a1") == "linear_rail"
  40. def test_strips_whitespace_and_dashes(self):
  41. assert get_rod_type(" P2S ") == "steel_rod"
  42. assert get_rod_type("A1-Mini") == "linear_rail"
  43. class TestX2DModel:
  44. """X2D printer support (issue #988).
  45. The X2D is a dual-nozzle enclosed printer launched April 2026. It shares
  46. the hardened steel rod hardware with P2S (NOT carbon rods) and uses
  47. RTSP on port 322 like other X/H series printers. Internal SSDP/MQTT
  48. model code is "N6"; serial numbers begin with "20P9".
  49. """
  50. def test_x2d_is_steel_rod_display_name(self):
  51. assert get_rod_type("X2D") == "steel_rod"
  52. def test_x2d_is_steel_rod_internal_code(self):
  53. assert get_rod_type("N6") == "steel_rod"
  54. def test_x2d_model_id_map(self):
  55. assert normalize_printer_model_id("N6") == "X2D"
  56. def test_x2d_model_map(self):
  57. assert normalize_printer_model("Bambu Lab X2D") == "X2D"
  58. def test_x2d_has_ethernet_display_name(self):
  59. assert has_ethernet("X2D") is True
  60. def test_x2d_has_ethernet_internal_code(self):
  61. assert has_ethernet("N6") is True
  62. def test_x2d_supports_rtsp_display_name(self):
  63. assert supports_rtsp("X2D") is True
  64. def test_x2d_supports_rtsp_internal_code(self):
  65. assert supports_rtsp("N6") is True
  66. def test_x2d_camera_port_is_rtsp(self):
  67. assert get_camera_port("N6") == 322
  68. assert get_camera_port("X2D") == 322
  69. def test_x2d_not_in_carbon_rod_set(self):
  70. """Regression guard: X2D has hardened steel rods, not carbon (#988).
  71. A prior PR classified X2D as carbon; the reporter confirmed it uses
  72. the same stainless steel rod gantry as P2S. This assertion pins the
  73. classification so a future change that reverts it will fail loudly.
  74. """
  75. assert "X2D" not in CARBON_ROD_MODELS
  76. assert "N6" not in CARBON_ROD_MODELS
  77. assert "X2D" in STEEL_ROD_MODELS
  78. assert "N6" in STEEL_ROD_MODELS