From ceea00f8232801afe180b1cc2a0f2e96885239c5 Mon Sep 17 00:00:00 2001 From: Florian LE GALL Date: Fri, 20 Dec 2024 11:11:05 +0100 Subject: [PATCH] feat(lab-3295): add tests project workflow --- .../project_workflow/operations.py | 2 +- .../project_workflow/operations_mixin.py | 16 +++++----- .../use_cases/project_workflow/__init__.py | 4 +-- .../presentation/test_project_workflow.py | 29 +++++++++++++++++ .../use_cases/test_project_workflow.py | 31 +++++++++++++++++++ 5 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 tests/integration/presentation/test_project_workflow.py create mode 100644 tests/integration/use_cases/test_project_workflow.py diff --git a/src/kili/adapters/kili_api_gateway/project_workflow/operations.py b/src/kili/adapters/kili_api_gateway/project_workflow/operations.py index 583ab46a7..babf8cfa9 100644 --- a/src/kili/adapters/kili_api_gateway/project_workflow/operations.py +++ b/src/kili/adapters/kili_api_gateway/project_workflow/operations.py @@ -1,7 +1,7 @@ """GraphQL Project Workflow operations.""" -def get_update_properties_in_project_workflow_mutation(fragment: str) -> str: +def get_update_project_workflow_mutation(fragment: str) -> str: """Return the GraphQL editProjectWorkflowSettings mutation.""" return f""" mutation editProjectWorkflowSettings($input: EditProjectWorkflowSettingsInput!) {{ diff --git a/src/kili/adapters/kili_api_gateway/project_workflow/operations_mixin.py b/src/kili/adapters/kili_api_gateway/project_workflow/operations_mixin.py index 6a9df1ddb..8c23e8503 100644 --- a/src/kili/adapters/kili_api_gateway/project_workflow/operations_mixin.py +++ b/src/kili/adapters/kili_api_gateway/project_workflow/operations_mixin.py @@ -10,7 +10,7 @@ from .mappers import project_input_mapper from .operations import ( - get_update_properties_in_project_workflow_mutation, + get_update_project_workflow_mutation, ) from .types import ProjectWorkflowDataKiliAPIGatewayInput @@ -18,20 +18,20 @@ class ProjectWorkflowOperationMixin(BaseOperationMixin): """Mixin extending Kili API Gateway class with Projects workflow related operations.""" - def update_properties_in_project_workflow( + def update_project_workflow( self, project_id: ProjectId, - project_data: ProjectWorkflowDataKiliAPIGatewayInput, + project_workflow_data: ProjectWorkflowDataKiliAPIGatewayInput, ) -> Dict: """Update properties in a project workflow.""" - project_workflow_data = project_input_mapper(data=project_data) + project_workflow_input = project_input_mapper(data=project_workflow_data) - fields = tuple(name for name, val in project_workflow_data.items() if val is not None) + fields = tuple(name for name, val in project_workflow_input.items() if val is not None) fragment = fragment_builder(fields) - mutation = get_update_properties_in_project_workflow_mutation(fragment) + mutation = get_update_project_workflow_mutation(fragment) - project_workflow_data["projectId"] = project_id + project_workflow_input["projectId"] = project_id - variables = {"input": project_workflow_data} + variables = {"input": project_workflow_input} result = self.graphql_client.execute(mutation, variables) return result["data"] diff --git a/src/kili/use_cases/project_workflow/__init__.py b/src/kili/use_cases/project_workflow/__init__.py index 17fcf8053..a628bda0a 100644 --- a/src/kili/use_cases/project_workflow/__init__.py +++ b/src/kili/use_cases/project_workflow/__init__.py @@ -22,6 +22,4 @@ def update_project_workflow( enforce_step_separation=enforce_step_separation, ) - return self._kili_api_gateway.update_properties_in_project_workflow( - project_id, project_workflow_data - ) + return self._kili_api_gateway.update_project_workflow(project_id, project_workflow_data) diff --git a/tests/integration/presentation/test_project_workflow.py b/tests/integration/presentation/test_project_workflow.py new file mode 100644 index 000000000..e3c181f71 --- /dev/null +++ b/tests/integration/presentation/test_project_workflow.py @@ -0,0 +1,29 @@ +import pytest_mock + +from kili.adapters.kili_api_gateway.kili_api_gateway import KiliAPIGateway +from kili.adapters.kili_api_gateway.project_workflow.operations import ( + get_update_project_workflow_mutation, +) +from kili.presentation.client.project_workflow import ProjectWorkflowClientMethods + + +def test_when_updating_project_workflow_then_it_returns_updated_project_workflow( + mocker: pytest_mock.MockerFixture, +): + kili = ProjectWorkflowClientMethods() + kili.kili_api_gateway = KiliAPIGateway( + graphql_client=mocker.MagicMock(), http_client=mocker.MagicMock() + ) + # Given + project_id = "fake_proj_id" + + # When + kili.update_project_workflow(project_id, enforce_step_separation=False) + + # Then + kili.kili_api_gateway.graphql_client.execute.assert_called_once_with( + get_update_project_workflow_mutation(" enforceStepSeparation"), + { + "input": {"projectId": "fake_proj_id", "enforceStepSeparation": False}, + }, + ) diff --git a/tests/integration/use_cases/test_project_workflow.py b/tests/integration/use_cases/test_project_workflow.py new file mode 100644 index 000000000..aa9ba0fec --- /dev/null +++ b/tests/integration/use_cases/test_project_workflow.py @@ -0,0 +1,31 @@ +from kili.adapters.kili_api_gateway.kili_api_gateway import KiliAPIGateway +from kili.adapters.kili_api_gateway.project_workflow.types import ( + ProjectWorkflowDataKiliAPIGatewayInput, +) +from kili.domain.project import ProjectId +from kili.use_cases.project_workflow import ProjectWorkflowUseCases + + +def test_given_a_project_workflow_when_update_it_then_it_updates_project_workflow_props( + kili_api_gateway: KiliAPIGateway, +): + # Given + def mocked_update_project_workflow( + project_id: ProjectId, + project_workflow_data: ProjectWorkflowDataKiliAPIGatewayInput, + ): + return { + "enforce_step_separation": project_workflow_data.enforce_step_separation, + "project_id": project_id, + } + + kili_api_gateway.update_project_workflow.side_effect = mocked_update_project_workflow + + # When + project = ProjectWorkflowUseCases(kili_api_gateway).update_project_workflow( + project_id=ProjectId("fake_proj_id"), + enforce_step_separation=False, + ) + + # Then + assert project == {"enforce_step_separation": False, "project_id": "fake_proj_id"}