mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
Fix test for self-signed url scrape
This commit is contained in:
parent
8a9184cef9
commit
5bf9dbb226
1 changed files with 14 additions and 7 deletions
|
@ -1,6 +1,5 @@
|
|||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
import re
|
||||
|
||||
from aider.commands import Commands
|
||||
from aider.io import InputOutput
|
||||
|
@ -10,17 +9,22 @@ from aider.scrape import Scraper
|
|||
class TestScrape(unittest.TestCase):
|
||||
def test_scrape_self_signed_ssl(self):
|
||||
# Test with SSL verification
|
||||
scraper_verify = Scraper(print_error=MagicMock(), playwright_available=True, verify_ssl=True)
|
||||
scraper_verify = Scraper(
|
||||
print_error=MagicMock(), playwright_available=True, verify_ssl=True
|
||||
)
|
||||
result_verify = scraper_verify.scrape("https://self-signed.badssl.com")
|
||||
self.assertIsNone(result_verify)
|
||||
scraper_verify.print_error.assert_called()
|
||||
|
||||
# Test without SSL verification
|
||||
scraper_no_verify = Scraper(print_error=MagicMock(), playwright_available=True, verify_ssl=False)
|
||||
scraper_no_verify = Scraper(
|
||||
print_error=MagicMock(), playwright_available=True, verify_ssl=False
|
||||
)
|
||||
result_no_verify = scraper_no_verify.scrape("https://self-signed.badssl.com")
|
||||
self.assertIsNotNone(result_no_verify)
|
||||
self.assertIn("self-signed.badssl.com", result_no_verify)
|
||||
self.assertIn("self-signed", result_no_verify)
|
||||
scraper_no_verify.print_error.assert_not_called()
|
||||
|
||||
def setUp(self):
|
||||
self.io = InputOutput(yes=True)
|
||||
self.commands = Commands(self.io, None)
|
||||
|
@ -88,15 +92,16 @@ class TestScrape(unittest.TestCase):
|
|||
|
||||
# Mock the playwright module to raise an error
|
||||
import playwright
|
||||
|
||||
playwright._impl._errors.Error = Exception # Mock the Error class
|
||||
|
||||
|
||||
def mock_content():
|
||||
raise playwright._impl._errors.Error("Test error")
|
||||
|
||||
# Mock the necessary objects and methods
|
||||
scraper.scrape_with_playwright = MagicMock()
|
||||
scraper.scrape_with_playwright.return_value = None
|
||||
|
||||
|
||||
# Call the scrape method
|
||||
result = scraper.scrape("https://example.com")
|
||||
|
||||
|
@ -104,7 +109,9 @@ class TestScrape(unittest.TestCase):
|
|||
self.assertIsNone(result)
|
||||
|
||||
# Assert that print_error was called with the expected error message
|
||||
mock_print_error.assert_called_once_with("Failed to retrieve content from https://example.com")
|
||||
mock_print_error.assert_called_once_with(
|
||||
"Failed to retrieve content from https://example.com"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue