test_refused_project_file_ack.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """A print start the printer refused is logged, and its answer is not read as
  2. an accepted print (FW-C1).
  3. The printer answers a ``project_file`` command on the report topic. A refusal
  4. went unlogged, so a support bundle showed nothing of it; and its job id was
  5. copied into the state like any status field, which the start watchdog reads
  6. as "the printer took the file" and so waited out its full 180 s before giving
  7. up.
  8. """
  9. import logging
  10. from backend.app.services.bambu_mqtt import BambuMQTTClient
  11. def _client() -> BambuMQTTClient:
  12. client = BambuMQTTClient(ip_address="10.0.0.9", serial_number="SN-FW", access_code="x", model="X1C")
  13. client.state.subtask_id = "100"
  14. client.state.subtask_name = "previous"
  15. return client
  16. def _ack(result: str) -> dict:
  17. return {
  18. "print": {
  19. "command": "project_file",
  20. "result": result,
  21. "reason": "file not found",
  22. "subtask_id": "200",
  23. "subtask_name": "refused",
  24. "url": "ftp://refused.3mf",
  25. }
  26. }
  27. def test_a_refusal_is_logged_and_changes_no_job(caplog):
  28. client = _client()
  29. with caplog.at_level(logging.INFO, logger="backend.app.services.bambu_mqtt"):
  30. client._process_message(_ack("FAIL"))
  31. assert (client.state.subtask_id, client.state.subtask_name) == ("100", "previous")
  32. assert any("refused" in r.getMessage() and "FAIL" in r.getMessage() for r in caplog.records)
  33. def test_an_accepted_start_still_names_its_job():
  34. client = _client()
  35. client._process_message(_ack("SUCCESS"))
  36. assert (client.state.subtask_id, client.state.subtask_name) == ("200", "refused")
  37. def test_a_refusal_is_remembered_until_the_next_start_is_sent():
  38. from unittest.mock import MagicMock
  39. client = _client()
  40. client._process_message(_ack("FAIL"))
  41. assert client.last_start_refusal == ("FAIL", "file not found")
  42. client._client = MagicMock()
  43. client.state.connected = True
  44. client.start_print("next.3mf")
  45. assert client.last_start_refusal is None
  46. def test_success_in_lower_case_is_not_a_refusal():
  47. client = _client()
  48. client._process_message(_ack("success"))
  49. assert client.last_start_refusal is None
  50. assert client.state.subtask_id == "200"