@@ -300,16 +300,47 @@ def test_process_document_section_no_pages(
300300 assert "Section 2 has no page IDs" in result .errors [0 ]
301301
302302 @patch ("idp_common.s3.get_text_content" )
303+ @patch ("idp_common.image.prepare_image" )
304+ @patch ("idp_common.image.prepare_bedrock_image_attachment" )
305+ @patch ("idp_common.bedrock.invoke_model" )
306+ @patch ("idp_common.s3.write_content" )
307+ @patch ("idp_common.utils.merge_metering_data" )
303308 @patch ("idp_common.metrics.put_metric" )
304309 def test_process_document_section_missing_page (
305- self , mock_put_metric , mock_get_text_content , service , sample_document
310+ self ,
311+ mock_put_metric ,
312+ mock_merge_metering ,
313+ mock_write_content ,
314+ mock_invoke_model ,
315+ mock_prepare_bedrock_image ,
316+ mock_prepare_image ,
317+ mock_get_text_content ,
318+ service ,
319+ sample_document ,
306320 ):
307321 """Test processing a document section with a missing page."""
308322 # Add a non-existent page ID to the section
309323 sample_document .sections [0 ].page_ids .append ("999" )
310324
311- # Mock text content for existing pages
325+ # Mock responses
312326 mock_get_text_content .side_effect = ["Page 1 text" , "Page 2 text" ]
327+ mock_prepare_image .return_value = b"fake_image_data"
328+ mock_prepare_bedrock_image .return_value = {"type" : "image" , "source" : {}}
329+ mock_invoke_model .return_value = {
330+ "response" : {
331+ "output" : {
332+ "message" : {
333+ "content" : [
334+ {
335+ "text" : '{"invoice_number": "INV-123"}'
336+ }
337+ ]
338+ }
339+ }
340+ },
341+ "metering" : {"input_tokens" : 100 , "output_tokens" : 50 },
342+ }
343+ mock_merge_metering .return_value = {"total_tokens" : 150 }
313344
314345 # Process the section
315346 result = service .process_document_section (sample_document , "1" )
@@ -326,12 +357,9 @@ def test_process_document_section_exception(
326357 # Mock an exception
327358 mock_get_text_content .side_effect = Exception ("Test exception" )
328359
329- # Process the section
330- result = service .process_document_section (sample_document , "1" )
331-
332- # Verify error was added
333- assert len (result .errors ) == 1
334- assert "Error processing section 1: Test exception" in result .errors [0 ]
360+ # Process the section and expect exception to be raised
361+ with pytest .raises (Exception , match = "Test exception" ):
362+ service .process_document_section (sample_document , "1" )
335363
336364 def test_extract_json_code_block (self , service ):
337365 """Test extracting JSON from code block."""
0 commit comments