test_spoolman_last_used.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. """Spoolman's "last used" means a print used the spool.
  2. ``update_spool`` stamped ``last_used = now`` on every call, and it is called by
  3. the AMS sync for every loaded spool, by clearing a removed spool's location and
  4. by weighing on the SpoolBuddy scale: every sync marked every loaded spool as
  5. just used. Print usage goes through Spoolman's /use endpoint, which sets
  6. last_used itself (Spoolman's database.spool.use_weight), so update_spool no
  7. longer touches it. Local mode already behaved this way.
  8. """
  9. from unittest.mock import AsyncMock, MagicMock
  10. import pytest
  11. from backend.app.services.spoolman import SpoolmanClient
  12. @pytest.mark.asyncio
  13. @pytest.mark.parametrize(
  14. "kwargs",
  15. [{"remaining_weight": 500.0}, {"location": "Printer 1 AMS A"}, {"clear_location": True}],
  16. ids=["weight", "location", "clear-location"],
  17. )
  18. async def test_an_update_does_not_mark_the_spool_used(kwargs):
  19. client = SpoolmanClient("http://spoolman.invalid")
  20. response = MagicMock()
  21. response.json.return_value = {"id": 3}
  22. client._request_spool = AsyncMock(return_value=response)
  23. await client.update_spool(spool_id=3, **kwargs)
  24. body = client._request_spool.await_args.kwargs["json_body"]
  25. assert "last_used" not in body