Skip to content

Commit

Permalink
Merge pull request #217 from ynput/test/entity-hub
Browse files Browse the repository at this point in the history
Tests: EntityHub updates
  • Loading branch information
iLLiCiTiT authored Nov 27, 2024
2 parents d373d20 + f654b52 commit 14eec9a
Show file tree
Hide file tree
Showing 5 changed files with 1,000 additions and 493 deletions.
22 changes: 12 additions & 10 deletions ayon_api/entity_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,14 +1775,6 @@ def lock(self):
def _get_entity_by_id(self, entity_id):
return self._entity_hub.get_entity_by_id(entity_id)

def get_name(self):
return self._name

def set_name(self, name):
self._name = name

name = property(get_name, set_name)

def get_parent_id(self):
"""Parent entity id.
Expand Down Expand Up @@ -1972,7 +1964,17 @@ def get_name(self):
)
return self._name

name = property(get_name)
def set_name(self, name):
if not self._supports_name:
raise NotImplementedError(
f"Name is not supported for '{self.entity_type}'."
)

if not isinstance(name, str):
raise TypeError("Name must be a string.")
self._name = name

name = property(get_name, set_name)

def get_label(self) -> Optional[str]:
if not self._supports_label:
Expand Down Expand Up @@ -3271,7 +3273,7 @@ class TaskEntity(BaseEntity):
name (str): Name of entity.
task_type (str): Type of task. Task type must be available in config
of project task types.
parent_id (Union[str, None]): Id of parent entity.
folder_id (Union[str, None]): Parent folder id.
label (Optional[str]): Task label.
status (Optional[str]): Task status.
tags (Optional[Iterable[str]]): Folder tags.
Expand Down
202 changes: 202 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from datetime import datetime, timedelta, timezone
import pytest

from ayon_api import (
get_project,
create_project,
update_project,
delete_project,
get_folders,
get_products,
get_tasks
)
from ayon_api.entity_hub import EntityHub


class _Cache:
Expand Down Expand Up @@ -60,3 +65,200 @@ def project_entity_fixture(project_name_fixture):
yield project_entity
if created:
delete_project(project_name_fixture)


@pytest.fixture
def clean_project(project_name_fixture):
hub = EntityHub(project_name_fixture)

for folder in get_folders(
project_name_fixture
):
# delete tasks
for task in get_tasks(
project_name_fixture,
folder_ids=[folder["id"]]
):
hub.delete_entity(hub.get_task_by_id(task["id"]))

# delete products
for product in list(get_products(
project_name_fixture, folder_ids=[folder["id"]]
)):
product_entity = hub.get_product_by_id(product["id"])
hub.delete_entity(product_entity)

entity = hub.get_folder_by_id(folder["id"])
hub.delete_entity(entity)

hub.commit_changes()


class TestEventFilters:
project_names = [
(None),
([]),
(["demo_Big_Episodic"]),
(["demo_Big_Feature"]),
(["demo_Commercial"]),
(["AY_Tests"]),
([
"demo_Big_Episodic",
"demo_Big_Feature",
"demo_Commercial",
"AY_Tests"
])
]

topics = [
(None),
([]),
(["entity.folder.attrib_changed"]),
(["entity.task.created", "entity.project.created"]),
(["settings.changed", "entity.version.status_changed"]),
(["entity.task.status_changed", "entity.folder.deleted"]),
([
"entity.project.changed",
"entity.task.tags_changed",
"entity.product.created"
])
]

users = [
(None),
([]),
(["admin"]),
(["mkolar", "tadeas.8964"]),
(["roy", "luke.inderwick", "ynbot"]),
([
"entity.folder.attrib_changed",
"entity.project.created",
"entity.task.created",
"settings.changed"
]),
]

# states is incorrect name for statuses
states = [
(None),
([]),
([
"pending",
"in_progress",
"finished",
"failed",
"aborted",
"restarted"
]),
(["failed", "aborted"]),
(["pending", "in_progress"]),
(["finished", "failed", "restarted"]),
(["finished"]),
]

include_logs = [
(None),
(True),
(False),
]

has_children = [
(None),
(True),
(False),
]

now = datetime.now(timezone.utc)

newer_than = [
(None),
((now - timedelta(days=2)).isoformat()),
((now - timedelta(days=5)).isoformat()),
((now - timedelta(days=10)).isoformat()),
((now - timedelta(days=20)).isoformat()),
((now - timedelta(days=30)).isoformat()),
]

older_than = [
(None),
((now - timedelta(days=0)).isoformat()),
((now - timedelta(days=5)).isoformat()),
((now - timedelta(days=10)).isoformat()),
((now - timedelta(days=20)).isoformat()),
((now - timedelta(days=30)).isoformat()),
]

fields = [
(None),
([]),
]


class TestInvalidEventFilters:
topics = [
(None),
(["invalid_topic_name_1", "invalid_topic_name_2"]),
(["invalid_topic_name_1"]),
]

project_names = [
(None),
(["invalid_project"]),
(["invalid_project", "demo_Big_Episodic", "demo_Big_Feature"]),
(["invalid_name_2", "demo_Commercial"]),
(["demo_Commercial"]),
]

states = [
(None),
(["pending_invalid"]),
(["in_progress_invalid"]),
(["finished_invalid", "failed_invalid"]),
]

users = [
(None),
(["ayon_invalid_user"]),
(["ayon_invalid_user1", "ayon_invalid_user2"]),
(["ayon_invalid_user1", "ayon_invalid_user2", "admin"]),
]

newer_than = [
(None),
((datetime.now(timezone.utc) + timedelta(days=2)).isoformat()),
((datetime.now(timezone.utc) + timedelta(days=5)).isoformat()),
((datetime.now(timezone.utc) - timedelta(days=5)).isoformat()),
]


class TestUpdateEventData:
update_sender = [
("test.server.api"),
]

update_username = [
("testing_user"),
]

update_status = [
("pending"),
("in_progress"),
("finished"),
("failed"),
("aborted"),
("restarted")
]

update_description = [
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
" Fusce vivera."
),
("Updated description test...")
]

update_retries = [
(1),
(0),
(10),
]
Loading

0 comments on commit 14eec9a

Please sign in to comment.