From 6f3cad492201c589038ebcbd9fa13b1f74e55de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20V=2E=20Treider?= Date: Wed, 18 Sep 2024 11:30:36 +0200 Subject: [PATCH] Turn on alpha tests (#1937) --- tests/tests_integration/conftest.py | 1 + .../test_data_modeling/test_core_model.py | 21 ++++++++------- .../test_api/test_datapoints.py | 22 +++++++--------- .../tests_integration/test_api/test_files.py | 26 ++++++++----------- .../test_api/test_time_series.py | 14 +++++----- 5 files changed, 40 insertions(+), 44 deletions(-) diff --git a/tests/tests_integration/conftest.py b/tests/tests_integration/conftest.py index 1d7bb5eb0b..1477622f33 100644 --- a/tests/tests_integration/conftest.py +++ b/tests/tests_integration/conftest.py @@ -21,6 +21,7 @@ def cognite_client() -> CogniteClient: def cognite_client_alpha() -> CogniteClient: load_dotenv(REPO_ROOT / "alpha.env") if "COGNITE_ALPHA_PROJECT" not in os.environ: + # TODO: If we are in CI, we should fail the test instead of skipping pytest.skip("ALPHA environment variables not set. Skipping ALPHA tests.") return CogniteClient.default_oauth_client_credentials( project=os.environ["COGNITE_ALPHA_PROJECT"], diff --git a/tests/tests_integration/test_api/test_data_modeling/test_core_model.py b/tests/tests_integration/test_api/test_data_modeling/test_core_model.py index 83f2014a5a..a1ee2d92e9 100644 --- a/tests/tests_integration/test_api/test_data_modeling/test_core_model.py +++ b/tests/tests_integration/test_api/test_data_modeling/test_core_model.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections.abc import Iterable -from datetime import datetime +from datetime import datetime, timedelta import pytest from _pytest.mark import ParameterSet @@ -22,7 +22,7 @@ def core_model_v1_node_test_cases() -> Iterable[ParameterSet]: today = datetime.now() - yesterday = today.replace(day=today.day - 1) + yesterday = today - timedelta(days=1) yield pytest.param( cdm.CogniteAssetApply( space=DATA_SPACE, @@ -108,6 +108,7 @@ def core_model_v1_node_test_cases() -> Iterable[ParameterSet]: name="Test model 3D", description="Test model 3D for core model v1 tests with Python SDK", aliases=["test_model_3d_alias"], + model_type="PointCloud", # TODO: Should be nullable, returns as 400 if not set ), cdm.Cognite3DModel, id="CogniteModel3D", @@ -201,8 +202,8 @@ def core_model_v1_edge_test_cases() -> Iterable[ParameterSet]: @pytest.fixture(scope="session") -def data_space(cognite_client_alpha: CogniteClient) -> Space: - space = cognite_client_alpha.data_modeling.spaces.apply( +def data_space(cognite_client: CogniteClient) -> Space: + space = cognite_client.data_modeling.spaces.apply( SpaceApply(space=DATA_SPACE, description="Test space for core model v1 tests with Python SDK", name=DATA_SPACE) ) return space @@ -212,14 +213,14 @@ class TestCoreModelv1: @pytest.mark.usefixtures("data_space") @pytest.mark.parametrize("write_instance, read_type", list(core_model_v1_node_test_cases())) def test_write_read_node( - self, write_instance: TypedNodeApply, read_type: type[TypedNode], cognite_client_alpha: CogniteClient + self, write_instance: TypedNodeApply, read_type: type[TypedNode], cognite_client: CogniteClient ) -> None: - created = cognite_client_alpha.data_modeling.instances.apply(write_instance) + created = cognite_client.data_modeling.instances.apply(write_instance) assert len(created.nodes) == 1 assert created.nodes[0].as_id() == write_instance.as_id() - read = cognite_client_alpha.data_modeling.instances.retrieve_nodes(write_instance.as_id(), node_cls=read_type) + read = cognite_client.data_modeling.instances.retrieve_nodes(write_instance.as_id(), node_cls=read_type) assert isinstance(read, read_type) assert read.as_id() == write_instance.as_id() @@ -239,16 +240,16 @@ def test_write_read_node( @pytest.mark.usefixtures("data_space") @pytest.mark.parametrize("write_instance, read_type", list(core_model_v1_edge_test_cases())) def test_write_read_edge( - self, write_instance: TypedEdgeApply, read_type: type[TypedEdge], cognite_client_alpha: CogniteClient + self, write_instance: TypedEdgeApply, read_type: type[TypedEdge], cognite_client: CogniteClient ) -> None: - created = cognite_client_alpha.data_modeling.instances.apply( + created = cognite_client.data_modeling.instances.apply( edges=write_instance, auto_create_start_nodes=True, auto_create_end_nodes=True ) assert len(created.edges) == 1 assert created.edges[0].as_id() == write_instance.as_id() - read = cognite_client_alpha.data_modeling.instances.retrieve_edges(write_instance.as_id(), edge_cls=read_type) + read = cognite_client.data_modeling.instances.retrieve_edges(write_instance.as_id(), edge_cls=read_type) assert isinstance(read, read_type) assert read.as_id() == write_instance.as_id() diff --git a/tests/tests_integration/test_api/test_datapoints.py b/tests/tests_integration/test_api/test_datapoints.py index ebf0baa1fa..42aa40b690 100644 --- a/tests/tests_integration/test_api/test_datapoints.py +++ b/tests/tests_integration/test_api/test_datapoints.py @@ -184,7 +184,7 @@ def all_retrieve_endpoints(cognite_client, retrieve_endpoints): @pytest.fixture(scope="session") -def instance_ts_id(cognite_client_alpha: CogniteClient, alpha_test_space: Space) -> InstanceId: +def instance_ts_id(cognite_client: CogniteClient, alpha_test_space: Space) -> InstanceId: my_ts = NodeApply( space=alpha_test_space.space, external_id="ts_python_sdk_instance_id_tests", @@ -199,7 +199,7 @@ def instance_ts_id(cognite_client_alpha: CogniteClient, alpha_test_space: Space) ) ], ) - created_ts = cognite_client_alpha.data_modeling.instances.apply(my_ts).nodes + created_ts = cognite_client.data_modeling.instances.apply(my_ts).nodes return created_ts[0].as_id() @@ -2764,29 +2764,27 @@ def test_dict_format_with_status_codes_using_insert_multiple(self, cognite_clien assert set(dps_numeric.status_symbol) == {"Good", "Uncertain", "Bad"} def test_insert_retrieve_delete_datapoints_with_instance_id( - self, cognite_client_alpha: CogniteClient, instance_ts_id: InstanceId + self, cognite_client: CogniteClient, instance_ts_id: InstanceId ) -> None: - cognite_client_alpha.time_series.data.insert([(0, 0.0), (1.0, 1.0)], instance_id=instance_ts_id) + cognite_client.time_series.data.insert([(0, 0.0), (1.0, 1.0)], instance_id=instance_ts_id) - retrieved = cognite_client_alpha.time_series.data.retrieve(instance_id=instance_ts_id, start=0, end=2) + retrieved = cognite_client.time_series.data.retrieve(instance_id=instance_ts_id, start=0, end=2) assert retrieved.timestamp == [0, 1] assert retrieved.value == [0.0, 1.0] - cognite_client_alpha.time_series.data.delete_range(0, 2, instance_id=instance_ts_id) + cognite_client.time_series.data.delete_range(0, 2, instance_id=instance_ts_id) - retrieved = cognite_client_alpha.time_series.data.retrieve(instance_id=instance_ts_id, start=0, end=2) + retrieved = cognite_client.time_series.data.retrieve(instance_id=instance_ts_id, start=0, end=2) assert retrieved.timestamp == [] - def test_insert_multiple_with_instance_id( - self, cognite_client_alpha: CogniteClient, instance_ts_id: InstanceId - ) -> None: - cognite_client_alpha.time_series.data.insert_multiple( + def test_insert_multiple_with_instance_id(self, cognite_client: CogniteClient, instance_ts_id: InstanceId) -> None: + cognite_client.time_series.data.insert_multiple( [{"instance_id": instance_ts_id, "datapoints": [{"timestamp": 4, "value": 42}]}] ) - retrieved = cognite_client_alpha.time_series.data.retrieve(instance_id=instance_ts_id, start=3, end=5) + retrieved = cognite_client.time_series.data.retrieve(instance_id=instance_ts_id, start=3, end=5) assert retrieved.timestamp == [4] assert retrieved.value == [42] diff --git a/tests/tests_integration/test_api/test_files.py b/tests/tests_integration/test_api/test_files.py index 7ac93c2b41..40f3287213 100644 --- a/tests/tests_integration/test_api/test_files.py +++ b/tests/tests_integration/test_api/test_files.py @@ -251,7 +251,7 @@ def test_upload_multipart(self, cognite_client: CogniteClient) -> None: cognite_client.files.delete(session.file_metadata.id) def test_create_retrieve_update_delete_with_instance_id( - self, cognite_client_alpha: CogniteClient, alpha_test_space: Space + self, cognite_client: CogniteClient, alpha_test_space: Space ) -> None: file = CogniteFileApply( space=alpha_test_space.space, @@ -264,47 +264,43 @@ def test_create_retrieve_update_delete_with_instance_id( ) instance_id = file.as_id() try: - created = cognite_client_alpha.data_modeling.instances.apply(file) + created = cognite_client.data_modeling.instances.apply(file) assert len(created.nodes) == 1 assert created.nodes[0].as_id() == instance_id - f1 = cognite_client_alpha.files.upload_content_bytes(b"f1", instance_id=instance_id) + f1 = cognite_client.files.upload_content_bytes(b"f1", instance_id=instance_id) time.sleep(0.5) - download_links = cognite_client_alpha.files.retrieve_download_urls(instance_id=instance_id) + download_links = cognite_client.files.retrieve_download_urls(instance_id=instance_id) assert len(download_links.values()) == 1 assert download_links[f1.instance_id].startswith("http") content_1 = "abcde" * 1_200_000 content_2 = "fghij" - with cognite_client_alpha.files.multipart_upload_content_session( - parts=2, instance_id=instance_id - ) as session: + with cognite_client.files.multipart_upload_content_session(parts=2, instance_id=instance_id) as session: session.upload_part(0, content_1) session.upload_part(1, content_2) - retrieved_content = cognite_client_alpha.files.download_bytes(instance_id=instance_id) + retrieved_content = cognite_client.files.download_bytes(instance_id=instance_id) assert len(retrieved_content) == 6000005 - retrieved = cognite_client_alpha.files.retrieve(instance_id=instance_id) + retrieved = cognite_client.files.retrieve(instance_id=instance_id) assert retrieved is not None assert retrieved.instance_id == instance_id update_writable = retrieved.as_write() update_writable.metadata = {"a": "b"} update_writable.external_id = "file_python_sdk_instance_id_tests_updated" - updated_writable = cognite_client_alpha.files.update(update_writable) + updated_writable = cognite_client.files.update(update_writable) assert updated_writable.metadata == {"a": "b"} assert updated_writable.external_id == "file_python_sdk_instance_id_tests_updated" - updated = cognite_client_alpha.files.update( - FileMetadataUpdate(instance_id=instance_id).metadata.add({"c": "d"}) - ) + updated = cognite_client.files.update(FileMetadataUpdate(instance_id=instance_id).metadata.add({"c": "d"})) assert updated.metadata == {"a": "b", "c": "d"} - retrieved = cognite_client_alpha.files.retrieve_multiple(instance_ids=[instance_id]) + retrieved = cognite_client.files.retrieve_multiple(instance_ids=[instance_id]) assert retrieved.dump() == [updated.dump()] finally: - cognite_client_alpha.data_modeling.instances.delete(nodes=instance_id) + cognite_client.data_modeling.instances.delete(nodes=instance_id) def test_create_delete_ignore_unknown_ids(self, cognite_client: CogniteClient) -> None: file_metadata = FileMetadata(name="mytestfile") diff --git a/tests/tests_integration/test_api/test_time_series.py b/tests/tests_integration/test_api/test_time_series.py index 52c990760f..8239a2a569 100644 --- a/tests/tests_integration/test_api/test_time_series.py +++ b/tests/tests_integration/test_api/test_time_series.py @@ -277,7 +277,7 @@ def test_aggregate_unique_metadata_keys( } def test_create_retrieve_update_delete_with_instance_id( - self, cognite_client_alpha: CogniteClient, alpha_test_space: Space, alpha_test_dataset: DataSet + self, cognite_client: CogniteClient, alpha_test_space: Space, alpha_test_dataset: DataSet ) -> None: my_ts = CogniteTimeSeriesApply( space=alpha_test_space.space, @@ -291,11 +291,11 @@ def test_create_retrieve_update_delete_with_instance_id( update = TimeSeriesUpdate(instance_id=my_ts.as_id()).metadata.add({"a": "b"}) try: - created = cognite_client_alpha.data_modeling.instances.apply(my_ts) + created = cognite_client.data_modeling.instances.apply(my_ts) assert len(created.nodes) == 1 assert created.nodes[0].as_id() == my_ts.as_id() - retrieved = cognite_client_alpha.time_series.retrieve(instance_id=my_ts.as_id()) + retrieved = cognite_client.time_series.retrieve(instance_id=my_ts.as_id()) assert retrieved is not None assert retrieved.instance_id == my_ts.as_id() @@ -303,18 +303,18 @@ def test_create_retrieve_update_delete_with_instance_id( update_writable.metadata = {"c": "d"} update_writable.external_id = "ts_python_sdk_instance_id_tests" update_writable.data_set_id = alpha_test_dataset.id - updated_writable = cognite_client_alpha.time_series.update(update_writable) + updated_writable = cognite_client.time_series.update(update_writable) assert updated_writable.metadata == {"c": "d"} assert updated_writable.data_set_id == alpha_test_dataset.id assert updated_writable.external_id == "ts_python_sdk_instance_id_tests" - updated = cognite_client_alpha.time_series.update(update) + updated = cognite_client.time_series.update(update) assert updated.metadata == {"a": "b", "c": "d"} - retrieved = cognite_client_alpha.time_series.retrieve_multiple(instance_ids=[my_ts.as_id()]) + retrieved = cognite_client.time_series.retrieve_multiple(instance_ids=[my_ts.as_id()]) assert retrieved.dump() == [updated.dump()] finally: - cognite_client_alpha.data_modeling.instances.delete(nodes=my_ts.as_id()) + cognite_client.data_modeling.instances.delete(nodes=my_ts.as_id()) class TestTimeSeriesHelperMethods: