diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 5ca0a69b5..e3f18cde7 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -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, } diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index ca8370828..05074697c 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,3 +1,4 @@ +import random import time import pytest @@ -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, @@ -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]: @@ -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( @@ -89,7 +92,19 @@ 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 ) @@ -97,7 +112,9 @@ def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integrat 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 ) @@ -105,7 +122,7 @@ def seed_simulator_model_revisions(cognite_client: CogniteClient, seed_simulator 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}]}, ) @@ -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")