Skip to content

Commit 276b5ba

Browse files
committed
fix: invalid api key override reinstated and gmaps mock autoused to fix invalid api key errors
1 parent 504d3b8 commit 276b5ba

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

backend/test/conftest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import os
2+
3+
os.environ["GOOGLE_MAPS_API_KEY"] = "invalid_google_maps_api_key_for_tests"
4+
25
from typing import Any, AsyncGenerator, Callable
36
from unittest.mock import MagicMock, patch
47

58
import bcrypt
69
import googlemaps
10+
import pytest
711
import pytest_asyncio
12+
import src.modules # Ensure all modules are imported so their entities are registered # noqa: F401
813
from httpx import ASGITransport, AsyncClient
9-
from sqlalchemy.ext.asyncio import AsyncSession
14+
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
1015
from src.core.authentication import StringRole
11-
from src.core.database import get_session
16+
from src.core.database import EntityBase, get_session
1217
from src.main import app
1318
from src.modules.account.account_service import AccountService
1419
from src.modules.complaint.complaint_service import ComplaintService
@@ -24,13 +29,6 @@
2429
from test.modules.police.police_utils import PoliceTestUtils
2530
from test.modules.student.student_utils import StudentTestUtils
2631

27-
os.environ["GOOGLE_MAPS_API_KEY"] = "invalid_google_maps_api_key_for_tests"
28-
29-
import pytest
30-
import src.modules # Ensure all modules are imported so their entities are registered # noqa: F401
31-
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
32-
from src.core.database import EntityBase
33-
3432
DATABASE_URL = "sqlite+aiosqlite:///:memory:"
3533

3634
# =================================== Database ======================================
@@ -131,9 +129,11 @@ def student_service(test_session: AsyncSession):
131129
return StudentService(session=test_session)
132130

133131

134-
@pytest.fixture()
135-
def mock_gmaps() -> MagicMock:
136-
return MagicMock(spec=googlemaps.Client)
132+
@pytest.fixture(autouse=True)
133+
def mock_gmaps():
134+
mock = MagicMock(spec=googlemaps.Client)
135+
with patch("googlemaps.Client", return_value=mock):
136+
yield mock
137137

138138

139139
@pytest.fixture()

0 commit comments

Comments
 (0)