22
33"""Unit tests for the /conversations REST API endpoints."""
44
5- from pytest_mock import MockerFixture
5+ from pytest_mock import MockerFixture , MockType
66import pytest
77from fastapi import HTTPException , status
88
@@ -122,7 +122,7 @@ def test_transform_message_with_empty_referenced_documents(self) -> None:
122122
123123
124124@pytest .fixture
125- def mock_configuration (mocker : MockerFixture ):
125+ def mock_configuration (mocker : MockerFixture ) -> MockType :
126126 """Mock configuration with conversation cache."""
127127 mock_config = mocker .Mock ()
128128 mock_cache = mocker .Mock ()
@@ -133,27 +133,31 @@ def mock_configuration(mocker: MockerFixture):
133133class TestCheckValidConversationId :
134134 """Test cases for the check_valid_conversation_id function."""
135135
136- def test_valid_conversation_id (self , mocker : MockerFixture ):
136+ def test_valid_conversation_id (self , mocker : MockerFixture ) -> None :
137137 """Test with a valid conversation ID."""
138138 mocker .patch ("app.endpoints.conversations_v2.check_suid" , return_value = True )
139139 # Should not raise an exception
140140 check_valid_conversation_id (VALID_CONVERSATION_ID )
141141
142- def test_invalid_conversation_id (self , mocker : MockerFixture ):
142+ def test_invalid_conversation_id (self , mocker : MockerFixture ) -> None :
143143 """Test with an invalid conversation ID."""
144144 mocker .patch ("app.endpoints.conversations_v2.check_suid" , return_value = False )
145145
146146 with pytest .raises (HTTPException ) as exc_info :
147147 check_valid_conversation_id (INVALID_CONVERSATION_ID )
148148
149149 assert exc_info .value .status_code == status .HTTP_400_BAD_REQUEST
150- assert "Invalid conversation ID format" in exc_info .value .detail ["response" ]
150+ detail = exc_info .value .detail
151+ assert isinstance (detail , dict )
152+ assert "Invalid conversation ID format" in detail ["response" ]
151153
152154
153155class TestCheckConversationExistence :
154156 """Test cases for the check_conversation_existence function."""
155157
156- def test_conversation_exists (self , mocker , mock_configuration ):
158+ def test_conversation_exists (
159+ self , mocker : MockerFixture , mock_configuration : MockType
160+ ) -> None :
157161 """Test when conversation exists."""
158162 mock_configuration .conversation_cache .list .return_value = [
159163 mocker .Mock (conversation_id = VALID_CONVERSATION_ID )
@@ -163,7 +167,9 @@ def test_conversation_exists(self, mocker, mock_configuration):
163167 # Should not raise an exception
164168 check_conversation_existence ("user_id" , VALID_CONVERSATION_ID )
165169
166- def test_conversation_not_exists (self , mocker , mock_configuration ):
170+ def test_conversation_not_exists (
171+ self , mocker : MockerFixture , mock_configuration : MockType
172+ ) -> None :
167173 """Test when conversation does not exist."""
168174 mock_configuration .conversation_cache .list .return_value = []
169175 mocker .patch ("app.endpoints.conversations_v2.configuration" , mock_configuration )
@@ -172,14 +178,16 @@ def test_conversation_not_exists(self, mocker, mock_configuration):
172178 check_conversation_existence ("user_id" , VALID_CONVERSATION_ID )
173179
174180 assert exc_info .value .status_code == status .HTTP_404_NOT_FOUND
175- assert "Conversation not found" in exc_info .value .detail ["response" ]
181+ detail = exc_info .value .detail
182+ assert isinstance (detail , dict )
183+ assert "Conversation not found" in detail ["response" ]
176184
177185
178186class TestUpdateConversationEndpoint :
179187 """Test cases for the PUT /conversations/{conversation_id} endpoint."""
180188
181189 @pytest .mark .asyncio
182- async def test_configuration_not_loaded (self , mocker : MockerFixture ):
190+ async def test_configuration_not_loaded (self , mocker : MockerFixture ) -> None :
183191 """Test the endpoint when configuration is not loaded."""
184192 mock_authorization_resolvers (mocker )
185193 mocker .patch ("app.endpoints.conversations_v2.configuration" , None )
@@ -197,8 +205,8 @@ async def test_configuration_not_loaded(self, mocker: MockerFixture):
197205
198206 @pytest .mark .asyncio
199207 async def test_invalid_conversation_id_format (
200- self , mocker : MockerFixture , mock_configuration
201- ):
208+ self , mocker : MockerFixture , mock_configuration : MockType
209+ ) -> None :
202210 """Test the endpoint with an invalid conversation ID format."""
203211 mock_authorization_resolvers (mocker )
204212 mocker .patch ("app.endpoints.conversations_v2.configuration" , mock_configuration )
@@ -214,10 +222,14 @@ async def test_invalid_conversation_id_format(
214222 )
215223
216224 assert exc_info .value .status_code == status .HTTP_400_BAD_REQUEST
217- assert "Invalid conversation ID format" in exc_info .value .detail ["response" ]
225+ detail = exc_info .value .detail
226+ assert isinstance (detail , dict )
227+ assert "Invalid conversation ID format" in detail ["response" ]
218228
219229 @pytest .mark .asyncio
220- async def test_conversation_cache_not_configured (self , mocker : MockerFixture ):
230+ async def test_conversation_cache_not_configured (
231+ self , mocker : MockerFixture
232+ ) -> None :
221233 """Test the endpoint when conversation cache is not configured."""
222234 mock_authorization_resolvers (mocker )
223235 mock_config = mocker .Mock ()
@@ -235,14 +247,14 @@ async def test_conversation_cache_not_configured(self, mocker: MockerFixture):
235247 )
236248
237249 assert exc_info .value .status_code == status .HTTP_404_NOT_FOUND
238- assert (
239- "Conversation cache is not configured" in exc_info . value . detail [ "response" ]
240- )
250+ detail = exc_info . value . detail
251+ assert isinstance ( detail , dict )
252+ assert "Conversation cache is not configured" in detail [ "response" ]
241253
242254 @pytest .mark .asyncio
243255 async def test_conversation_not_found (
244- self , mocker : MockerFixture , mock_configuration
245- ):
256+ self , mocker : MockerFixture , mock_configuration : MockType
257+ ) -> None :
246258 """Test the endpoint when conversation does not exist."""
247259 mock_authorization_resolvers (mocker )
248260 mocker .patch ("app.endpoints.conversations_v2.configuration" , mock_configuration )
@@ -259,10 +271,14 @@ async def test_conversation_not_found(
259271 )
260272
261273 assert exc_info .value .status_code == status .HTTP_404_NOT_FOUND
262- assert "Conversation not found" in exc_info .value .detail ["response" ]
274+ detail = exc_info .value .detail
275+ assert isinstance (detail , dict )
276+ assert "Conversation not found" in detail ["response" ]
263277
264278 @pytest .mark .asyncio
265- async def test_successful_update (self , mocker : MockerFixture , mock_configuration ):
279+ async def test_successful_update (
280+ self , mocker : MockerFixture , mock_configuration : MockType
281+ ) -> None :
266282 """Test successful topic summary update."""
267283 mock_authorization_resolvers (mocker )
268284 mocker .patch ("app.endpoints.conversations_v2.configuration" , mock_configuration )
0 commit comments