"""Unit tests for the pure-HTTP block-page classifier.""" import pytest from scoutlet.response_classifier import detect_block_page, BlockDetectionResult class TestDetectBlockPage: # --- Engine-specific detection --- def test_google_sorry_detected(self): html = 'sorry.google.com recaptcha' result = detect_block_page(html, "https://www.google.com/sorry/index") assert result.blocked is True assert "Google CAPTCHA" in result.reason def test_bing_block_detected(self): html = 'bing.com/security/ blocked' result = detect_block_page(html) assert result.blocked is True assert "Bing block" in result.reason def test_ddg_rate_limit_detected(self): html = 'duckduckgo.com/?q=test&t=hc_abc' result = detect_block_page(html) assert result.blocked is True assert "DDG" in result.reason def test_ddg_challenge_form_detected(self): html = '
' result = detect_block_page(html) assert result.blocked is True assert "DDG" in result.reason # --- Generic detection (short pages only) --- def test_access_denied_on_short_page(self): html = "Access Denied" assert len(html) < 2048 result = detect_block_page(html) assert result.blocked is True assert "Access Denied" in result.reason def test_browser_check_on_short_page(self): html = "Checking your browser" result = detect_block_page(html) assert result.blocked is True def test_cloudflare_challenge_on_short_page(self): html = '
' result = detect_block_page(html) assert result.blocked is True assert "Cloudflare" in result.reason def test_akamai_reference_on_short_page(self): html = "Reference #123456.7890ab" result = detect_block_page(html) assert result.blocked is True # --- No false positives --- def test_normal_page_not_blocked(self): html = "

Python Tutorial

Learn Python

" result = detect_block_page(html) assert result.blocked is False def test_normal_long_page_not_blocked(self): # "Access Denied" in a long page should NOT trigger generic detection html = "" + "Normal content. " * 200 + "Access Denied" + "" assert len(html) >= 2048 result = detect_block_page(html) assert result.blocked is False def test_empty_response_blocked(self): result = detect_block_page("") assert result.blocked is True assert "Empty" in result.reason