@@ -146,95 +146,6 @@ async def test_generate_title_exception(self, history_service):
146146 result = await history_service .generate_title (conversation_messages )
147147 assert result == "Fallback content"
148148
149- @pytest .mark .asyncio
150- async def test_add_conversation_new (self , history_service ):
151- """Test adding a new conversation"""
152- user_id = "test-user-id"
153- request_json = {
154- "conversation_id" : None ,
155- "messages" : [{"role" : "user" , "content" : "Hello" }]
156- }
157-
158- mock_cosmos_client = AsyncMock ()
159- mock_cosmos_client .create_conversation = AsyncMock (
160- return_value = {"id" : "new-conv-id" , "title" : "Test Title" , "createdAt" : "2023-01-01T00:00:00Z" }
161- )
162- mock_cosmos_client .create_message = AsyncMock (return_value = "success" )
163-
164- with patch .object (history_service , "init_cosmosdb_client" , return_value = mock_cosmos_client ):
165- with patch .object (history_service , "generate_title" , AsyncMock (return_value = "Test Title" )):
166- with patch ("services.history_service.complete_chat_request" , AsyncMock (return_value = {"response" : "test" })):
167- result = await history_service .add_conversation (user_id , request_json )
168- assert result == {"response" : "test" }
169-
170- # Verify calls
171- mock_cosmos_client .create_conversation .assert_awaited_once ()
172- mock_cosmos_client .create_message .assert_awaited_once ()
173-
174- @pytest .mark .asyncio
175- async def test_add_conversation_existing (self , history_service ):
176- """Test adding to an existing conversation"""
177- user_id = "test-user-id"
178- request_json = {
179- "conversation_id" : "existing-id" ,
180- "messages" : [{"role" : "user" , "content" : "Hello" }]
181- }
182-
183- mock_cosmos_client = AsyncMock ()
184- mock_cosmos_client .create_message = AsyncMock (return_value = "success" )
185-
186- with patch .object (history_service , "init_cosmosdb_client" , return_value = mock_cosmos_client ):
187- with patch ("services.history_service.complete_chat_request" , AsyncMock (return_value = {"response" : "test" })):
188- result = await history_service .add_conversation (user_id , request_json )
189- assert result == {"response" : "test" }
190-
191- # Verify calls
192- mock_cosmos_client .create_message .assert_awaited_once ()
193-
194- @pytest .mark .asyncio
195- async def test_add_conversation_cosmos_not_configured (self , history_service ):
196- """Test adding conversation when cosmos is not configured"""
197- user_id = "test-user-id"
198- request_json = {
199- "conversation_id" : "existing-id" ,
200- "messages" : [{"role" : "user" , "content" : "Hello" }]
201- }
202-
203- with patch .object (history_service , "init_cosmosdb_client" , return_value = None ):
204- with pytest .raises (ValueError , match = "CosmosDB is not configured or unavailable" ):
205- await history_service .add_conversation (user_id , request_json )
206-
207- @pytest .mark .asyncio
208- async def test_add_conversation_no_user_message (self , history_service ):
209- """Test adding conversation with no user message"""
210- user_id = "test-user-id"
211- request_json = {
212- "conversation_id" : "existing-id" ,
213- "messages" : [{"role" : "assistant" , "content" : "Hello" }]
214- }
215-
216- mock_cosmos_client = AsyncMock ()
217-
218- with patch .object (history_service , "init_cosmosdb_client" , return_value = mock_cosmos_client ):
219- with pytest .raises (ValueError , match = "No user message found" ):
220- await history_service .add_conversation (user_id , request_json )
221-
222- @pytest .mark .asyncio
223- async def test_add_conversation_conversation_not_found (self , history_service ):
224- """Test adding to a non-existent conversation"""
225- user_id = "test-user-id"
226- request_json = {
227- "conversation_id" : "non-existent-id" ,
228- "messages" : [{"role" : "user" , "content" : "Hello" }]
229- }
230-
231- mock_cosmos_client = AsyncMock ()
232- mock_cosmos_client .create_message = AsyncMock (return_value = "Conversation not found" )
233-
234- with patch .object (history_service , "init_cosmosdb_client" , return_value = mock_cosmos_client ):
235- with pytest .raises (ValueError , match = "Conversation not found" ):
236- await history_service .add_conversation (user_id , request_json )
237-
238149 @pytest .mark .asyncio
239150 async def test_update_conversation (self , history_service ):
240151 """Test updating an existing conversation"""
0 commit comments