Spaces:
Build error
Build error
| """ | |
| E2E Tests for Gemini API Endpoints | |
| Tests the full job lifecycle: create → status → download/cancel | |
| External API (fal.ai) is mocked via environment variables. | |
| """ | |
| import pytest | |
| from unittest.mock import patch, MagicMock, AsyncMock | |
| import base64 | |
| # Create a minimal valid PNG image (1x1 pixel) | |
| MINIMAL_PNG = base64.b64encode( | |
| b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\x0f\x00\x00\x01\x01\x00\x05\x18\xd8N\x00\x00\x00\x00IEND\xaeB`\x82' | |
| ).decode() | |
| class TestGeminiModelsE2E: | |
| """Test /gemini/models endpoint.""" | |
| def test_get_models_requires_auth(self, api_client): | |
| """Models endpoint requires authentication.""" | |
| response = api_client.get("/gemini/models") | |
| # Models endpoint is also protected | |
| assert response.status_code == 401 | |
| class TestGeminiJobProtectionE2E: | |
| """Test that Gemini endpoints require authentication.""" | |
| def test_job_creation_requires_auth(self, api_client, endpoint, payload): | |
| """Job creation endpoints require authentication.""" | |
| response = api_client.post(endpoint, json=payload) | |
| assert response.status_code == 401 | |
| def test_job_status_requires_auth(self, api_client): | |
| """Job status requires authentication.""" | |
| response = api_client.get("/gemini/job/job_12345") | |
| assert response.status_code == 401 | |
| def test_job_list_requires_auth(self, api_client): | |
| """Job list requires authentication.""" | |
| response = api_client.get("/gemini/jobs") | |
| assert response.status_code == 401 | |
| def test_download_requires_auth(self, api_client): | |
| """Download requires authentication.""" | |
| response = api_client.get("/gemini/download/job_12345") | |
| assert response.status_code == 401 | |
| def test_cancel_requires_auth(self, api_client): | |
| """Cancel requires authentication.""" | |
| response = api_client.post("/gemini/job/job_12345/cancel") | |
| assert response.status_code == 401 | |
| def test_delete_requires_auth(self, api_client): | |
| """Delete requires authentication.""" | |
| response = api_client.delete("/gemini/job/job_12345") | |
| assert response.status_code == 401 | |
| class TestGeminiJobNotFoundE2E: | |
| """Test 404 responses for non-existent jobs when authenticated.""" | |
| # Note: These tests would require real auth which needs Google OAuth mock | |
| # For now, we verify the endpoint exists and rejects invalid requests | |
| pass | |