Skip to content

Commit

Permalink
feat(lab-3295): add tests project workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
florianlega committed Dec 20, 2024
1 parent 369bf00 commit c07d150
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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!) {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@

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


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"]
4 changes: 1 addition & 3 deletions src/kili/use_cases/project_workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
29 changes: 29 additions & 0 deletions tests/integration/presentation/test_project_workflow.py
Original file line number Diff line number Diff line change
@@ -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},
},
)
32 changes: 32 additions & 0 deletions tests/integration/use_cases/test_project_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 "id" in project
assert project == {"enforce_step_separation": False, "project_id": "fake_proj_id"}

0 comments on commit c07d150

Please sign in to comment.