Skip to content

Commit 3eac74b

Browse files
query_pdf_info: Default to all queries.
- Introduced `ALL_PDF_INFO_QUERIES` constant for predefined query sets. - Updated synchronous and asynchronous `query_pdf_info` methods to use `ALL_PDF_INFO_QUERIES` as the default value for `queries`. - Adjusted type definitions and imports accordingly. - Updated tests to cover new defaults. Assisted-by: Codex
1 parent 60cff20 commit 3eac74b

6 files changed

Lines changed: 47 additions & 9 deletions

File tree

src/pdfrest/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
TiffPdfRestPayload,
4646
UploadURLs,
4747
)
48-
from .types import PdfInfoQuery
48+
from .types import ALL_PDF_INFO_QUERIES, PdfInfoQuery
4949

5050
DEFAULT_BASE_URL = "https://api.pdfrest.com"
5151
API_KEY_ENV_VAR = "PDFREST_API_KEY"
@@ -1420,7 +1420,7 @@ def query_pdf_info(
14201420
self,
14211421
file: PdfRestFile | Sequence[PdfRestFile],
14221422
*,
1423-
queries: Sequence[PdfInfoQuery] | PdfInfoQuery,
1423+
queries: Sequence[PdfInfoQuery] | PdfInfoQuery = ALL_PDF_INFO_QUERIES,
14241424
extra_query: Query | None = None,
14251425
extra_headers: AnyMapping | None = None,
14261426
extra_body: Body | None = None,
@@ -1687,7 +1687,7 @@ async def query_pdf_info(
16871687
self,
16881688
file: PdfRestFile | Sequence[PdfRestFile],
16891689
*,
1690-
queries: Sequence[PdfInfoQuery] | PdfInfoQuery,
1690+
queries: Sequence[PdfInfoQuery] | PdfInfoQuery = ALL_PDF_INFO_QUERIES,
16911691
extra_query: Query | None = None,
16921692
extra_headers: AnyMapping | None = None,
16931693
extra_body: Body | None = None,

src/pdfrest/models/_validators.py

Whitespace-only changes.

src/pdfrest/types/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Public import surface for shared pdfrest types."""
22

3-
from .public import PdfInfoQuery
3+
from .public import ALL_PDF_INFO_QUERIES, PdfInfoQuery
44

5-
__all__ = ["PdfInfoQuery"]
5+
__all__ = ["ALL_PDF_INFO_QUERIES", "PdfInfoQuery"]

src/pdfrest/types/public.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from __future__ import annotations
44

5-
from typing import Literal
5+
from typing import Literal, cast, get_args
66

7-
__all__ = ("PdfInfoQuery",)
7+
__all__ = ("ALL_PDF_INFO_QUERIES", "PdfInfoQuery")
88

99
PdfInfoQuery = Literal[
1010
"tagged",
@@ -39,3 +39,7 @@
3939
"pdfx_claim",
4040
"requires_password_to_open",
4141
]
42+
43+
ALL_PDF_INFO_QUERIES: tuple[PdfInfoQuery, ...] = cast(
44+
tuple[PdfInfoQuery, ...], get_args(PdfInfoQuery)
45+
)

tests/live/test_live_pdf_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
88
from pdfrest.models import PdfRestFile, PdfRestInfoResponse
99
from pdfrest.models._internal import PdfInfoPayload
10-
from pdfrest.types import PdfInfoQuery
10+
from pdfrest.types import ALL_PDF_INFO_QUERIES, PdfInfoQuery
1111

1212
from ..resources import get_test_resource_path
1313

@@ -19,6 +19,7 @@ def _allowed_queries() -> tuple[PdfInfoQuery, ...]:
1919

2020

2121
ALLOWED_QUERIES: tuple[PdfInfoQuery, ...] = _allowed_queries()
22+
assert ALLOWED_QUERIES == ALL_PDF_INFO_QUERIES
2223

2324

2425
EXPECTED_VALUES: dict[PdfInfoQuery, Any] = {

tests/test_query_pdf_info.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pdfrest import AsyncPdfRestClient, PdfRestClient
1111
from pdfrest.models import PdfRestFileID, PdfRestInfoResponse
12-
from pdfrest.types import PdfInfoQuery
12+
from pdfrest.types import ALL_PDF_INFO_QUERIES, PdfInfoQuery
1313

1414
from .graphics_test_helpers import ASYNC_API_KEY, VALID_API_KEY, make_pdf_file
1515

@@ -61,6 +61,39 @@ def handler(request: httpx.Request) -> httpx.Response:
6161
assert response.all_queries_processed is True
6262

6363

64+
def test_query_pdf_info_default_queries(monkeypatch: pytest.MonkeyPatch) -> None:
65+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
66+
input_file = make_pdf_file(str(PdfRestFileID.generate()))
67+
expected_serialized = ",".join(ALL_PDF_INFO_QUERIES)
68+
69+
def handler(request: httpx.Request) -> httpx.Response:
70+
if request.method != "POST" or request.url.path != "/pdf-info":
71+
msg = f"Unexpected request {request.method} {request.url}"
72+
raise AssertionError(msg)
73+
payload = json.loads(request.content.decode("utf-8"))
74+
assert payload == {
75+
"id": str(input_file.id),
76+
"queries": expected_serialized,
77+
}
78+
return httpx.Response(
79+
200,
80+
json={
81+
"inputId": str(input_file.id),
82+
"page_count": 1,
83+
"tagged": False,
84+
"allQueriesProcessed": True,
85+
},
86+
)
87+
88+
transport = httpx.MockTransport(handler)
89+
with PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client:
90+
response = client.query_pdf_info(input_file)
91+
92+
assert isinstance(response, PdfRestInfoResponse)
93+
assert response.page_count == 1
94+
assert response.tagged is False
95+
96+
6497
def test_query_pdf_info_request_customization(monkeypatch: pytest.MonkeyPatch) -> None:
6598
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
6699
resource_id = PdfRestFileID.generate()

0 commit comments

Comments
 (0)