Skip to content

Commit 00ee448

Browse files
authored
fix(LAB-2960): set inputType and jsonInterface as optional (#1736)
1 parent adca525 commit 00ee448

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

src/kili/presentation/client/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class ProjectClientMethods(BaseClientMethods):
3737
# pylint: disable=too-many-arguments
3838
def create_project(
3939
self,
40-
input_type: InputType,
41-
json_interface: Dict,
4240
title: str,
4341
description: str = "",
42+
input_type: Optional[InputType] = None,
43+
json_interface: Optional[Dict] = None,
4444
project_id: Optional[ProjectId] = None,
4545
project_type: Optional[ProjectType] = None,
4646
tags: Optional[ListOrTuple[str]] = None,

src/kili/use_cases/project/project.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ class ProjectUseCases(BaseUseCases):
2424
# pylint: disable=too-many-arguments
2525
def create_project(
2626
self,
27-
input_type: InputType,
28-
json_interface: Dict,
2927
title: str,
3028
description: str,
31-
project_id: Optional[ProjectId],
3229
project_type: Optional[ProjectType],
3330
compliance_tags: Optional[ListOrTuple[ComplianceTag]],
31+
project_id: Optional[ProjectId] = None,
32+
input_type: Optional[InputType] = None,
33+
json_interface: Optional[Dict] = None,
3434
) -> ProjectId:
3535
"""Create or copy a project if project_id is set."""
3636
if project_id is not None:
3737
project_copied = self._kili_api_gateway.get_project(
38-
project_id=project_id, fields=["jsonInterface", "instructions"]
38+
project_id=project_id, fields=["jsonInterface", "instructions", "inputType"]
3939
)
4040
project_tag = self._kili_api_gateway.list_tags_by_project(
4141
project_id=project_id, fields=["id"]
4242
)
4343
new_project_id = self._kili_api_gateway.create_project(
44-
input_type=input_type,
44+
input_type=project_copied["inputType"],
4545
json_interface=project_copied["jsonInterface"],
4646
title=title,
4747
description=description,
@@ -62,6 +62,11 @@ def create_project(
6262
f"Tag {tag['id']} doesn't belong to your organization and was not copied."
6363
)
6464
self._kili_api_gateway.check_tag(project_id=new_project_id, tag_id=tag["id"])
65+
elif input_type is None or json_interface is None:
66+
raise ValueError(
67+
"""Arguments `input_type` and `json_interface` must be set
68+
if no `project_id` is providen."""
69+
)
6570
else:
6671
new_project_id = self._kili_api_gateway.create_project(
6772
input_type=input_type,

tests/e2e/test_query_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@pytest.fixture(scope="module")
1010
def project_id(kili: Kili):
1111
project = kili.create_project(
12-
"TEXT",
12+
input_type="TEXT",
1313
json_interface={
1414
"jobs": {
1515
"CLASSIFICATION_JOB": {

tests/integration/use_cases/test_project.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ def test_when_create_project_it_works(kili_api_gateway: KiliAPIGateway):
4848
assert project_id == "fake_project_id"
4949

5050

51+
def test_when_create_project_without_inputType_or_jsonInterface_it_throw_an_error(
52+
kili_api_gateway: KiliAPIGateway,
53+
):
54+
kili_api_gateway.create_project.return_value = "fake_project_id"
55+
56+
# When
57+
project_use_cases = ProjectUseCases(kili_api_gateway)
58+
59+
# Then
60+
with pytest.raises(
61+
ValueError,
62+
match="Arguments `input_type` and `json_interface` must be set\n if no `project_id` is providen.",
63+
):
64+
project_use_cases.create_project(
65+
title="test",
66+
description="description",
67+
project_type=None,
68+
compliance_tags=None,
69+
)
70+
71+
5172
def test_when_create_project_with_project_id_it_works(kili_api_gateway: KiliAPIGateway):
5273
# Given
5374
tags = [
@@ -58,14 +79,13 @@ def test_when_create_project_with_project_id_it_works(kili_api_gateway: KiliAPIG
5879
kili_api_gateway.get_project.return_value = {
5980
"jsonInterface": interface,
6081
"instructions": "fake_instructions",
82+
"inputType": "TEXT",
6183
}
6284
kili_api_gateway.list_tags_by_project.return_value = tags
6385
kili_api_gateway.list_tags_by_org.return_value = tags
6486

6587
# When
6688
project_id = ProjectUseCases(kili_api_gateway).create_project(
67-
input_type="TEXT",
68-
json_interface=interface,
6989
title="test",
7090
description="description",
7191
project_id=ProjectId("fake_project_id"),
@@ -91,6 +111,7 @@ def test_when_create_project_with_project_id_it_throw_an_error_if_tags_do_not_be
91111
kili_api_gateway.get_project.return_value = {
92112
"jsonInterface": interface,
93113
"instructions": "fake_instructions",
114+
"inputType": "TEXT",
94115
}
95116
kili_api_gateway.list_tags_by_project.return_value = tags
96117
kili_api_gateway.list_tags_by_org.return_value = org_tags
@@ -102,8 +123,6 @@ def test_when_create_project_with_project_id_it_throw_an_error_if_tags_do_not_be
102123
match="Tag tag1_id doesn't belong to your organization and was not copied.",
103124
):
104125
project_use_cases.create_project(
105-
input_type="TEXT",
106-
json_interface=interface,
107126
title="test",
108127
description="description",
109128
project_id=ProjectId("fake_project_id"),

0 commit comments

Comments
 (0)