Skip to content

Commit

Permalink
don't fail at creating 1k events over-and-over...
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Oct 5, 2023
1 parent 042f5d0 commit 1ef99b6
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions tests/tests_integration/test_api/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import uuid

import pytest
Expand All @@ -11,11 +12,33 @@
TemplateInstance,
TemplateInstanceList,
)
from cognite.client.data_classes.events import Event
from cognite.client.data_classes.events import Event, EventList
from cognite.client.data_classes.templates import Source, TemplateInstanceUpdate, View, ViewResolveList, ViewResolver
from cognite.client.exceptions import CogniteNotFoundError


@pytest.fixture(scope="session")
def ensure_event_test_data(cognite_client):
events = EventList(
[
Event(
external_id=f"test_evt_templates_1_{i}",
type="test_templates_1",
start_time=i * 1000,
)
for i in range(1001)
]
)
try:
cognite_client.events.retrieve_multiple(
external_ids=events.as_external_ids(),
ignore_unknwown_ids=False,
)
except CogniteNotFoundError:
cognite_client.events.upsert(events)
time.sleep(3)


@pytest.fixture
def new_template_group(cognite_client):
external_id = uuid.uuid4().hex[:20]
Expand Down Expand Up @@ -75,22 +98,9 @@ def new_template_instance(cognite_client, new_template_group_version):
cognite_client.templates.instances.delete(ext_id, new_version.version, instance.external_id)


@pytest.fixture(scope="session")
@pytest.fixture
@pytest.mark.usefixtures("ensure_event_test_data")
def new_view(cognite_client, new_template_group_version):
events = [
Event(
external_id=f"test_evt_templates_1_{i}",
type="test_templates_1",
start_time=i * 1000,
)
for i in range(1001)
]
try:
cognite_client.events.create(events)
except Exception:
# We only generate this data once for a given project, to prevent issues with eventual consistency etc.
None

new_group, ext_id, new_version = new_template_group_version
view = View(
external_id="test",
Expand All @@ -115,7 +125,7 @@ def test_groups_get_single(self, cognite_client, new_template_group):
assert isinstance(res[0], TemplateGroup)
assert new_group.external_id == ext_id

def test_groups_retrieve_unknown(self, cognite_client, new_template_group):
def test_groups_retrieve_unknown(self, cognite_client):
with pytest.raises(CogniteNotFoundError):
cognite_client.templates.groups.retrieve_multiple(external_ids=["this does not exist"])
assert cognite_client.templates.groups.retrieve_multiple(external_ids="this does not exist") is None
Expand Down Expand Up @@ -224,16 +234,12 @@ def test_view_list(self, cognite_client, new_view):
def test_view_delete(self, cognite_client, new_view):
new_group, ext_id, new_version, view = new_view
cognite_client.templates.views.delete(ext_id, new_version.version, [view.external_id])
assert (
len(
[
res
for res in cognite_client.templates.views.list(ext_id, new_version.version)
if res.external_id == view.external_id
]
)
== 0
)
should_be_empty = [
res
for res in cognite_client.templates.views.list(ext_id, new_version.version)
if res.external_id == view.external_id
]
assert len(should_be_empty) == 0

def test_view_resolve(self, cognite_client, new_view):
new_group, ext_id, new_version, view = new_view
Expand Down

0 comments on commit 1ef99b6

Please sign in to comment.