test_printer_model_codes.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """Bambu internal model codes resolve to the right printer everywhere.
  2. The codes are shared by the SSDP DevModel header (so ``Printer.model`` of an
  3. older install can hold them) and slice_info's ``printer_model_id``. A real P1P
  4. 3MF carries ``C11`` next to "Bambu Lab P1P", and the X1 Carbon's code is
  5. ``BL-P001``. Several maps had the C-codes shifted onto the wrong printers:
  6. C11/C12 read as X1C/X1, the X1E's C13 checked P2S firmware, and the P2S's N7
  7. was missing, which left a P2S file's ``sliced_for_model`` as the raw code.
  8. """
  9. import pytest
  10. from backend.app.services.firmware_check import FirmwareCheckService
  11. from backend.app.utils.printer_models import (
  12. get_rod_type,
  13. has_ethernet,
  14. has_remote_storage_toggle,
  15. is_gcode_compatible,
  16. normalize_printer_model_id,
  17. )
  18. CODES = [
  19. ("BL-P001", "X1C"),
  20. ("BL-P002", "X1"),
  21. ("C13", "X1E"),
  22. ("C11", "P1P"),
  23. ("C12", "P1S"),
  24. ("N7", "P2S"),
  25. ("N6", "X2D"),
  26. ("O1D", "H2D"),
  27. ("N2S", "A1"),
  28. ("N1", "A1 Mini"),
  29. ]
  30. @pytest.mark.parametrize(("code", "name"), CODES)
  31. def test_code_resolves_to_its_printer(code, name):
  32. assert normalize_printer_model_id(code) == name
  33. @pytest.mark.parametrize(("code", "name"), CODES)
  34. def test_capabilities_agree_between_code_and_name(code, name):
  35. assert has_ethernet(code) == has_ethernet(name)
  36. assert get_rod_type(code) == get_rod_type(name)
  37. assert has_remote_storage_toggle(code) == has_remote_storage_toggle(name)
  38. def test_the_p1p_has_no_ethernet_and_the_x1c_has():
  39. assert not has_ethernet("C11")
  40. assert has_ethernet("BL-P001")
  41. def test_a_p2s_file_can_go_to_a_p2s():
  42. # A 3MF without printer_model in project_settings keeps the resolved
  43. # printer_model_id as sliced_for_model; for N7 that used to be "N7",
  44. # which the dispatch gate compared against "P2S" and refused.
  45. assert is_gcode_compatible(normalize_printer_model_id("N7"), "P2S")
  46. @pytest.mark.parametrize(
  47. ("model", "key"),
  48. [("C13", "x1e"), ("X1E", "x1e"), ("C11", "p1"), ("C12", "p1"), ("N7", "p2s"), ("BL-P001", "x1")],
  49. )
  50. def test_firmware_line_for_code(model, key):
  51. assert FirmwareCheckService()._resolve_api_key(model) == key