Files
Scrapling/tests/fetchers/sync/test_requests_session.py
T
2025-08-15 04:52:51 +03:00

48 lines
1.3 KiB
Python

import pytest
from scrapling.engines.static import FetcherSession, FetcherClient
class TestFetcherSession:
"""Test FetcherSession functionality"""
def test_fetcher_session_creation(self):
"""Test FetcherSession creation"""
session = FetcherSession(
timeout=30,
retries=3,
stealthy_headers=True
)
assert session.default_timeout == 30
assert session.default_retries == 3
assert session.stealth is True
def test_fetcher_session_context_manager(self):
"""Test FetcherSession as a context manager"""
session = FetcherSession()
with session as s:
assert s == session
assert session._curl_session is not None
# Session should be cleaned up
def test_fetcher_session_double_enter(self):
"""Test error on double entering"""
session = FetcherSession()
with session:
with pytest.raises(RuntimeError):
session.__enter__()
def test_fetcher_client_creation(self):
"""Test FetcherClient creation"""
client = FetcherClient()
# Should not have context manager methods
assert client.__enter__ is None
assert client.__exit__ is None
assert client._curl_session is True # Special marker