test_configure_setting_id_3444.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. """A Bambu setting id sent to Configure as the filament id (#3444).
  2. The reporter's iOS client called ``/slots/{ams}/{tray}/configure`` with a
  3. spool's ``slicer_filament`` as ``tray_info_idx``: "GFSL99", a setting id. The
  4. route passed it on, the P1S reported the slot blank and auto-unlink dropped the
  5. spool. The assignment path converts it (normalize_slicer_filament); Configure
  6. now does the same, with the #3387 helper.
  7. """
  8. from unittest.mock import MagicMock, patch
  9. import pytest
  10. from httpx import AsyncClient
  11. def _client():
  12. client = MagicMock()
  13. client.ams_set_filament_setting.return_value = True
  14. client.extrusion_cali_sel.return_value = True
  15. return client
  16. def _status():
  17. status = MagicMock()
  18. status.raw_data = {"ams": {"ams": []}}
  19. status.nozzles = [MagicMock(nozzle_diameter="0.4")]
  20. status.ams_extruder_map = None
  21. status.kprofiles = []
  22. return status
  23. async def _configure(async_client, printer_id, **params):
  24. client = _client()
  25. with patch("backend.app.api.routes.printers.printer_manager") as pm:
  26. pm.get_client.return_value = client
  27. pm.get_status.return_value = _status()
  28. response = await async_client.post(
  29. f"/api/v1/printers/{printer_id}/slots/0/0/configure",
  30. params={
  31. "tray_type": "PLA",
  32. "tray_sub_brands": "Generic PLA",
  33. "tray_color": "000000FF",
  34. "nozzle_temp_min": 190,
  35. "nozzle_temp_max": 250,
  36. **params,
  37. },
  38. )
  39. assert response.status_code == 200, response.text
  40. return client
  41. @pytest.mark.asyncio
  42. @pytest.mark.integration
  43. @pytest.mark.parametrize(
  44. ("sent", "filament_id", "setting_id"),
  45. [
  46. ("GFSL99", "GFL99", "GFSL99"), # the report
  47. ("GFSL99_02", "GFL99", "GFSL99_02"), # with its version
  48. ("GFSA05_10", "GFA01", "GFSA05_10"), # Bambu gives this one Matte's id (#3387)
  49. ("GFSNLS03", "GFSNL03", "GFSNLS03"), # SUNLU
  50. ],
  51. )
  52. async def test_a_setting_id_is_sent_as_its_filament_id(
  53. async_client: AsyncClient, printer_factory, sent, filament_id, setting_id
  54. ):
  55. printer = await printer_factory(model="P1S")
  56. client = await _configure(async_client, printer.id, tray_info_idx=sent)
  57. slot = client.ams_set_filament_setting.call_args.kwargs
  58. assert slot["tray_info_idx"] == filament_id
  59. assert slot["setting_id"] == setting_id
  60. assert client.extrusion_cali_sel.call_args.kwargs["filament_id"] == filament_id
  61. @pytest.mark.asyncio
  62. @pytest.mark.integration
  63. @pytest.mark.parametrize("sent", ["GFL99", "GFS99", "GFSNL03", "P4d64437"])
  64. async def test_filament_ids_are_left_alone(async_client: AsyncClient, printer_factory, sent):
  65. """Support ids ("GFS99") and SUNLU's ("GFSNL03") start with GFS but are filament ids."""
  66. printer = await printer_factory(model="P1S")
  67. client = await _configure(async_client, printer.id, tray_info_idx=sent)
  68. assert client.ams_set_filament_setting.call_args.kwargs["tray_info_idx"] == sent
  69. @pytest.mark.asyncio
  70. @pytest.mark.integration
  71. async def test_the_clients_own_setting_id_is_kept(async_client: AsyncClient, printer_factory):
  72. printer = await printer_factory(model="P1S")
  73. client = await _configure(async_client, printer.id, tray_info_idx="GFSL99", setting_id="GFSL99_01")
  74. slot = client.ams_set_filament_setting.call_args.kwargs
  75. assert (slot["tray_info_idx"], slot["setting_id"]) == ("GFL99", "GFSL99_01")
  76. @pytest.mark.asyncio
  77. @pytest.mark.integration
  78. async def test_a_k_profile_setting_id_is_converted_too(async_client: AsyncClient, printer_factory):
  79. """The K profile's filament id becomes the slot's when they differ, and the
  80. calibration table is keyed by filament ids."""
  81. printer = await printer_factory(model="P1S")
  82. client = await _configure(
  83. async_client, printer.id, tray_info_idx="GFL99", cali_idx=3, kprofile_filament_id="GFSL99_02"
  84. )
  85. slot = client.ams_set_filament_setting.call_args.kwargs
  86. assert slot["tray_info_idx"] == "GFL99"
  87. assert client.extrusion_cali_sel.call_args.kwargs["filament_id"] == "GFL99"
  88. @pytest.mark.asyncio
  89. @pytest.mark.integration
  90. async def test_a_k_profile_for_another_preset_realigns_the_slot_with_its_filament_id(
  91. async_client: AsyncClient, printer_factory
  92. ):
  93. """Realigned to the K profile, the slot gets its filament id, and its setting id as setting_id."""
  94. printer = await printer_factory(model="P1S")
  95. client = await _configure(
  96. async_client, printer.id, tray_info_idx="GFL99", cali_idx=3, kprofile_filament_id="GFSL05_07"
  97. )
  98. slot = client.ams_set_filament_setting.call_args.kwargs
  99. assert (slot["tray_info_idx"], slot["setting_id"]) == ("GFL05", "GFSL05_07")
  100. assert client.extrusion_cali_sel.call_args.kwargs["filament_id"] == "GFL05"