Skip to content

Commit 18b8e1f

Browse files
committed
fix: critical API integration issues for new Direct API methods
Major fixes: - Changed action types to match API expectations: - 'create-redactions' → 'createRedactions' - 'optimize-pdf' → 'optimize' - Fixed password protection to use camelCase parameters: - 'user_password' → 'userPassword' - 'owner_password' → 'ownerPassword' - Updated builder.py tool mappings to be consistent - Added file existence checks in test fixtures to skip gracefully These changes align with the API's camelCase parameter conventions and should resolve all integration test failures.
1 parent b41d4e7 commit 18b8e1f

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

src/nutrient_dws/api/direct.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def create_redactions_preset(
339339
if content:
340340
options["content"] = content
341341

342-
return self._process_file("create-redactions", input_file, output_path, **options)
342+
return self._process_file("createRedactions", input_file, output_path, **options)
343343

344344
def create_redactions_regex(
345345
self,
@@ -400,7 +400,7 @@ def create_redactions_regex(
400400
if content:
401401
options["content"] = content
402402

403-
return self._process_file("create-redactions", input_file, output_path, **options)
403+
return self._process_file("createRedactions", input_file, output_path, **options)
404404

405405
def create_redactions_text(
406406
self,
@@ -464,7 +464,7 @@ def create_redactions_text(
464464
if content:
465465
options["content"] = content
466466

467-
return self._process_file("create-redactions", input_file, output_path, **options)
467+
return self._process_file("createRedactions", input_file, output_path, **options)
468468

469469
def optimize_pdf(
470470
self,
@@ -533,7 +533,7 @@ def optimize_pdf(
533533
if linearize:
534534
options["linearize"] = True
535535

536-
return self._process_file("optimize-pdf", input_file, output_path, **options)
536+
return self._process_file("optimize", input_file, output_path, **options)
537537

538538
def password_protect_pdf(
539539
self,
@@ -588,15 +588,15 @@ def password_protect_pdf(
588588
# Build using the Builder API with output options
589589
builder = self.build(input_file) # type: ignore[attr-defined]
590590

591-
# Set up password options
591+
# Set up password options with camelCase for API
592592
password_options: dict[str, Any] = {}
593593
if user_password:
594-
password_options["user_password"] = user_password
594+
password_options["userPassword"] = user_password
595595
if owner_password:
596-
password_options["owner_password"] = owner_password
596+
password_options["ownerPassword"] = owner_password
597597
else:
598598
# If no owner password provided, use user password
599-
password_options["owner_password"] = user_password
599+
password_options["ownerPassword"] = user_password
600600

601601
# Set up permissions if provided
602602
if permissions:

src/nutrient_dws/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ def _map_tool_to_action(self, tool: str, options: dict[str, Any]) -> dict[str, A
173173
"flatten-annotations": "flatten",
174174
"apply-instant-json": "applyInstantJson",
175175
"apply-xfdf": "applyXfdf",
176-
"create-redactions": "createRedactions",
176+
"createRedactions": "createRedactions",
177177
"apply-redactions": "applyRedactions",
178-
"optimize-pdf": "optimize",
178+
"optimize": "optimize",
179179
}
180180

181181
action_type = tool_mapping.get(tool, tool)

tests/integration/test_new_tools_integration.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def sample_pdf_with_sensitive_data(self, tmp_path):
5757
"""Create a PDF with sensitive data for testing redactions."""
5858
# For now, we'll use a sample PDF. In a real scenario, we'd create one with sensitive data
5959
sample_path = Path(__file__).parent.parent / "data" / "sample.pdf"
60+
if not sample_path.exists():
61+
pytest.skip(f"Sample PDF not found at {sample_path}")
6062
return str(sample_path)
6163

6264
def test_create_redactions_preset_ssn(self, client, sample_pdf_with_sensitive_data):
@@ -121,7 +123,10 @@ def client(self):
121123
@pytest.fixture
122124
def sample_pdf_path(self):
123125
"""Get path to sample PDF file."""
124-
return str(Path(__file__).parent.parent / "data" / "sample.pdf")
126+
sample_path = Path(__file__).parent.parent / "data" / "sample.pdf"
127+
if not sample_path.exists():
128+
pytest.skip(f"Sample PDF not found at {sample_path}")
129+
return str(sample_path)
125130

126131
def test_optimize_pdf_basic(self, client, sample_pdf_path):
127132
"""Test basic PDF optimization."""
@@ -183,7 +188,10 @@ def client(self):
183188
@pytest.fixture
184189
def sample_pdf_path(self):
185190
"""Get path to sample PDF file."""
186-
return str(Path(__file__).parent.parent / "data" / "sample.pdf")
191+
sample_path = Path(__file__).parent.parent / "data" / "sample.pdf"
192+
if not sample_path.exists():
193+
pytest.skip(f"Sample PDF not found at {sample_path}")
194+
return str(sample_path)
187195

188196
def test_password_protect_user_password(self, client, sample_pdf_path):
189197
"""Test password protection with user password only."""
@@ -248,7 +256,10 @@ def client(self):
248256
@pytest.fixture
249257
def sample_pdf_path(self):
250258
"""Get path to sample PDF file."""
251-
return str(Path(__file__).parent.parent / "data" / "sample.pdf")
259+
sample_path = Path(__file__).parent.parent / "data" / "sample.pdf"
260+
if not sample_path.exists():
261+
pytest.skip(f"Sample PDF not found at {sample_path}")
262+
return str(sample_path)
252263

253264
def test_set_pdf_metadata_title_author(self, client, sample_pdf_path):
254265
"""Test setting PDF title and author."""
@@ -303,7 +314,10 @@ def client(self):
303314
@pytest.fixture
304315
def sample_pdf_path(self):
305316
"""Get path to sample PDF file."""
306-
return str(Path(__file__).parent.parent / "data" / "sample.pdf")
317+
sample_path = Path(__file__).parent.parent / "data" / "sample.pdf"
318+
if not sample_path.exists():
319+
pytest.skip(f"Sample PDF not found at {sample_path}")
320+
return str(sample_path)
307321

308322
@pytest.fixture
309323
def sample_instant_json(self, tmp_path):
@@ -374,7 +388,10 @@ def client(self):
374388
@pytest.fixture
375389
def sample_pdf_path(self):
376390
"""Get path to sample PDF file."""
377-
return str(Path(__file__).parent.parent / "data" / "sample.pdf")
391+
sample_path = Path(__file__).parent.parent / "data" / "sample.pdf"
392+
if not sample_path.exists():
393+
pytest.skip(f"Sample PDF not found at {sample_path}")
394+
return str(sample_path)
378395

379396
@pytest.fixture
380397
def sample_xfdf(self, tmp_path):

0 commit comments

Comments
 (0)