PDFCLOUD-5839 Re-align tests with API#42
Conversation
✅ Deploy Preview for pdfrest-python ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Had to close and open to get the tests to run, go figure. |
a3a16ca to
54e584d
Compare
datalogics-kam
left a comment
There was a problem hiding this comment.
Changes to the PDF/A support.
- Don't change the client interface to be open ended for
PdfAType. It should still strictly declare canonical types. Type hinting is a hint, so the user can still pass a lower casestr, and the low level validation will fix it. - I agree on the less strict validation before going to pdfRest, just avoid duplicating lists of values by using
get_args.
| file: PdfRestFile | Sequence[PdfRestFile], | ||
| *, | ||
| output_type: PdfAType, | ||
| output_type: PdfAOutputType, |
There was a problem hiding this comment.
This is a tough one; changing the name of the type is a breaking change to the interface.
Changing to a type that has | str removes type checking and IDE assistance.
It's totally okay that that the typing system of this interface is more strict than pdfRest. It can guide the user toward canonical use while still allowing non-conforming inputs.
- If the user is using types strictly, and the IDE is assisting in choosing values, it'll suggest upper case and all is good. In this case,
Literalworks kind of likeEnumStr, in that there's one best way to write it. - If the user isn't using types, they can put any string they want here, and the payload class will validate it. Even if it's lower case.
Please remove changes to the client interface here.
| #: PDF/A conformance targets accepted by ``convert_to_pdfa``. | ||
| #: Canonical PDF/A conformance targets accepted by ``convert_to_pdfa``. | ||
| PdfAType = Literal["PDF/A-1b", "PDF/A-2b", "PDF/A-2u", "PDF/A-3b", "PDF/A-3u"] | ||
| #: Caller-facing ``convert_to_pdfa`` input type. Values are matched |
There was a problem hiding this comment.
Please just take out PdfAOutputType. Saying | str is as wide open as just str, so this isn't really constraining anything.
| response = client.convert_to_pdfa( | ||
| input_file, | ||
| output_type="PDF/A-3b", | ||
| output_type="pdf/a-3b", |
There was a problem hiding this comment.
There's a new test that tests lowercase; I would suggest that this revert to uppercase as it was before.
| response = await client.convert_to_pdfa( | ||
| input_file, | ||
| output_type="PDF/A-2u", | ||
| output_type="pdf/a-2u", |
There was a problem hiding this comment.
There's a new test that tests lowercase; I would suggest that this revert to uppercase as it was before.
| PDFA_OUTPUT_TYPES: tuple[PdfAType, ...] = ( | ||
| "PDF/A-1b", | ||
| "PDF/A-2b", | ||
| "PDF/A-2u", | ||
| "PDF/A-3b", | ||
| "PDF/A-3u", | ||
| ) |
There was a problem hiding this comment.
Pllease avoid duplication here; it's possible to get the values from the literal
PDFA_OUTPUT_TYPES: tuple[PdfAType, ...] = get_args(PdfAType)
(you'll have to import get_args from typing)
54e584d to
c4f7195
Compare
c4f7195 to
b7bb76a
Compare
b7bb76a to
18b4748
Compare
|
This:
needs to come out of the commit message on bea3204. Otherwise, I think it's improved. |
- Normalize PDF/A `output_type` values case-insensitively during payload validation before enforcing the canonical `PdfAType` literals. - Derive the accepted canonical values from `get_args(PdfAType)` instead of maintaining a separate hard-coded list. - Update unit and live PDF/A tests to cover lowercase inputs. Assisted-by: Codex
- Add sync and async live tests proving `logo_opacity=0.0` succeeds. - Keep invalid-opacity cases focused on out-of-range values by supplying required signature names in the overridden payload. Assisted-by: Codex
18b4748 to
619a011
Compare
datalogics-kam
left a comment
There was a problem hiding this comment.
Review findings from Codex PR Review Auditor. I did not rerun live tests because the previously attached live server was incorrect; the comments below are based on the diff, policy files, and focused mocked/unit coverage.
| output_type: Annotated[ | ||
| PdfAType, | ||
| Field(serialization_alias="output_type"), | ||
| BeforeValidator(_normalize_pdfa_output_type), |
There was a problem hiding this comment.
[P2] This changes local payload validation/serialization, but the branch only adds live coverage. Please add sync and async MockTransport tests, or payload-model tests plus client assertions, showing lowercase output_type normalizes to canonical PDF/A-2b in the outbound /pdfa body.
| "type": "new", | ||
| "name": "live-logo-opacity-zero", | ||
| "location": make_signature_location(), | ||
| "logo_opacity": 0.0, |
There was a problem hiding this comment.
[P1] This succeeds only by overriding the serialized body with extra_body; callers using signature_configuration={..., "logo_opacity": 0.0} still hit the SDK's gt=0 validation. If zero is now valid, update the payload constraint and unit tests, then exercise the public argument path instead of bypassing it.
There was a problem hiding this comment.
I think what Codex is saying here is that the logo opacity is still gt=0 in _internal.py, at line 1024, but should be ge=0 plus appropriate tests.
datalogics-kam
left a comment
There was a problem hiding this comment.
The PDF/A work looks a lot better, but I ran the PR Review Auditor skill and it found a few things; please address those.
PDFCLOUD-5839
Why this change
This branch closes two validation gaps in the SDK’s live and payload-level coverage.
First,
convert_to_pdfanow accepts case-insensitiveoutput_typestrings at validation time while keeping the public type surface opinionated around the canonicalPdfATypeliterals. That preserves IDE guidance and stricter typing for callers without forcing runtime inputs to already match the canonical case.Second, the live signing suite was treating
logo_opacity=0.0as invalid even though zero opacity is a valid boundary value. That left the branch without a test proving the lower bound is accepted.What changed
For PDF/A conversion, the payload validator now normalizes string
output_typevalues case-insensitively before enforcing the existingPdfATypeliteral. The canonical allowed values are derived fromget_args(PdfAType)so the validation logic does not maintain a second hard-coded list.The PDF/A live suite was updated to add explicit sync and async lowercase input coverage, while preserving the canonical uppercase coverage already driven from
PdfAType.For signing, the live tests now separate the invalid-opacity coverage from the zero-opacity boundary. Negative values remain the lower-bound failure case, and new sync and async live tests assert that
logo_opacity=0.0succeeds.Behavior changes
convert_to_pdfanow accepts inputs such as"pdf/a-2b"and normalizes them to the canonical PDF/A literal before request serialization. Invalid values still fail validation or server-side checks as before.The sign-PDF live suite now reflects the intended boundary behavior for
logo_opacity: values below0.0are rejected, while exactly0.0is treated as valid.Validation
Validated locally with:
uv run pytest -n auto --maxschedchunk 2 tests/test_convert_to_pdfa.pyuv run ruff check tests/test_convert_to_pdfa.pyuv run basedpyright tests/test_convert_to_pdfa.py tests/live/test_live_convert_to_pdfa.pyNot run locally:
tests/live/test_live_convert_to_pdfa.pytests/live/test_live_sign_pdf.pyThose live suites require pdfRest credentials and service access.
Risks and follow-ups
The main runtime change is intentionally narrow and limited to PDF/A
output_typenormalization. The larger risk is drift between live API behavior and the SDK’s expectations, which is why the added live coverage matters here.This branch does not add broader unit coverage for lowercase PDF/A inputs beyond the existing focused request/validation tests, and it does not rerun the full nox matrix as part of this iteration.