"""Tests for link validator."""
import pytest
from src.link_validator import LinkValidator
@pytest.mark.asyncio
class TestLinkValidator:
"""Test the LinkValidator class."""
def setup_method(self):
"""Set up test fixtures."""
self.validator = LinkValidator(timeout=5.0)
async def test_validate_good_link(self):
"""Test validation of a working link."""
# Use a reliable public URL
status = await self.validator.validate_link("https://www.example.com")
assert status == "Good"
async def test_validate_bad_link(self):
"""Test validation of a broken link."""
# This should return 404
status = await self.validator.validate_link(
"https://httpbin.org/status/404"
)
assert status == "Bad"
async def test_validate_timeout(self):
"""Test validation with timeout."""
# Use a URL that delays response
validator = LinkValidator(timeout=1.0)
status = await validator.validate_link(
"https://httpbin.org/delay/5"
)
assert status == "Bad"
async def test_validate_invalid_url(self):
"""Test validation of invalid URL."""
status = await self.validator.validate_link("not-a-valid-url")
assert status == "Bad"
async def test_validate_multiple_links(self):
"""Test validation of multiple links concurrently."""
urls = [
"https://www.example.com",
"https://httpbin.org/status/404",
"https://www.google.com",
]
results = await self.validator.validate_links(urls)
assert len(results) == 3
assert results["https://www.example.com"] == "Good"
assert results["https://httpbin.org/status/404"] == "Bad"
assert results["https://www.google.com"] == "Good"