test_command_response_content_3531.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """#3531: the debug log records the content of commands the printer reports back.
  2. The H3C touchscreen's Unload All is one command, ``multi_slot_ams_change_filament``,
  3. whose fields are not documented anywhere. The printer reports it back like every
  4. command, but the debug log kept only its name. push_status (the status itself)
  5. and project_file (which may carry a signed download URL) stay name-only.
  6. """
  7. import logging
  8. import pytest
  9. from backend.app.services.bambu_mqtt import BambuMQTTClient
  10. @pytest.fixture
  11. def mqtt_client():
  12. return BambuMQTTClient(ip_address="192.168.1.100", serial_number="TEST123", access_code="12345678")
  13. def _content_lines(caplog):
  14. return [r.getMessage() for r in caplog.records if " content: " in r.getMessage()]
  15. def test_a_reported_command_is_logged_with_its_fields(mqtt_client, caplog):
  16. caplog.set_level(logging.DEBUG, logger="backend.app.services.bambu_mqtt")
  17. mqtt_client._process_message(
  18. {"print": {"command": "multi_slot_ams_change_filament", "sequence_id": "7", "slots": [{"ams_id": 128}]}}
  19. )
  20. lines = _content_lines(caplog)
  21. assert len(lines) == 1
  22. assert "multi_slot_ams_change_filament content:" in lines[0]
  23. assert '"slots": [{"ams_id": 128}]' in lines[0]
  24. @pytest.mark.parametrize("command", ["push_status", "project_file"])
  25. def test_status_and_print_start_stay_name_only(mqtt_client, caplog, command):
  26. caplog.set_level(logging.DEBUG, logger="backend.app.services.bambu_mqtt")
  27. mqtt_client._process_message({"print": {"command": command, "url": "https://example.invalid/signed?token=x"}})
  28. assert _content_lines(caplog) == []
  29. def test_long_content_is_capped(mqtt_client, caplog):
  30. caplog.set_level(logging.DEBUG, logger="backend.app.services.bambu_mqtt")
  31. mqtt_client._process_message({"print": {"command": "gcode_line", "param": "G1 X1\n" * 2000}})
  32. (line,) = _content_lines(caplog)
  33. assert len(line.split(" content: ", 1)[1]) == 4000