|
14 | 14 | PdfRestConfigurationError, |
15 | 15 | PdfRestTimeoutError, |
16 | 16 | UpResponse, |
| 17 | + client as client_module, |
17 | 18 | ) |
18 | 19 |
|
19 | 20 | VALID_API_KEY = "12345678-1234-1234-1234-123456789abc" |
@@ -61,6 +62,39 @@ def handler(request: httpx.Request) -> httpx.Response: |
61 | 62 | assert response.product == "pdfRest API Toolkit" |
62 | 63 |
|
63 | 64 |
|
| 65 | +def test_client_sets_sdk_headers(monkeypatch: pytest.MonkeyPatch) -> None: |
| 66 | + monkeypatch.setenv("PDFREST_API_KEY", VALID_API_KEY) |
| 67 | + monkeypatch.setattr(client_module.importlib.metadata, "version", lambda _: "1.2.3") |
| 68 | + |
| 69 | + def handler(request: httpx.Request) -> httpx.Response: |
| 70 | + assert request.headers["wsn"] == "pdfrest-python" |
| 71 | + assert request.headers["User-Agent"] == "pdfrest-python-sdk/1.2.3" |
| 72 | + assert request.headers["Accept"] == "application/json" |
| 73 | + return httpx.Response(200, json=_build_up_response()) |
| 74 | + |
| 75 | + transport = httpx.MockTransport(handler) |
| 76 | + with PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client: |
| 77 | + client.up() |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.asyncio |
| 81 | +async def test_async_client_sets_sdk_headers( |
| 82 | + monkeypatch: pytest.MonkeyPatch, |
| 83 | +) -> None: |
| 84 | + monkeypatch.setenv("PDFREST_API_KEY", ASYNC_API_KEY) |
| 85 | + monkeypatch.setattr(client_module.importlib.metadata, "version", lambda _: "4.5.6") |
| 86 | + |
| 87 | + def handler(request: httpx.Request) -> httpx.Response: |
| 88 | + assert request.headers["wsn"] == "pdfrest-python" |
| 89 | + assert request.headers["User-Agent"] == "pdfrest-python-sdk/4.5.6" |
| 90 | + assert request.headers["Accept"] == "application/json" |
| 91 | + return httpx.Response(200, json=_build_up_response()) |
| 92 | + |
| 93 | + transport = httpx.MockTransport(handler) |
| 94 | + async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client: |
| 95 | + await client.up() |
| 96 | + |
| 97 | + |
64 | 98 | def test_missing_api_key_raises(monkeypatch: pytest.MonkeyPatch) -> None: |
65 | 99 | monkeypatch.delenv("PDFREST_API_KEY", raising=False) |
66 | 100 |
|
|
0 commit comments