Skip to content

Commit

Permalink
integration test for dm file diagram detect
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Liabøtrø committed Aug 30, 2024
1 parent 1ba65e7 commit 64b47cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cognite/client/_api/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _process_file_ids(
file_references, FileReference, "file_references must be FileReference or list of FileReference"
)
# Handle empty lists
if not (external_ids or ids or file_references):
if not (external_ids or ids or instance_ids or file_references):
raise ValueError("No ids, external ids or file references specified")

id_objs = [{"fileId": id} for id in ids]
Expand Down
22 changes: 22 additions & 0 deletions tests/tests_integration/test_api/test_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
DiagramDetectResults,
FileReference,
)
from cognite.client.data_classes.data_modeling import NodeId

PNID_FILE_ID = 3261066797848581
DIAGRAM_SPACE = "diagram_space"
DM_FILE_EXTERNAL_ID = "diagrams_test_pnid.pdf"

ELEVEN_PAGE_PNID_EXTERNAL_ID = "functional_tests.pdf"
FIFTY_FIVE_PAGE_PNID_EXTERNAL_ID = "5functional_tests.pdf"
Expand Down Expand Up @@ -103,3 +106,22 @@ def test_run_diagram_detect_in_pattern_mode(self, cognite_client):

assert len(detected_by_resource_type["file_reference"]) >= 10 # 14 seen when making the test
assert len(detected_by_resource_type["instrument"]) >= 60 # 72 seen when making the test

def test_run_diagram_detect_with_file_instance_id(self, cognite_client):
entities = [{"name": "YT-96122"}, {"name": "XE-96125", "ee": 123}, {"name": "XWDW-9615"}]

file_instance_id = NodeId(space=DIAGRAM_SPACE, external_id=DM_FILE_EXTERNAL_ID)
detect_job = cognite_client.diagrams.detect(file_instance_ids=[file_instance_id], entities=entities)
assert isinstance(detect_job, DiagramDetectResults)
assert {"statusCount", "numFiles", "items", "partialMatch", "minTokens", "searchField"}.issubset(
detect_job.result
)
assert {"fileId", "annotations"}.issubset(detect_job.result["items"][0])
assert "Completed" == detect_job.status
assert [] == detect_job.errors
assert isinstance(detect_job.items[0], DiagramDetectItem)
assert isinstance(detect_job[PNID_FILE_ID], DiagramDetectItem)

assert 3 == len(detect_job[PNID_FILE_ID].annotations)
for annotation in detect_job[PNID_FILE_ID].annotations:
assert 1 == annotation["region"]["page"]

0 comments on commit 64b47cf

Please sign in to comment.