MCPcopy Create free account
hub / github.com/grapeot/devin.cursorrules / TestWebScraper

Class TestWebScraper

tests/test_web_scraper.py:14–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12pytestmark = pytest.mark.asyncio
13
14class TestWebScraper(unittest.TestCase):
15 @classmethod
16 def setUpClass(cls):
17 """Set up any necessary test fixtures."""
18 cls.mock_response = MagicMock()
19 cls.mock_response.status = 200
20 cls.mock_response.text.return_value = "Test content"
21
22 cls.mock_client_session = MagicMock()
23 cls.mock_client_session.__aenter__.return_value = cls.mock_client_session
24 cls.mock_client_session.__aexit__.return_value = None
25 cls.mock_client_session.get.return_value.__aenter__.return_value = cls.mock_response
26
27 def setUp(self):
28 """Set up test fixtures before each test method."""
29 self.urls = ["http://example1.com", "http://example2.com"]
30 self.mock_session = self.mock_client_session
31
32 def test_validate_url(self):
33 # Test valid URLs
34 self.assertTrue(validate_url('https://example.com'))
35 self.assertTrue(validate_url('http://example.com/path?query=1'))
36 self.assertTrue(validate_url('https://sub.example.com:8080/path'))
37
38 # Test invalid URLs
39 self.assertFalse(validate_url('not-a-url'))
40 self.assertFalse(validate_url('http://'))
41 self.assertFalse(validate_url('https://'))
42 self.assertFalse(validate_url(''))
43
44 def test_parse_html(self):
45 # Test with empty or None input
46 self.assertEqual(parse_html(None), "")
47 self.assertEqual(parse_html(""), "")
48
49 # Test with simple HTML
50 html = """
51 <html>
52 <body>
53 <h1>Title</h1>
54 <p>Paragraph text</p>
55 <a href="https://example.com">Link text</a>
56 <script>var x = 1;</script>
57 <style>.css { color: red; }</style>
58 </body>
59 </html>
60 """
61 result = parse_html(html)
62 self.assertIn("Title", result)
63 self.assertIn("Paragraph text", result)
64 self.assertIn("[Link text](https://example.com)", result)
65 self.assertNotIn("var x = 1", result) # Script content should be filtered
66 self.assertNotIn(".css", result) # Style content should be filtered
67
68 # Test with nested elements
69 html = """
70 <html>
71 <body>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected