4
0

test_update_squid.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """Tests for Squid update errors exposed to the frontend."""
  2. from routes import main_routes
  3. from utils import updateSquid
  4. def test_update_squid_reports_missing_wget(monkeypatch):
  5. """A missing wget binary produces a safe, actionable failure message."""
  6. monkeypatch.setattr(
  7. updateSquid.platform,
  8. "freedesktop_os_release",
  9. lambda: {"ID": "ubuntu", "VERSION_CODENAME": "jammy"},
  10. )
  11. monkeypatch.setattr(updateSquid.shutil, "which", lambda _name: None)
  12. success, message = updateSquid.update_squid()
  13. assert success is False
  14. assert message == updateSquid.WGET_NOT_INSTALLED_MESSAGE
  15. def test_install_returns_missing_wget_error_as_json(client, monkeypatch):
  16. """AJAX callers receive the reason instead of an invisible flash redirect."""
  17. monkeypatch.setattr(
  18. main_routes,
  19. "update_squid",
  20. lambda: (False, updateSquid.WGET_NOT_INSTALLED_MESSAGE),
  21. )
  22. response = client.post("/install", headers={"Accept": "application/json"})
  23. assert response.status_code == 503
  24. assert response.get_json() == {
  25. "status": "error",
  26. "message": updateSquid.WGET_NOT_INSTALLED_MESSAGE,
  27. }
  28. def test_install_returns_success_as_json(client, monkeypatch):
  29. """AJAX callers get an explicit success result before the page reloads."""
  30. monkeypatch.setattr(main_routes, "update_squid", lambda: (True, None))
  31. response = client.post("/install", headers={"Accept": "application/json"})
  32. assert response.status_code == 200
  33. assert response.get_json()["status"] == "success"