@@ -157,7 +157,7 @@ def mock_stream(method, _url, timeout=10):
157157async def test_download_excel_scan_error (test_scraper ):
158158 """
159159 Test the scenario where virus scanning fails (connection reset, etc.).
160- The method should also skip returning file content, but not label it as a virus .
160+ If MIME is valid, content should still be returned (fallback behavior) .
161161 """
162162 fake_excel_content = b"FakeExcelData"
163163 url = "http://example.com/scan_error.xls"
@@ -179,14 +179,15 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
179179 def mock_stream (method , _url , timeout = 10 ):
180180 return MockResponseContext (200 , fake_excel_content )
181181
182- # "ERROR" indicates scanning couldn't complete
182+ # "ERROR" means scanning failed, but MIME check passes
183183 with patch .object (test_scraper .session , 'stream' , side_effect = mock_stream ), \
184- patch .object (test_scraper ._security_manager , 'scan_for_viruses' , return_value = ("ERROR" ,"Connection reset by peer " )), \
184+ patch .object (test_scraper ._security_manager , 'scan_for_viruses' , return_value = ("ERROR" , "Connection reset" )), \
185185 patch .object (test_scraper ._security_manager , 'is_excel_file' , return_value = True ):
186186
187187 returned_url , content = await test_scraper .download_excel (url )
188188 assert returned_url == url
189- assert content is None , "Should skip returning content if scan error occurs."
189+ assert content == fake_excel_content # ✅ New expected behavior
190+
190191
191192@pytest .mark .asyncio
192193async def test_download_excel_not_excel (test_scraper ):
0 commit comments