From 528ef1c92298be8d12625189751ea96c9eba6f0d Mon Sep 17 00:00:00 2001 From: Anders Albert <60234212+doctrino@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:22:11 +0200 Subject: [PATCH] Tests: TimeSeries Subscriptions (#1980) --- tests/conftest.py | 2 +- .../test_api/test_datapoint_subscriptions.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index af9678e6e..07a4f8cf3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,7 +26,7 @@ def disable_gzip(): @pytest.fixture(scope="session") -def os_and_py_version(): +def os_and_py_version() -> str: # Nice to use to create resources that is unique to each test runner return f"{platform.system()}-{platform.python_version()}" diff --git a/tests/tests_integration/test_api/test_datapoint_subscriptions.py b/tests/tests_integration/test_api/test_datapoint_subscriptions.py index c1bc7736f..12fd93324 100644 --- a/tests/tests_integration/test_api/test_datapoint_subscriptions.py +++ b/tests/tests_integration/test_api/test_datapoint_subscriptions.py @@ -20,8 +20,6 @@ ) from cognite.client.utils._text import random_string -TIMESERIES_EXTERNAL_IDS = [f"PYSDK DataPoint Subscription Test {no}" for no in range(20)] - @contextmanager def create_subscription_with_cleanup( @@ -36,18 +34,20 @@ def create_subscription_with_cleanup( @pytest.fixture(scope="session") -def all_time_series_external_ids(cognite_client: CogniteClient) -> list[str]: +def all_time_series_external_ids(cognite_client: CogniteClient, os_and_py_version: str) -> list[str]: + timeseries_external_ids = [f"PYSDK DataPoint Subscription {os_and_py_version} Test {no}" for no in range(20)] + existing_xids = cognite_client.time_series.retrieve_multiple( - external_ids=TIMESERIES_EXTERNAL_IDS, ignore_unknown_ids=True + external_ids=timeseries_external_ids, ignore_unknown_ids=True ).as_external_ids() - if existing_xids == TIMESERIES_EXTERNAL_IDS: + if existing_xids == timeseries_external_ids: return existing_xids return cognite_client.time_series.upsert( [ TimeSeries(external_id=external_id, name=external_id, is_string=False) - for external_id in TIMESERIES_EXTERNAL_IDS + for external_id in timeseries_external_ids ], mode="replace", ).as_external_ids() @@ -261,10 +261,11 @@ def test_iterate_data_subscription_datapoints_added( assert batch.subscription_changes.added[0].external_id == time_series_external_ids[0] existing_data = cognite_client.time_series.data.retrieve_dataframe(external_id=time_series_external_ids[0]) + start = pd.Timestamp("now") if existing_data.empty else existing_data.index[-1] + pd.Timedelta("1d") new_values = [42, 43] new_data = pd.DataFrame( {time_series_external_ids[0]: new_values}, - index=pd.date_range(start=existing_data.index[-1] + pd.Timedelta("1d"), periods=2, freq="1d"), + index=pd.date_range(start=start, periods=2, freq="1d"), ) new_timestamps = new_data.index.asi8 // 10**6 try: