2424 helpers ,
2525 save_robot_deck_attitude ,
2626)
27+ from server_utils .fastapi_utils .app_state import AppState , get_app_state
2728
2829# NOTE(FS 10-24-2023), the fixtures using these functions currently ONLY
2930# get pulled in by OT-2 server tests. If this ever changes, we need to
4748from robot_server .health .router import ComponentVersions , get_versions
4849from robot_server .runs .run_data_manager import RunDataManager
4950from robot_server .runs .dependencies import get_run_data_manager
51+ from robot_server .service .notifications .notification_client import (
52+ NotificationClient ,
53+ _notification_client_accessor ,
54+ )
5055
5156test_router = routing .APIRouter ()
5257
@@ -178,12 +183,30 @@ async def get_run_data_manager_override() -> RunDataManager:
178183 del app .dependency_overrides [get_run_data_manager ]
179184
180185
186+ @pytest .fixture
187+ def _override_app_state_with_notification_client (decoy : Decoy ) -> Iterator [None ]:
188+ """Override app_state to include a mocked notification client."""
189+ mock_app_state = AppState ()
190+ mock_notification_client = decoy .mock (cls = NotificationClient )
191+
192+ _notification_client_accessor .set_on (mock_app_state , mock_notification_client )
193+
194+ async def get_app_state_override () -> AppState :
195+ """Override for get_app_state."""
196+ return mock_app_state
197+
198+ app .dependency_overrides [get_app_state ] = get_app_state_override
199+ yield
200+ del app .dependency_overrides [get_app_state ]
201+
202+
181203@pytest .fixture
182204def api_client (
183205 _override_hardware_with_mock : None ,
184206 _override_sql_engine_with_mock : None ,
185207 _override_version_with_mock : None ,
186208 _override_ot2_hardware_with_mock : None ,
209+ _override_app_state_with_notification_client : None ,
187210) -> TestClient :
188211 client = TestClient (app )
189212 client .headers .update (
@@ -199,6 +222,7 @@ def api_client_camera_overrides(
199222 _override_version_with_mock : None ,
200223 _override_ot2_hardware_with_mock : None ,
201224 _override_run_data_manager_with_mock : None ,
225+ _override_app_state_with_notification_client : None ,
202226) -> TestClient :
203227 client = TestClient (app )
204228 client .headers .update (
0 commit comments