Skip to content

Commit 62bda41

Browse files
authored
Merge pull request #223 from ynput/test/entity-hub
Tests: Following Entity hub tests
2 parents d23a6bd + 2cd81c6 commit 62bda41

File tree

4 files changed

+340
-164
lines changed

4 files changed

+340
-164
lines changed

tests/conftest.py

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
create_project,
77
update_project,
88
delete_project,
9+
get_events,
910
get_folders,
1011
get_products,
1112
get_tasks
@@ -70,33 +71,76 @@ def project_entity_fixture(project_name_fixture):
7071
@pytest.fixture
7172
def clean_project(project_name_fixture):
7273
hub = EntityHub(project_name_fixture)
73-
74-
for folder in get_folders(
75-
project_name_fixture
76-
):
77-
# delete tasks
74+
hub.fetch_hierarchy_entities()
75+
76+
folder_ids = {
77+
folder["id"]
78+
for folder in get_folders(project_name_fixture, fields={"id"})
79+
}
80+
task_ids = {
81+
task["id"]
7882
for task in get_tasks(
79-
project_name_fixture,
80-
folder_ids=[folder["id"]]
81-
):
82-
hub.delete_entity(hub.get_task_by_id(task["id"]))
83+
project_name_fixture, folder_ids=folder_ids, fields={"id"}
84+
)
85+
}
86+
product_ids = {
87+
product["id"]
88+
for product in get_products(
89+
project_name_fixture, folder_ids=folder_ids, fields={"id"}
90+
)
91+
}
92+
for product_id in product_ids:
93+
product = hub.get_product_by_id(product_id)
94+
if product is not None:
95+
hub.delete_entity(product)
96+
97+
for task_id in task_ids:
98+
task = hub.get_task_by_id(task_id)
99+
if task is not None:
100+
hub.delete_entity(task)
101+
102+
hub.commit_changes()
83103

84-
# delete products
85-
for product in list(get_products(
86-
project_name_fixture, folder_ids=[folder["id"]]
87-
)):
88-
product_entity = hub.get_product_by_id(product["id"])
89-
hub.delete_entity(product_entity)
104+
for folder_id in folder_ids:
105+
folder = hub.get_folder_by_id(folder_id)
106+
if folder is not None:
107+
hub.delete_entity(folder)
90108

91-
entity = hub.get_folder_by_id(folder["id"])
92-
hub.delete_entity(entity)
109+
hub.commit_changes()
93110

94-
hub.commit_changes()
111+
112+
@pytest.fixture(params=[3, 4, 5])
113+
def event_ids(request):
114+
length = request.param
115+
if length == 0:
116+
return None
117+
118+
recent_events = list(get_events(
119+
newer_than=(datetime.now(timezone.utc) - timedelta(days=5)).isoformat()
120+
))
121+
122+
return [recent_event["id"] for recent_event in recent_events[:length]]
123+
124+
125+
@pytest.fixture
126+
def event_id():
127+
"""Fixture that retrieves the ID of a recent event created within
128+
the last 5 days.
129+
130+
Returns:
131+
- The event ID of the most recent event within the last 5 days
132+
if available.
133+
- `None` if no recent events are found within this time frame.
134+
135+
"""
136+
recent_events = list(get_events(
137+
newer_than=(datetime.now(timezone.utc) - timedelta(days=5)).isoformat()
138+
))
139+
return recent_events[0]["id"] if recent_events else None
95140

96141

97142
class TestEventFilters:
98143
project_names = [
99-
(None),
100144
([]),
101145
(["demo_Big_Episodic"]),
102146
(["demo_Big_Feature"]),
@@ -111,7 +155,6 @@ class TestEventFilters:
111155
]
112156

113157
topics = [
114-
(None),
115158
([]),
116159
(["entity.folder.attrib_changed"]),
117160
(["entity.task.created", "entity.project.created"]),
@@ -262,3 +305,17 @@ class TestUpdateEventData:
262305
(0),
263306
(10),
264307
]
308+
309+
310+
class TestProductData:
311+
names = [
312+
("test_name"),
313+
("test_123"),
314+
]
315+
316+
product_types = [
317+
("animation"),
318+
("camera"),
319+
("render"),
320+
("workfile"),
321+
]

0 commit comments

Comments
 (0)