Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereiracgn committed Dec 10, 2024
1 parent 1cdc8b2 commit 9fead1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
14 changes: 7 additions & 7 deletions tests/tests_integration/test_api/test_simulators/seed/data.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import time

data_set_id = 1521375514069
development_data_set_id = 97552494921583

# data_set_id = 1521375514069
# development_data_set_id = 97552494921583
data_set_id = 97552494921583

resource_names = {
"simulator_external_id": "py_sdk_integration_tests",
"simulator_integration_external_id": "py_sdk_integration_tests_connector",
"simulator_model_external_id": "integration_tests_workflow_model_02",
"simulator_model_revision_external_id": "integration_tests_workflow_model_revision_1",
"simulator_model_external_id": "py_sdk_integration_tests_model",
"simulator_model_revision_external_id": "pysdk_model_revision",
"simulator_model_file_external_id": "ShowerMixer_simulator_model_file_3",
"simulator_routine_external_id": "integration_tests_workflow_routine",
"simulator_routine_revision_external_id": "integration_tests_workflow_routine_revision",
"simulator_routine_external_id": "pysdk_routine",
"simulator_routine_revision_external_id": "pysdk_routine_revision",
"simulator_test_data_set_id": data_set_id,
}

Expand Down
43 changes: 27 additions & 16 deletions tests/tests_integration/test_api/test_simulators/test_simulators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
import time

import pytest
Expand All @@ -11,8 +12,8 @@
)
from cognite.client.exceptions import CogniteAPIError
from tests.tests_integration.test_api.test_simulators.seed.data import (
resource_names,
data_set_id,
resource_names,
simulator,
simulator_integration,
simulator_model,
Expand All @@ -21,6 +22,8 @@
simulator_routine_revision,
)

model_unique_external_id = f"{resource_names['simulator_model_external_id']}_{random.randint(100,500)}"


@pytest.fixture(scope="class")
def seed_resource_names() -> dict[str, str]:
Expand Down Expand Up @@ -79,7 +82,7 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) ->
@pytest.fixture
def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integration) -> None:
models = cognite_client.simulators.models.list()
model_seed = list(filter(lambda x: x.external_id == simulator_model["externalId"], models))
model_seed = list(filter(lambda x: x.external_id == model_unique_external_id, models))

if len(model_seed) > 0:
cognite_client.post(
Expand All @@ -89,23 +92,37 @@ def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integrat

cognite_client.post(
f"/api/v1/projects/{cognite_client.config.project}/simulators/models",
json={"items": [simulator_model]}, # Post actual simulator models here
json={
"items": [{**simulator_model, "externalId": model_unique_external_id}]
}, # Post actual simulator models here
)

yield

models = cognite_client.simulators.models.list()
model_seed = list(filter(lambda x: x.external_id == model_unique_external_id, models))

cognite_client.post(
f"/api/v1/projects/{cognite_client.config.project}/simulators/models/delete",
json={"items": [{"id": model_seed[0].id}]}, # Post actual simulator models here
)


@pytest.fixture
def seed_simulator_model_revisions(cognite_client: CogniteClient, seed_simulator_models, seed_file) -> None:
cognite_client.post(
f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions",
json={"items": [{**simulator_model_revision, "fileId": seed_file.id}]}, # Post actual simulator models here
json={
"items": [{**simulator_model_revision, "fileId": seed_file.id, "modelExternalId": model_unique_external_id}]
}, # Post actual simulator models here
)


@pytest.fixture
def seed_simulator_routines(cognite_client: CogniteClient, seed_simulator_model_revisions) -> None:
cognite_client.post(
f"/api/v1/projects/{cognite_client.config.project}/simulators/routines",
json={"items": [simulator_routine]},
json={"items": [{**simulator_routine, "modelExternalId": model_unique_external_id}]},
)


Expand Down Expand Up @@ -172,28 +189,22 @@ def test_list_models(self, cognite_client: CogniteClient, seed_resource_names) -
assert len(models) > 0

def test_retrieve_model(self, cognite_client: CogniteClient, seed_resource_names) -> None:
model = cognite_client.simulators.models.retrieve(
external_id=seed_resource_names["simulator_model_external_id"]
)
model = cognite_client.simulators.models.retrieve(external_id=model_unique_external_id)
assert model is not None
assert model.external_id == seed_resource_names["simulator_model_external_id"]
assert model.external_id == model_unique_external_id

def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource_names) -> None:
revisions = cognite_client.simulators.models.list(
limit=5,
filter=SimulatorModelRevisionsFilter(
model_external_ids=[seed_resource_names["simulator_model_external_id"]]
),
filter=SimulatorModelRevisionsFilter(model_external_ids=[model_unique_external_id]),
)
assert len(revisions) > 0

def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resource_names) -> None:
# TODO : this test is incorrect, it should retrieve model revisions instead of model
model = cognite_client.simulators.models.retrieve(
external_id=seed_resource_names["simulator_model_external_id"]
)
model = cognite_client.simulators.models.retrieve(external_id=model_unique_external_id)
assert model is not None
assert model.external_id == seed_resource_names["simulator_model_external_id"]
assert model.external_id == model_unique_external_id


@pytest.mark.usefixtures("seed_resource_names", "seed_simulator_routine_revisions")
Expand Down

0 comments on commit 9fead1a

Please sign in to comment.