@@ -108,8 +108,6 @@ def test_create_chunks_and_embeddings_none_context(self, mock_logger):
108108 openai_client = mock_openai_client ,
109109 )
110110
111- # When context is None, the function should catch the AttributeError
112- # and log an exception, returning an empty list
113111 mock_logger .exception .assert_called_once_with ("Failed to create chunks and embeddings" )
114112 assert result == []
115113
@@ -253,43 +251,34 @@ def test_regenerate_chunks_for_context_success(
253251 self , mock_split_text , mock_create_chunks , mock_openai_class , mock_logger
254252 ):
255253 """Test successful regeneration of chunks for context."""
256- # Setup context mock
257254 context = MagicMock ()
258255 context .content = "This is test content for chunking"
259256
260- # Setup existing chunks
261257 mock_existing_chunks = MagicMock ()
262258 context .chunks = mock_existing_chunks
263259
264- # Setup chunk splitting
265260 new_chunk_texts = ["chunk1" , "chunk2" ]
266261 mock_split_text .return_value = new_chunk_texts
267262
268- # Setup OpenAI client
269263 mock_openai_client = MagicMock ()
270264 mock_openai_class .return_value = mock_openai_client
271265
272266 regenerate_chunks_for_context (context )
273267
274- # Verify old chunks were deleted
275268 mock_existing_chunks .all .assert_called_once ()
276269 mock_existing_chunks .all ().delete .assert_called_once ()
277270
278- # Verify content was split
279271 mock_split_text .assert_called_once_with (context .content )
280272
281- # Verify OpenAI client was created
282273 mock_openai_class .assert_called_once ()
283274
284- # Verify new chunks were created
285275 mock_create_chunks .assert_called_once_with (
286276 chunk_texts = new_chunk_texts ,
287277 context = context ,
288278 openai_client = mock_openai_client ,
289279 save = True ,
290280 )
291281
292- # Verify success log
293282 mock_logger .info .assert_called_once_with (
294283 "Successfully completed chunk regeneration for new context"
295284 )
@@ -298,32 +287,25 @@ def test_regenerate_chunks_for_context_success(
298287 @patch ("apps.ai.common.utils.Chunk.split_text" )
299288 def test_regenerate_chunks_for_context_no_content (self , mock_split_text , mock_logger ):
300289 """Test regeneration when there's no content to chunk."""
301- # Setup context mock
302290 context = MagicMock ()
303291 context .content = "Some content"
304292
305- # Setup existing chunks
306293 mock_existing_chunks = MagicMock ()
307294 context .chunks = mock_existing_chunks
308295
309- # Setup chunk splitting to return empty list
310296 mock_split_text .return_value = []
311297
312298 regenerate_chunks_for_context (context )
313299
314- # Verify old chunks were deleted
315300 mock_existing_chunks .all .assert_called_once ()
316301 mock_existing_chunks .all ().delete .assert_called_once ()
317302
318- # Verify content was split
319303 mock_split_text .assert_called_once_with (context .content )
320304
321- # Verify warning was logged and process stopped
322305 mock_logger .warning .assert_called_once_with (
323306 "No content to chunk for Context. Process stopped."
324307 )
325308
326- # Verify success log was not called
327309 mock_logger .info .assert_not_called ()
328310
329311 @patch ("apps.ai.common.utils.logger" )
@@ -334,40 +316,32 @@ def test_regenerate_chunks_for_context_no_existing_chunks(
334316 self , mock_split_text , mock_create_chunks , mock_openai_class , mock_logger
335317 ):
336318 """Test regeneration when there are no existing chunks."""
337- # Setup context mock
338319 context = MagicMock ()
339320 context .content = "This is test content for chunking"
340321
341- # Setup no existing chunks
342322 mock_existing_chunks = MagicMock ()
343323 context .chunks = mock_existing_chunks
344324
345- # Setup chunk splitting
346325 new_chunk_texts = ["chunk1" , "chunk2" ]
347326 mock_split_text .return_value = new_chunk_texts
348327
349- # Setup OpenAI client
350328 mock_openai_client = MagicMock ()
351329 mock_openai_class .return_value = mock_openai_client
352330
353331 regenerate_chunks_for_context (context )
354332
355- # Verify delete was called regardless of count
356333 mock_existing_chunks .all .assert_called_once ()
357334 mock_existing_chunks .all ().delete .assert_called_once ()
358335
359- # Verify content was split
360336 mock_split_text .assert_called_once_with (context .content )
361337
362- # Verify new chunks were created
363338 mock_create_chunks .assert_called_once_with (
364339 chunk_texts = new_chunk_texts ,
365340 context = context ,
366341 openai_client = mock_openai_client ,
367342 save = True ,
368343 )
369344
370- # Verify success log
371345 mock_logger .info .assert_called_once_with (
372346 "Successfully completed chunk regeneration for new context"
373347 )
0 commit comments