Skip to content

Commit

Permalink
The largest test test_get_vents_all_filter_combinations moved to sepe…
Browse files Browse the repository at this point in the history
…rate file, new tests added, old tests edited
  • Loading branch information
tadeas-hejnic committed Nov 26, 2024
1 parent 8291ce2 commit 5552089
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 399 deletions.
188 changes: 188 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from datetime import datetime, timedelta, timezone
import pytest
from xml.dom.minidom import Entity

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 +66,185 @@ 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),
]
57 changes: 46 additions & 11 deletions tests/test_entity_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import uuid

from requests import delete
import test

import pytest

Expand Down Expand Up @@ -264,7 +265,7 @@ def test_custom_values_on_entities(project_entity_fixture):
hub.commit_changes()


def test_label_eq_name_on_entities(project_entity_fixture):
def test_label_eq_name_on_entities_1(project_entity_fixture):
"""Test label that have same values as name on folder and task.
When the entity has same name and label, the label should be set to None.
Expand Down Expand Up @@ -372,11 +373,11 @@ def test_data_changes_on_entities(project_entity_fixture):

hub = EntityHub(project_name)

folder = hub.get_or_query_entity_by_id(folder_id, {"folder"})
folder = hub.get_or_fetch_entity_by_id(folder_id, {"folder"})
folder.data["key3"] = "value3"
folder.data.pop("key1")

task = hub.get_or_query_entity_by_id(task_id, {"task"})
task = hub.get_or_fetch_entity_by_id(task_id, {"task"})
task.data["key4"] = "value4"
task.data.pop("key2")
hub.commit_changes()
Expand All @@ -397,7 +398,7 @@ def test_data_changes_on_entities(project_entity_fixture):
hub.commit_changes()


def test_label_eq_name_on_entities(project_entity_fixture):
def test_label_eq_name_on_entities_2(project_entity_fixture):
"""Test label that have same values as name on folder and task.
When the entity has same name and label, the label should be set to None.
Expand Down Expand Up @@ -430,8 +431,8 @@ def test_label_eq_name_on_entities(project_entity_fixture):
hub.commit_changes()

hub = EntityHub(project_name)
folder = hub.get_or_query_entity_by_id(folder_id, {"folder"})
task = hub.get_or_query_entity_by_id(task_id, {"task"})
folder = hub.get_or_fetch_entity_by_id(folder_id, {"folder"})
task = hub.get_or_fetch_entity_by_id(task_id, {"task"})

assert folder.status == init_status_name, (
"Folder status set on create was not propagated"
Expand Down Expand Up @@ -759,7 +760,7 @@ def test_create_delete_with_duplicated_names(

test_names = [
("test_name"),
# ("test_123"),
("test_123"),
]

test_product_types = [
Expand All @@ -769,6 +770,8 @@ def test_create_delete_with_duplicated_names(
("workfile"),
]


@pytest.mark.usefixtures("clean_project")
@pytest.mark.parametrize("folder_name", test_names)
@pytest.mark.parametrize("product_name", test_names)
@pytest.mark.parametrize("product_type", test_product_types)
Expand Down Expand Up @@ -833,6 +836,7 @@ def test_create_delete_products(
assert product.get_folder_id() == folder["id"]


@pytest.mark.usefixtures("clean_project")
@pytest.mark.parametrize("name", test_names)
def test_create_delete_folders(project_entity_fixture, name):
project_name = project_entity_fixture["name"]
Expand Down Expand Up @@ -893,10 +897,12 @@ def test_create_delete_folders(project_entity_fixture, name):


test_version_numbers = [
([1, 2, 3, 4])
([1, 2, 3, 4]),
([8, 10, 4, 5]),
]


@pytest.mark.usefixtures("clean_project")
@pytest.mark.parametrize("version_numbers", test_version_numbers)
def test_create_delete_versions(project_entity_fixture, version_numbers):
# prepare hierarchy
Expand Down Expand Up @@ -953,6 +959,7 @@ def test_create_delete_versions(project_entity_fixture, version_numbers):
]


@pytest.mark.usefixtures("clean_project")
@pytest.mark.parametrize("version_number", test_invalid_version_number)
def test_create_invalid_versions(project_entity_fixture, version_number):
# prepare hierarchy
Expand Down Expand Up @@ -983,6 +990,7 @@ def test_create_invalid_versions(project_entity_fixture, version_number):
hub.commit_changes()


@pytest.mark.usefixtures("clean_project")
def test_change_status_on_version(project_entity_fixture):
folder_types = [
type["name"] for type in project_entity_fixture["folderTypes"]
Expand Down Expand Up @@ -1020,6 +1028,7 @@ def test_change_status_on_version(project_entity_fixture):
assert version.get_status() == status_name


@pytest.mark.usefixtures("clean_project")
@pytest.mark.parametrize("version", test_version_numbers)
def test_set_invalid_status_on_version(project_entity_fixture, version):
folder_types = [
Expand Down Expand Up @@ -1087,6 +1096,7 @@ def test_set_invalid_status_on_version(project_entity_fixture, version):
]


@pytest.mark.usefixtures("clean_project")
@pytest.mark.parametrize("tags", test_tags)
def test_set_tag_on_version(project_entity_fixture, tags):
folder_types = [
Expand Down Expand Up @@ -1125,12 +1135,37 @@ def test_set_invalid_tag_on_version():
raise NotImplementedError()


def test_status_definition_on_project(project_entity_fixture):
test_statuses = [
("status1"),
("status2"),
("status3"),
]

test_icon = [
("arrow_forward"),
("expand_circle_down"),
("done_outline"),
]


@pytest.mark.parametrize("status_name", test_statuses)
@pytest.mark.parametrize("icon_name", test_icon)
def test_status_definition_on_project(
project_entity_fixture,
status_name,
icon_name
):
hub = EntityHub(project_entity_fixture["name"])

project = hub.project_entity
project.status = "test_status"
print(project.status)
project.get_statuses().create(
status_name,
icon_name
)
assert status_name == project.get_statuses().get(status_name).get_name()
assert icon_name == project.get_statuses().get(status_name).get_icon()

# print(project.status)

# project.set_status()
# project_status_obj = hub.project_entity.get_statuses()
Expand Down
Loading

0 comments on commit 5552089

Please sign in to comment.