Skip to content

Commit f6c97f8

Browse files
fix(documents): improve typing and naming
1 parent 32c844a commit f6c97f8

File tree

4 files changed

+27
-933
lines changed

4 files changed

+27
-933
lines changed

src/uipath/_services/documents_service.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ..models.documents import (
1414
ActionPriority,
1515
ExtractionResponse,
16-
ValidatedResult,
16+
ExtractionResult,
1717
ValidationAction,
1818
)
1919
from ..tracing._traced import traced
@@ -502,8 +502,8 @@ async def result_getter() -> Tuple[str, Any]:
502502
response["operationId"] = operation_id
503503
return ValidationAction.model_validate(response)
504504

505-
@traced(name="documents_create_validation_action", run_type="uipath")
506-
def create_validation_action(
505+
@traced(name="documents_create_validate_extraction_action", run_type="uipath")
506+
def create_validate_extraction_action(
507507
self,
508508
action_title: str,
509509
action_priority: ActionPriority,
@@ -513,7 +513,7 @@ def create_validation_action(
513513
storage_bucket_directory_path: str,
514514
extraction_response: ExtractionResponse,
515515
) -> ValidationAction:
516-
"""Create a validation action for a document based on the extraction response. More details about validation actions can be found in the [official documentation](https://docs.uipath.com/ixp/automation-cloud/latest/user-guide/validating-extractions).
516+
"""Create a validate extraction action for a document based on the extraction response. More details about validation actions can be found in the [official documentation](https://docs.uipath.com/ixp/automation-cloud/latest/user-guide/validating-extractions).
517517
518518
Args:
519519
action_title (str): Title of the action.
@@ -529,7 +529,7 @@ def create_validation_action(
529529
530530
Examples:
531531
```python
532-
validation_action = service.create_validation_action(
532+
validation_action = service.create_validate_extraction_action(
533533
action_title="Test Validation Action",
534534
action_priority=ActionPriority.MEDIUM,
535535
action_catalog="default_du_actions",
@@ -558,8 +558,8 @@ def create_validation_action(
558558
operation_id=operation_id,
559559
)
560560

561-
@traced(name="documents_create_validation_action_async", run_type="uipath")
562-
async def create_validation_action_async(
561+
@traced(name="documents_create_validate_extraction_action_async", run_type="uipath")
562+
async def create_validate_extraction_action_async(
563563
self,
564564
action_title: str,
565565
action_priority: ActionPriority,
@@ -569,7 +569,7 @@ async def create_validation_action_async(
569569
storage_bucket_directory_path: str,
570570
extraction_response: ExtractionResponse,
571571
) -> ValidationAction:
572-
"""Asynchronously create a validation action for a document based on the extraction response."""
572+
"""Asynchronously create a validate extraction action for a document based on the extraction response."""
573573
# Add reference to sync method docstring
574574
operation_id = await self._start_validation_async(
575575
project_id=extraction_response.project_id,
@@ -589,11 +589,11 @@ async def create_validation_action_async(
589589
operation_id=operation_id,
590590
)
591591

592-
@traced(name="documents_get_validation_result", run_type="uipath")
593-
def get_validation_result(
592+
@traced(name="documents_get_validate_extraction_result", run_type="uipath")
593+
def get_validate_extraction_result(
594594
self, validation_action: ValidationAction
595-
) -> ValidatedResult:
596-
"""Get the result of a validation action.
595+
) -> ExtractionResult:
596+
"""Get the result of a validate extraction action.
597597
598598
Note:
599599
This method will block until the validation action is completed, meaning the user has completed the validation in UiPath Action Center.
@@ -602,11 +602,11 @@ def get_validation_result(
602602
validation_action (ValidationAction): The validation action to get the result for, typically obtained from the [`create_validation_action`][uipath._services.documents_service.DocumentsService.create_validation_action] method.
603603
604604
Returns:
605-
ValidatedResult: The result of the validation action.
605+
ExtractionResult: The result of the validation action.
606606
607607
Examples:
608608
```python
609-
validated_result = service.get_validation_result(validation_action)
609+
validated_result = service.get_validate_extraction_result(validation_action)
610610
```
611611
"""
612612
response = self._wait_for_operation(
@@ -624,13 +624,13 @@ def get_validation_result(
624624
success_status="Completed",
625625
)
626626

627-
return ValidatedResult.model_validate(response)
627+
return ExtractionResult.model_validate(response)
628628

629-
@traced(name="documents_get_validation_result_async", run_type="uipath")
630-
async def get_validation_result_async(
629+
@traced(name="documents_get_validate_extraction_result_async", run_type="uipath")
630+
async def get_validate_extraction_result_async(
631631
self, validation_action: ValidationAction
632-
) -> ValidatedResult:
633-
"""Asynchronously get the result of a validation action."""
632+
) -> ExtractionResult:
633+
"""Asynchronously get the result of a validate extraction action."""
634634

635635
async def result_getter() -> Tuple[str, Any]:
636636
result = await self._get_validation_result_async(
@@ -648,4 +648,4 @@ async def result_getter() -> Tuple[str, Any]:
648648
success_status="Completed",
649649
)
650650

651-
return ValidatedResult.model_validate(response)
651+
return ExtractionResult.model_validate(response)

src/uipath/models/documents.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,3 @@ class ValidationAction(BaseModel):
108108
project_id: str = Field(alias="projectId")
109109
tag: str
110110
operation_id: str = Field(alias="operationId")
111-
112-
113-
class ValidatedResult(BaseModel):
114-
"""A model representing the result of a validation action.
115-
116-
Attributes:
117-
document_id (str): The ID of the validated document.
118-
results_document (dict): The validated results document.
119-
"""
120-
121-
model_config = ConfigDict(
122-
serialize_by_alias=True,
123-
validate_by_alias=True,
124-
)
125-
126-
document_id: str = Field(alias="DocumentId")
127-
results_document: dict = Field(alias="ResultsDocument") # type: ignore

tests/sdk/services/test_documents_service.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ def create_validation_action_response(documents_tests_data_path: Path) -> dict:
3737
return json.load(f)
3838

3939

40-
@pytest.fixture
41-
def validated_result(documents_tests_data_path: Path) -> dict: # type: ignore
42-
with open(
43-
documents_tests_data_path / "validated_result.json",
44-
"r",
45-
) as f:
46-
return json.load(f)
47-
48-
4940
class TestDocumentsService:
5041
@pytest.mark.parametrize("mode", ["sync", "async"])
5142
@pytest.mark.asyncio
@@ -348,7 +339,7 @@ async def test_create_validation_action(
348339

349340
# ACT
350341
if mode == "async":
351-
response = await service.create_validation_action_async(
342+
response = await service.create_validate_extraction_action_async(
352343
action_title=action_title,
353344
action_priority=action_priority,
354345
action_catalog=action_catalog,
@@ -360,7 +351,7 @@ async def test_create_validation_action(
360351
),
361352
)
362353
else:
363-
response = service.create_validation_action(
354+
response = service.create_validate_extraction_action(
364355
action_title=action_title,
365356
action_priority=action_priority,
366357
action_catalog=action_catalog,
@@ -388,7 +379,7 @@ async def test_get_validation_result(
388379
tenant: str,
389380
service: DocumentsService,
390381
create_validation_action_response: dict, # type: ignore
391-
validated_result: dict, # type: ignore
382+
extraction_response: dict, # type: ignore
392383
mode: str,
393384
):
394385
# ARRANGE
@@ -400,7 +391,7 @@ async def test_get_validation_result(
400391
create_validation_action_response["operationId"] = operation_id
401392
create_validation_action_response["actionStatus"] = "Completed"
402393
create_validation_action_response["validatedExtractionResults"] = (
403-
validated_result
394+
extraction_response["extractionResult"]
404395
)
405396

406397
httpx_mock.add_response(
@@ -412,20 +403,20 @@ async def test_get_validation_result(
412403

413404
# ACT
414405
if mode == "async":
415-
response = await service.get_validation_result_async(
406+
response = await service.get_validate_extraction_result_async(
416407
validation_action=ValidationAction.model_validate(
417408
create_validation_action_response
418409
)
419410
)
420411
else:
421-
response = service.get_validation_result(
412+
response = service.get_validate_extraction_result(
422413
validation_action=ValidationAction.model_validate(
423414
create_validation_action_response
424415
)
425416
)
426417

427418
# ASSERT
428-
assert response.model_dump() == validated_result
419+
assert response.model_dump() == extraction_response["extractionResult"]
429420

430421
@pytest.mark.parametrize("mode", ["sync", "async"])
431422
@pytest.mark.asyncio

0 commit comments

Comments
 (0)