mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 05:45: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
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
import re
|
|
||||||
|
|
||||||
from aider.commands import Commands
|
from aider.commands import Commands
|
||||||
from aider.io import InputOutput
|
from aider.io import InputOutput
|
||||||
|
@ -10,17 +9,22 @@ from aider.scrape import Scraper
|
||||||
class TestScrape(unittest.TestCase):
|
class TestScrape(unittest.TestCase):
|
||||||
def test_scrape_self_signed_ssl(self):
|
def test_scrape_self_signed_ssl(self):
|
||||||
# Test with SSL verification
|
# 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")
|
result_verify = scraper_verify.scrape("https://self-signed.badssl.com")
|
||||||
self.assertIsNone(result_verify)
|
self.assertIsNone(result_verify)
|
||||||
scraper_verify.print_error.assert_called()
|
scraper_verify.print_error.assert_called()
|
||||||
|
|
||||||
# Test without SSL verification
|
# 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")
|
result_no_verify = scraper_no_verify.scrape("https://self-signed.badssl.com")
|
||||||
self.assertIsNotNone(result_no_verify)
|
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()
|
scraper_no_verify.print_error.assert_not_called()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.io = InputOutput(yes=True)
|
self.io = InputOutput(yes=True)
|
||||||
self.commands = Commands(self.io, None)
|
self.commands = Commands(self.io, None)
|
||||||
|
@ -88,6 +92,7 @@ class TestScrape(unittest.TestCase):
|
||||||
|
|
||||||
# Mock the playwright module to raise an error
|
# Mock the playwright module to raise an error
|
||||||
import playwright
|
import playwright
|
||||||
|
|
||||||
playwright._impl._errors.Error = Exception # Mock the Error class
|
playwright._impl._errors.Error = Exception # Mock the Error class
|
||||||
|
|
||||||
def mock_content():
|
def mock_content():
|
||||||
|
@ -104,7 +109,9 @@ class TestScrape(unittest.TestCase):
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
# Assert that print_error was called with the expected error message
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue