test_updates_api.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Integration tests for Updates API endpoints."""
  2. from unittest.mock import AsyncMock, patch
  3. import pytest
  4. from httpx import AsyncClient
  5. class TestUpdatesAPI:
  6. @pytest.mark.asyncio
  7. async def test_get_version(self, async_client: AsyncClient):
  8. response = await async_client.get("/api/v1/updates/version")
  9. assert response.status_code == 200
  10. @pytest.mark.asyncio
  11. async def test_apply_update_docker_rejection(self, async_client: AsyncClient):
  12. with patch("backend.app.api.routes.updates._is_docker_environment", return_value=True):
  13. response = await async_client.post("/api/v1/updates/apply")
  14. result = response.json()
  15. assert result["success"] is False
  16. assert result["is_docker"] is True
  17. @pytest.mark.asyncio
  18. async def test_apply_update_non_docker(self, async_client: AsyncClient):
  19. """Test non-Docker path - mock _perform_update to prevent side effects."""
  20. with (
  21. patch("backend.app.api.routes.updates._is_docker_environment", return_value=False),
  22. patch("backend.app.api.routes.updates._perform_update", new_callable=AsyncMock),
  23. ):
  24. response = await async_client.post("/api/v1/updates/apply")
  25. assert response.json()["success"] is True
  26. def test_is_docker_with_dockerenv(self):
  27. from backend.app.api.routes.updates import _is_docker_environment
  28. with patch("os.path.exists", return_value=True):
  29. assert _is_docker_environment() is True
  30. def test_parse_version(self):
  31. from backend.app.api.routes.updates import parse_version
  32. assert parse_version("0.1.5")[:3] == (0, 1, 5)
  33. def test_is_newer_version(self):
  34. from backend.app.api.routes.updates import is_newer_version
  35. assert is_newer_version("0.1.5", "0.1.5b7") is True