diff --git a/client/ayon_core/plugins/publish/integrate_traits.py b/client/ayon_core/plugins/publish/integrate_traits.py index 2a35135b84..b607e527b2 100644 --- a/client/ayon_core/plugins/publish/integrate_traits.py +++ b/client/ayon_core/plugins/publish/integrate_traits.py @@ -51,8 +51,13 @@ class IntegrateTraits(pyblish.api.InstancePlugin): "Instance has no persistent representations. Skipping") return + # 3) get anatomy template name # template_name = self.get_template_name(instance) + # 4) initialize OperationsSession() + # for now we'll skip this step right now as there is some + # old representation style code that needs to be updated.z + @staticmethod def filter_lifecycle( representations: list[Representation]) -> list[Representation]: diff --git a/tests/client/ayon_core/plugins/publish/test_integrate_traits.py b/tests/client/ayon_core/plugins/publish/test_integrate_traits.py index 3874cc43d4..1262266943 100644 --- a/tests/client/ayon_core/plugins/publish/test_integrate_traits.py +++ b/tests/client/ayon_core/plugins/publish/test_integrate_traits.py @@ -2,26 +2,25 @@ from __future__ import annotations import base64 -from typing import TYPE_CHECKING +from pathlib import Path import pyblish.api import pytest from ayon_core.pipeline.traits import ( FileLocation, - GapPolicy, Image, + MimeType, Persistent, PixelBased, Representation, + Sequence, + Transient, ) # Tagged, # TemplatePath, from ayon_core.plugins.publish.integrate_traits import IntegrateTraits -from pipeline.traits import MimeType, Sequence - -if TYPE_CHECKING: - from pathlib import Path +from ayon_core.settings import get_project_settings PNG_FILE_B64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR4AWNgAAAAAgABc3UBGAAAAABJRU5ErkJggg==" # noqa: E501 SEQUENCE_LENGTH = 10 @@ -47,11 +46,48 @@ def sequence_files(tmp_path_factory: pytest.TempPathFactory) -> list[Path]: @pytest.fixture() def mock_context( + project: object, single_file: Path, sequence_files: list[Path]) -> pyblish.api.Context: - """Return a mock instance.""" + """Return a mock instance. + + This is mocking pyblish context for testing. It is using real AYON project + thanks to the ``project`` fixture. + + This returns following data:: + + project_name: str + project_code: str + project_root_folders: dict[str, str] + folder: IdNamePair + task: IdNamePair + product: IdNamePair + version: IdNamePair + representations: List[IdNamePair] + links: List[str] + + Args: + project (object): The project info. It is `ProjectInfo` object + returned by pytest fixture. + single_file (Path): The path to a single image file. + sequence_files (list[Path]): The paths to a sequence of image files. + + """ context = pyblish.api.Context() + context.data["projectName"] = project.project_name + context.data["hostName"] = "test_host" + context.data["project_settings"] = get_project_settings( + project.project_name) + instance = context.create_instance("mock_instance") + instance.data["anatomyData"] = { + "project": project.project_name, + "task": { + "name": project.task.name, + "type": "test" # pytest-ayon doesn't return the task type yet + } + } + instance.data["productType"] = "test_product" instance.data["integrate"] = True instance.data["farm"] = False @@ -71,12 +107,7 @@ def mock_context( frame_start=1, frame_end=SEQUENCE_LENGTH, frame_padding=4, - gaps_policy=GapPolicy.forbidden, frame_regex=r"^img\.(\d{4})\.png$", - step=1, - frame_start_handle=0, - frame_end_handle=0, - frame_list=None ), FileLocation( file_path=sequence_files[0], @@ -93,9 +124,41 @@ def mock_context( return context def test_get_template_name(mock_context: pyblish.api.Context) -> None: - """Test get_template_name.""" + """Test get_template_name. + + TODO (antirotor): this will always return "default" probably, if + there are no studio overrides. To test this properly, we need + to set up the studio overrides in the test environment. + + """ integrator = IntegrateTraits() template_name = integrator.get_template_name( - mock_context["mock_instance"]) + mock_context[0]) - assert template_name == "mock_instance" + assert template_name == "default" + +def test_filter_lifecycle() -> None: + """Test filter_lifecycle.""" + integrator = IntegrateTraits() + persistent_representation = Representation( + name="test", + traits=[ + Persistent(), + FileLocation( + file_path=Path("test"), + file_size=1234), + Image(), + MimeType(mime_type="image/png"), + ]) + transient_representation = Representation( + name="test", + traits=[ + Transient(), + Image(), + MimeType(mime_type="image/png"), + ]) + filtered = integrator.filter_lifecycle( + [persistent_representation, transient_representation]) + + assert len(filtered) == 1 + assert filtered[0] == persistent_representation