Skip to content

Commit ed75653

Browse files
committed
Resolve failing tests
1 parent 07d05a4 commit ed75653

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

backend/api/projects.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ async def get_project(
185185

186186
except ValueError as e:
187187
raise HTTPException(status_code=400, detail=f"Invalid project ID: {str(e)}")
188+
except HTTPException:
189+
# Re-raise HTTPExceptions without wrapping them
190+
raise
188191
except Exception as e:
189192
raise HTTPException(
190193
status_code=500, detail=f"Failed to fetch project: {str(e)}"
@@ -217,6 +220,9 @@ async def delete_project(
217220

218221
except ValueError as e:
219222
raise HTTPException(status_code=400, detail=f"Invalid project ID: {str(e)}")
223+
except HTTPException:
224+
# Re-raise HTTPExceptions without wrapping them
225+
raise
220226
except Exception as e:
221227
raise HTTPException(
222228
status_code=500, detail=f"Failed to delete project: {str(e)}"
@@ -255,6 +261,9 @@ async def get_upload_url(
255261

256262
except ValueError as e:
257263
raise HTTPException(status_code=400, detail=f"Invalid project ID: {str(e)}")
264+
except HTTPException:
265+
# Re-raise HTTPExceptions without wrapping them
266+
raise
258267
except Exception as e:
259268
raise HTTPException(
260269
status_code=500, detail=f"Failed to generate upload URL: {str(e)}"
@@ -309,6 +318,9 @@ async def get_project_status(
309318

310319
except ValueError as e:
311320
raise HTTPException(status_code=400, detail=f"Invalid project ID: {str(e)}")
321+
except HTTPException:
322+
# Re-raise HTTPExceptions without wrapping them
323+
raise
312324
except Exception as e:
313325
raise HTTPException(
314326
status_code=500, detail=f"Failed to fetch project status: {str(e)}"

backend/tests/conftest.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from unittest.mock import Mock, patch
23

34
import pytest
45
from fastapi.testclient import TestClient
@@ -8,8 +9,22 @@
89
os.environ["JWT_SECRET"] = "test_secret"
910
os.environ["TESTING"] = "true"
1011

11-
# Now that the environment is configured, we can import the application
12-
from main import app
12+
# Mock the storage service BEFORE importing the app to prevent MinIO connection attempts
13+
mock_storage = Mock()
14+
mock_storage.connect.return_value = True
15+
mock_storage.generate_presigned_url.return_value = (
16+
"https://test-minio/test-bucket/test-file?presigned=true"
17+
)
18+
mock_storage.health_check.return_value = {
19+
"status": "healthy",
20+
"message": "MinIO storage is operational (mocked)",
21+
"bucket": "test-bucket",
22+
}
23+
24+
# Apply the mock before importing the app
25+
with patch("services.storage_service.storage_service", mock_storage):
26+
# Now that the environment is configured, we can import the application
27+
from main import app
1328
from models.base import Base
1429
from models.project import ProjectTable # Import to register with Base
1530
from models.user import UserTable # Import to register with Base
@@ -44,7 +59,16 @@ def test_db_setup():
4459

4560

4661
@pytest.fixture(scope="function")
47-
def test_client(test_db_setup):
62+
def mock_storage_service():
63+
"""Mock the storage service to avoid MinIO connection in tests"""
64+
# The storage service is already mocked at import time, just return the mock
65+
from services.storage_service import storage_service
66+
67+
return storage_service
68+
69+
70+
@pytest.fixture(scope="function")
71+
def test_client(test_db_setup, mock_storage_service):
4872
"""
4973
A TestClient that uses the in-memory SQLite database.
5074
Each test function gets a clean database.

backend/tests/test_mock_endpoints.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ def test_get_projects(
141141
app.dependency_overrides.clear()
142142

143143

144-
def test_create_project(test_client, test_access_token, test_user_in_db):
144+
def test_create_project(
145+
test_client, test_access_token, test_user_in_db, mock_storage_service
146+
):
145147
"""Test create project endpoint"""
146148
app.dependency_overrides[verify_token] = mock_verify_token
147149
try:
@@ -303,7 +305,11 @@ def test_project_status(
303305

304306

305307
def test_get_upload_url(
306-
test_client, test_access_token, test_user_in_db, test_project_in_db
308+
test_client,
309+
test_access_token,
310+
test_user_in_db,
311+
test_project_in_db,
312+
mock_storage_service,
307313
):
308314
"""Test get upload URL endpoint"""
309315
app.dependency_overrides[verify_token] = mock_verify_token
@@ -352,7 +358,9 @@ def test_invalid_google_token(test_client):
352358
assert response.status_code == 401
353359

354360

355-
def test_project_not_found(test_client, test_access_token, test_user_in_db):
361+
def test_project_not_found(
362+
test_client, test_access_token, test_user_in_db, mock_storage_service
363+
):
356364
"""Test project not found error"""
357365
app.dependency_overrides[verify_token] = mock_verify_token
358366
try:

0 commit comments

Comments
 (0)