Skip to content

Commit

Permalink
Tests: TimeSeries Subscriptions (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Oct 16, 2024
1 parent f9365ee commit 528ef1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"

Expand Down
15 changes: 8 additions & 7 deletions tests/tests_integration/test_api/test_datapoint_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 528ef1c

Please sign in to comment.