Skip to content

Commit ed7e1ff

Browse files
author
Cursor
committed
Add autoscraper test to test harness
1 parent 45d9955 commit ed7e1ff

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

test_proxy_headers.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,68 @@ def test(self, config: TestConfig) -> TestResult:
401401
)
402402

403403

404+
# =============================================================================
405+
# autoscraper Test
406+
# =============================================================================
407+
408+
class AutoscraperTest(ModuleTest):
409+
"""Test for autoscraper extension."""
410+
411+
name = "autoscraper"
412+
413+
def test(self, config: TestConfig) -> TestResult:
414+
try:
415+
from python_proxy_headers.autoscraper_proxy import ProxyAutoScraper
416+
417+
# Create scraper with optional proxy headers to send
418+
scraper = ProxyAutoScraper(proxy_headers=config.proxy_headers_to_send or None)
419+
420+
# Access the underlying ProxySession to test proxy headers
421+
# (AutoScraper itself doesn't expose response headers)
422+
session = scraper._get_session()
423+
session.proxies = {
424+
'http': config.proxy_url,
425+
'https': config.proxy_url
426+
}
427+
428+
# Make request using the session directly
429+
response = session.get(config.test_url)
430+
431+
# Check for proxy header in response
432+
header_value = self._check_header(dict(response.headers), config.proxy_header)
433+
434+
# Clean up
435+
scraper.close()
436+
437+
if header_value:
438+
return TestResult(
439+
module_name=self.name,
440+
success=True,
441+
header_value=header_value,
442+
response_status=response.status_code
443+
)
444+
else:
445+
return TestResult(
446+
module_name=self.name,
447+
success=False,
448+
error=f"Header '{config.proxy_header}' not found in response",
449+
response_status=response.status_code
450+
)
451+
452+
except ImportError as e:
453+
return TestResult(
454+
module_name=self.name,
455+
success=False,
456+
error=f"Import error: {e}"
457+
)
458+
except Exception as e:
459+
return TestResult(
460+
module_name=self.name,
461+
success=False,
462+
error=f"{type(e).__name__}: {e}"
463+
)
464+
465+
404466
# =============================================================================
405467
# Test Registry
406468
# =============================================================================
@@ -411,6 +473,7 @@ def test(self, config: TestConfig) -> TestResult:
411473
'requests': RequestsTest,
412474
'aiohttp': AiohttpTest,
413475
'httpx': HttpxTest,
476+
'autoscraper': AutoscraperTest,
414477
}
415478

416479

0 commit comments

Comments
 (0)