|
| 1 | +import asyncio |
| 2 | + |
| 3 | +from hyperbrowser import AsyncHyperbrowser, Hyperbrowser |
| 4 | +from hyperbrowser.config import ClientConfig |
| 5 | +from hyperbrowser.transport.async_transport import AsyncTransport |
| 6 | +from hyperbrowser.transport.sync import SyncTransport |
| 7 | + |
| 8 | + |
| 9 | +def test_sync_transport_accepts_custom_headers(): |
| 10 | + transport = SyncTransport( |
| 11 | + api_key="test-key", |
| 12 | + headers={"X-Correlation-Id": "abc123", "User-Agent": "custom-agent"}, |
| 13 | + ) |
| 14 | + try: |
| 15 | + assert transport.client.headers["x-api-key"] == "test-key" |
| 16 | + assert transport.client.headers["X-Correlation-Id"] == "abc123" |
| 17 | + assert transport.client.headers["User-Agent"] == "custom-agent" |
| 18 | + finally: |
| 19 | + transport.close() |
| 20 | + |
| 21 | + |
| 22 | +def test_async_transport_accepts_custom_headers(): |
| 23 | + async def run() -> None: |
| 24 | + transport = AsyncTransport( |
| 25 | + api_key="test-key", |
| 26 | + headers={"X-Correlation-Id": "abc123", "User-Agent": "custom-agent"}, |
| 27 | + ) |
| 28 | + try: |
| 29 | + assert transport.client.headers["x-api-key"] == "test-key" |
| 30 | + assert transport.client.headers["X-Correlation-Id"] == "abc123" |
| 31 | + assert transport.client.headers["User-Agent"] == "custom-agent" |
| 32 | + finally: |
| 33 | + await transport.close() |
| 34 | + |
| 35 | + asyncio.run(run()) |
| 36 | + |
| 37 | + |
| 38 | +def test_sync_client_config_headers_are_applied_to_transport(): |
| 39 | + client = Hyperbrowser( |
| 40 | + config=ClientConfig(api_key="test-key", headers={"X-Team-Trace": "team-1"}) |
| 41 | + ) |
| 42 | + try: |
| 43 | + assert client.transport.client.headers["X-Team-Trace"] == "team-1" |
| 44 | + finally: |
| 45 | + client.close() |
| 46 | + |
| 47 | + |
| 48 | +def test_async_client_config_headers_are_applied_to_transport(): |
| 49 | + async def run() -> None: |
| 50 | + client = AsyncHyperbrowser( |
| 51 | + config=ClientConfig(api_key="test-key", headers={"X-Team-Trace": "team-1"}) |
| 52 | + ) |
| 53 | + try: |
| 54 | + assert client.transport.client.headers["X-Team-Trace"] == "team-1" |
| 55 | + finally: |
| 56 | + await client.close() |
| 57 | + |
| 58 | + asyncio.run(run()) |
0 commit comments