-
Notifications
You must be signed in to change notification settings - Fork 3
PDFCLOUD-5555 Add zip and unzip client methods #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
datalogics-tsmith
merged 5 commits into
pdfrest:main
from
datalogics-cgreen:pdfcloud-5464-zip
Feb 18, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62f7e00
Add ZIP tool
datalogics-cgreen fbb7407
Add tests of ZIP tool
datalogics-cgreen 4bc2d1d
Add Unzip tool
datalogics-cgreen d2ca8b3
Add tests of Unzip tool
datalogics-cgreen b68d8c3
tests: Add async tests for unzip_file and zip_files methods
datalogics-kam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import zipfile | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient | ||
| from pdfrest.models import PdfRestFile | ||
|
|
||
| from ..resources import get_test_resource_path | ||
|
|
||
|
|
||
| def _build_zip_payload(tmp_path: Path) -> Path: | ||
| zip_path = tmp_path / "sample.zip" | ||
| with zipfile.ZipFile(zip_path, "w") as bundle: | ||
| report_path = get_test_resource_path("report.pdf") | ||
| bundle.write(report_path, arcname="report.pdf") | ||
| return zip_path | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def uploaded_zip_file( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| tmp_path_factory: pytest.TempPathFactory, | ||
| ) -> PdfRestFile: | ||
| zip_path = _build_zip_payload(tmp_path_factory.mktemp("zip-input")) | ||
| with PdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client: | ||
| return client.files.create_from_paths([zip_path])[0] | ||
|
|
||
|
|
||
| def test_live_unzip_file( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| uploaded_zip_file: PdfRestFile, | ||
| ) -> None: | ||
| with PdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client: | ||
| response = client.unzip_file(uploaded_zip_file) | ||
|
|
||
| assert response.output_files | ||
| assert all(file.size > 0 for file in response.output_files) | ||
| assert all(file.name for file in response.output_files) | ||
| assert str(response.input_id) == str(uploaded_zip_file.id) | ||
|
|
||
|
|
||
| def test_live_unzip_invalid_override( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| uploaded_zip_file: PdfRestFile, | ||
| ) -> None: | ||
| with ( | ||
| PdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client, | ||
| pytest.raises(PdfRestApiError, match="id"), | ||
| ): | ||
| client.unzip_file( | ||
| uploaded_zip_file, | ||
| extra_body={"id": "not-a-uuid"}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_live_unzip_file_async( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| uploaded_zip_file: PdfRestFile, | ||
| ) -> None: | ||
| async with AsyncPdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client: | ||
| response = await client.unzip_file( | ||
| uploaded_zip_file, | ||
| extra_query={"trace": "async"}, | ||
| ) | ||
|
|
||
| assert response.output_files | ||
| assert all(file.size > 0 for file in response.output_files) | ||
| assert all(file.name for file in response.output_files) | ||
| assert str(response.input_id) == str(uploaded_zip_file.id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient | ||
| from pdfrest.models import PdfRestFile | ||
|
|
||
| from ..resources import get_test_resource_path | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def uploaded_zip_inputs( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| ) -> list[PdfRestFile]: | ||
| paths = [ | ||
| get_test_resource_path("report.pdf"), | ||
| get_test_resource_path("report.docx"), | ||
| ] | ||
| with PdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client: | ||
| return client.files.create_from_paths(paths) | ||
|
|
||
|
|
||
| def test_live_zip_files( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| uploaded_zip_inputs: list[PdfRestFile], | ||
| ) -> None: | ||
| with PdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client: | ||
| response = client.zip_files( | ||
| uploaded_zip_inputs, | ||
| output="live-zip", | ||
| ) | ||
|
|
||
| assert response.output_file.name.startswith("live-zip") | ||
| assert response.output_file.name.endswith(".zip") | ||
| assert response.output_file.type == "application/zip" | ||
| assert response.output_file.size > 0 | ||
| assert {str(file.id) for file in uploaded_zip_inputs} == { | ||
| str(file_id) for file_id in response.input_ids | ||
| } | ||
|
|
||
|
|
||
| def test_live_zip_files_invalid_id_override( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| uploaded_zip_inputs: list[PdfRestFile], | ||
| ) -> None: | ||
| with ( | ||
| PdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client, | ||
| pytest.raises(PdfRestApiError, match="id"), | ||
| ): | ||
| client.zip_files( | ||
| uploaded_zip_inputs, | ||
| extra_body={"id": "not-a-uuid"}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_live_zip_files_async( | ||
| pdfrest_api_key: str, | ||
| pdfrest_live_base_url: str, | ||
| uploaded_zip_inputs: list[PdfRestFile], | ||
| ) -> None: | ||
| async with AsyncPdfRestClient( | ||
| api_key=pdfrest_api_key, | ||
| base_url=pdfrest_live_base_url, | ||
| ) as client: | ||
| response = await client.zip_files( | ||
| uploaded_zip_inputs, | ||
| output="live-zip-async", | ||
| extra_query={"trace": "async"}, | ||
| ) | ||
|
|
||
| assert response.output_file.name.startswith("live-zip-async") | ||
| assert response.output_file.name.endswith(".zip") | ||
| assert response.output_file.type == "application/zip" | ||
| assert response.output_file.size > 0 | ||
| assert {str(file.id) for file in uploaded_zip_inputs} == { | ||
| str(file_id) for file_id in response.input_ids | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.