|
20 | 20 | from unittest import mock |
21 | 21 |
|
22 | 22 | from google.adk.errors.already_exists_error import AlreadyExistsError |
| 23 | +from google.adk.errors.session_not_found_error import SessionNotFoundError |
23 | 24 | from google.adk.events.event import Event |
24 | 25 | from google.adk.events.event import EventActions |
25 | 26 | from google.adk.integrations.firestore.firestore_session_service import FirestoreSessionService |
@@ -268,6 +269,28 @@ async def test_append_event(mock_firestore_client): |
268 | 269 | assert session.last_update_time == event.timestamp |
269 | 270 |
|
270 | 271 |
|
| 272 | +@pytest.mark.asyncio |
| 273 | +async def test_append_event_session_not_found(mock_firestore_client): |
| 274 | + service = FirestoreSessionService(client=mock_firestore_client) |
| 275 | + session = Session(id="test_session", app_name="test_app", user_id="test_user") |
| 276 | + event = Event(invocation_id="test_inv", author="user") |
| 277 | + |
| 278 | + session_doc_snapshot = mock.MagicMock() |
| 279 | + session_doc_snapshot.exists = False |
| 280 | + |
| 281 | + root_coll = mock_firestore_client.collection.return_value |
| 282 | + app_ref = root_coll.document.return_value |
| 283 | + users_coll = app_ref.collection.return_value |
| 284 | + user_ref = users_coll.document.return_value |
| 285 | + sessions_ref = user_ref.collection.return_value |
| 286 | + session_doc_ref = sessions_ref.document.return_value |
| 287 | + session_doc_ref.get = mock.AsyncMock(return_value=session_doc_snapshot) |
| 288 | + |
| 289 | + with mock.patch("google.cloud.firestore.async_transactional", lambda x: x): |
| 290 | + with pytest.raises(SessionNotFoundError): |
| 291 | + await service.append_event(session, event) |
| 292 | + |
| 293 | + |
271 | 294 | @pytest.mark.asyncio |
272 | 295 | async def test_append_event_with_state_delta(mock_firestore_client): |
273 | 296 | service = FirestoreSessionService(client=mock_firestore_client) |
|
0 commit comments