test_ftp_list_timeout_route.py 1.0 KB

123456789101112131415161718192021222324252627
  1. """The file manager says a slow listing is slow, not that the printer is gone (TO-C13)."""
  2. from unittest.mock import AsyncMock, patch
  3. import pytest
  4. from httpx import AsyncClient
  5. from backend.app.services.bambu_ftp import FileListResult
  6. pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
  7. @pytest.mark.parametrize(
  8. ("result", "warnings"),
  9. [
  10. (FileListResult(files=[], available=False, timed_out=True), ["listing_timed_out"]),
  11. (FileListResult(files=[], available=False), ["printer_unavailable"]),
  12. (FileListResult(files=[], available=True), []),
  13. ],
  14. )
  15. async def test_the_listing_warning_says_which(async_client: AsyncClient, printer_factory, result, warnings):
  16. printer = await printer_factory()
  17. with patch("backend.app.api.routes.printers.list_files_result_async", new=AsyncMock(return_value=result)):
  18. response = await async_client.get(f"/api/v1/printers/{printer.id}/files?path=/ipcam")
  19. assert response.status_code == 200
  20. assert response.json()["warnings"] == warnings