From 64b47cfc5d1770e6f56a6fb8d8ad92aa4d2dc5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ola=20Liab=C3=B8tr=C3=B8?= Date: Fri, 30 Aug 2024 08:52:35 +0200 Subject: [PATCH] integration test for dm file diagram detect --- cognite/client/_api/diagrams.py | 2 +- .../test_api/test_diagrams.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cognite/client/_api/diagrams.py b/cognite/client/_api/diagrams.py index f3c1ba55d..01da62154 100644 --- a/cognite/client/_api/diagrams.py +++ b/cognite/client/_api/diagrams.py @@ -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] diff --git a/tests/tests_integration/test_api/test_diagrams.py b/tests/tests_integration/test_api/test_diagrams.py index bd223e3bb..29e5f1f1c 100644 --- a/tests/tests_integration/test_api/test_diagrams.py +++ b/tests/tests_integration/test_api/test_diagrams.py @@ -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" @@ -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"]