Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
silvavelosa committed Nov 22, 2023
1 parent f462bb4 commit 39f7eba
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions tests/tests_integration/test_api/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from cognite.client.data_classes.workflows import (
CDFTaskParameters,
FunctionTaskParameters,
SubworkflowTaskParameters,
TransformationTaskParameters,
Workflow,
WorkflowDefinitionUpsert,
Expand Down Expand Up @@ -70,13 +71,37 @@ def workflow_version_list(cognite_client: CogniteClient) -> WorkflowVersionList:
workflow_definition=WorkflowDefinitionUpsert(
tasks=[
WorkflowTask(
external_id=f"{workflow_id}-2-task1",
external_id="subworkflow1",
parameters=SubworkflowTaskParameters(
tasks=[
WorkflowTask(
external_id="s1-task1",
parameters=CDFTaskParameters(
resource_path="/dummy/no/real/resource/path",
method="GET",
body={"limit": 1},
),
),
WorkflowTask(
external_id="s1-task2",
parameters=CDFTaskParameters(
resource_path="/dummy/no/real/resource/path",
method="GET",
body={"limit": 1},
),
),
]
),
),
WorkflowTask(
external_id="task1",
parameters=CDFTaskParameters(
resource_path="/dummy/no/real/resource/path",
method="GET",
body={"limit": 1},
),
)
depends_on=["subworkflow1"],
),
],
description=None,
),
Expand Down Expand Up @@ -106,7 +131,10 @@ def handle(client, data: dict):
return output

cognite_client.functions.create(name="Add", external_id=external_id, function_handle=handle)
pytest.skip("Function need to be redeployed, skipping tests that need it", allow_module_level=True)
pytest.skip(
"Function need to be redeployed, skipping tests that need it",
allow_module_level=True,
)


@pytest.fixture(scope="session")
Expand All @@ -122,7 +150,10 @@ def handle(client, data: dict):
return output

cognite_client.functions.create(name="Multiply", external_id=external_id, function_handle=handle)
pytest.skip("Function need to be redeployed, skipping tests that need it", allow_module_level=True)
pytest.skip(
"Function need to be redeployed, skipping tests that need it",
allow_module_level=True,
)


@pytest.fixture
Expand Down Expand Up @@ -171,7 +202,9 @@ def workflow_execution_list(
return executions
# Creating at least one execution
result = cognite_client.workflows.executions.trigger(
add_multiply_workflow.workflow_external_id, add_multiply_workflow.version, {"a": 5, "b": 6}
add_multiply_workflow.workflow_external_id,
add_multiply_workflow.version,
{"a": 5, "b": 6},
)
t0 = time.time()
while result.status != "completed":
Expand Down Expand Up @@ -274,14 +307,16 @@ def test_list_workflow_version_limit(
def test_delete_non_existing_raise(self, cognite_client: CogniteClient) -> None:
with pytest.raises(CogniteAPIError) as e:
cognite_client.workflows.versions.delete(
("integration_test-non_existing_workflow_version", "1"), ignore_unknown_ids=False
("integration_test-non_existing_workflow_version", "1"),
ignore_unknown_ids=False,
)

assert "not found" in str(e.value)

def test_delete_non_existing(self, cognite_client: CogniteClient) -> None:
cognite_client.workflows.versions.delete(
("integration_test-non_existing_workflow_version", "1"), ignore_unknown_ids=True
("integration_test-non_existing_workflow_version", "1"),
ignore_unknown_ids=True,
)

def test_retrieve_workflow(self, cognite_client: CogniteClient, workflow_version_list: WorkflowVersionList) -> None:
Expand All @@ -299,7 +334,9 @@ def test_retrieve_non_existing_workflow(self, cognite_client: CogniteClient) ->

class TestWorkflowExecutions:
def test_list_workflow_executions(
self, cognite_client: CogniteClient, workflow_execution_list: WorkflowExecutionList
self,
cognite_client: CogniteClient,
workflow_execution_list: WorkflowExecutionList,
) -> None:
workflow_ids = set(w.as_workflow_id() for w in workflow_execution_list)

Expand All @@ -311,7 +348,9 @@ def test_list_workflow_executions(
assert all(w.as_workflow_id() in workflow_ids for w in listed)

def test_retrieve_workflow_execution_detailed(
self, cognite_client: CogniteClient, workflow_execution_list: WorkflowExecutionList
self,
cognite_client: CogniteClient,
workflow_execution_list: WorkflowExecutionList,
) -> None:
retrieved = cognite_client.workflows.executions.retrieve_detailed(workflow_execution_list[0].id)

Expand Down

0 comments on commit 39f7eba

Please sign in to comment.