Skip to content

Commit

Permalink
fix(LAB-2960): set inputType and jsonInterface as optional (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
FannyGaudin committed Jul 5, 2024
1 parent adca525 commit 00ee448
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/kili/presentation/client/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class ProjectClientMethods(BaseClientMethods):
# pylint: disable=too-many-arguments
def create_project(
self,
input_type: InputType,
json_interface: Dict,
title: str,
description: str = "",
input_type: Optional[InputType] = None,
json_interface: Optional[Dict] = None,
project_id: Optional[ProjectId] = None,
project_type: Optional[ProjectType] = None,
tags: Optional[ListOrTuple[str]] = None,
Expand Down
15 changes: 10 additions & 5 deletions src/kili/use_cases/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ class ProjectUseCases(BaseUseCases):
# pylint: disable=too-many-arguments
def create_project(
self,
input_type: InputType,
json_interface: Dict,
title: str,
description: str,
project_id: Optional[ProjectId],
project_type: Optional[ProjectType],
compliance_tags: Optional[ListOrTuple[ComplianceTag]],
project_id: Optional[ProjectId] = None,
input_type: Optional[InputType] = None,
json_interface: Optional[Dict] = None,
) -> ProjectId:
"""Create or copy a project if project_id is set."""
if project_id is not None:
project_copied = self._kili_api_gateway.get_project(
project_id=project_id, fields=["jsonInterface", "instructions"]
project_id=project_id, fields=["jsonInterface", "instructions", "inputType"]
)
project_tag = self._kili_api_gateway.list_tags_by_project(
project_id=project_id, fields=["id"]
)
new_project_id = self._kili_api_gateway.create_project(
input_type=input_type,
input_type=project_copied["inputType"],
json_interface=project_copied["jsonInterface"],
title=title,
description=description,
Expand All @@ -62,6 +62,11 @@ def create_project(
f"Tag {tag['id']} doesn't belong to your organization and was not copied."
)
self._kili_api_gateway.check_tag(project_id=new_project_id, tag_id=tag["id"])
elif input_type is None or json_interface is None:
raise ValueError(
"""Arguments `input_type` and `json_interface` must be set
if no `project_id` is providen."""
)
else:
new_project_id = self._kili_api_gateway.create_project(
input_type=input_type,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_query_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@pytest.fixture(scope="module")
def project_id(kili: Kili):
project = kili.create_project(
"TEXT",
input_type="TEXT",
json_interface={
"jobs": {
"CLASSIFICATION_JOB": {
Expand Down
27 changes: 23 additions & 4 deletions tests/integration/use_cases/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ def test_when_create_project_it_works(kili_api_gateway: KiliAPIGateway):
assert project_id == "fake_project_id"


def test_when_create_project_without_inputType_or_jsonInterface_it_throw_an_error(
kili_api_gateway: KiliAPIGateway,
):
kili_api_gateway.create_project.return_value = "fake_project_id"

# When
project_use_cases = ProjectUseCases(kili_api_gateway)

# Then
with pytest.raises(
ValueError,
match="Arguments `input_type` and `json_interface` must be set\n if no `project_id` is providen.",
):
project_use_cases.create_project(
title="test",
description="description",
project_type=None,
compliance_tags=None,
)


def test_when_create_project_with_project_id_it_works(kili_api_gateway: KiliAPIGateway):
# Given
tags = [
Expand All @@ -58,14 +79,13 @@ def test_when_create_project_with_project_id_it_works(kili_api_gateway: KiliAPIG
kili_api_gateway.get_project.return_value = {
"jsonInterface": interface,
"instructions": "fake_instructions",
"inputType": "TEXT",
}
kili_api_gateway.list_tags_by_project.return_value = tags
kili_api_gateway.list_tags_by_org.return_value = tags

# When
project_id = ProjectUseCases(kili_api_gateway).create_project(
input_type="TEXT",
json_interface=interface,
title="test",
description="description",
project_id=ProjectId("fake_project_id"),
Expand All @@ -91,6 +111,7 @@ def test_when_create_project_with_project_id_it_throw_an_error_if_tags_do_not_be
kili_api_gateway.get_project.return_value = {
"jsonInterface": interface,
"instructions": "fake_instructions",
"inputType": "TEXT",
}
kili_api_gateway.list_tags_by_project.return_value = tags
kili_api_gateway.list_tags_by_org.return_value = org_tags
Expand All @@ -102,8 +123,6 @@ def test_when_create_project_with_project_id_it_throw_an_error_if_tags_do_not_be
match="Tag tag1_id doesn't belong to your organization and was not copied.",
):
project_use_cases.create_project(
input_type="TEXT",
json_interface=interface,
title="test",
description="description",
project_id=ProjectId("fake_project_id"),
Expand Down

0 comments on commit 00ee448

Please sign in to comment.