Skip to content

Commit f18b5ef

Browse files
committed
test: missing tests
1 parent eb6b9dd commit f18b5ef

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import uuid
2+
3+
import pytest
4+
5+
from kili.client import Kili
6+
7+
8+
@pytest.fixture()
9+
def project_id(kili: Kili):
10+
project_id = kili.create_project(
11+
input_type="TEXT", json_interface={"jobs": {}}, title="test_tags.py e2e admin SDK"
12+
)["id"]
13+
14+
yield project_id
15+
16+
kili.delete_project(project_id)
17+
18+
19+
def test_given_org_with_tags_when_i_update_tag_then_it_is_updated(kili: Kili):
20+
# Given
21+
org_tags = kili.tags(fields=("label",))
22+
assert len(org_tags) > 0, "Organization has no tags"
23+
tag_to_update = next(tag for tag in org_tags if tag["label"])
24+
prev_tag_name = tag_to_update["label"]
25+
26+
# When
27+
new_tag_name = str(uuid.uuid4())
28+
kili.update_tag(tag_name=prev_tag_name, new_tag_name=new_tag_name)
29+
30+
# Then
31+
org_tags = kili.tags(fields=("label",))
32+
assert len(org_tags) > 0, "Organization has no tags"
33+
assert new_tag_name in [tag["label"] for tag in org_tags]
34+
35+
# Cleanup
36+
kili.update_tag(tag_name=new_tag_name, new_tag_name=prev_tag_name)

tests/e2e/org_user/test_tags_org.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import pytest
2+
3+
from kili.client import Kili
4+
5+
6+
@pytest.fixture()
7+
def project_id(kili: Kili):
8+
project_id = kili.create_project(
9+
input_type="TEXT", json_interface={"jobs": {}}, title="test_tags.py e2e user SDK"
10+
)["id"]
11+
12+
yield project_id
13+
14+
kili.delete_project(project_id)
15+
16+
17+
def test_given_org_tags_when_i_tag_project_it_tags_it(kili: Kili, project_id: str):
18+
# Given
19+
org_tags = kili.tags(fields=("label",))
20+
assert len(org_tags) > 0, "Organization has no tags"
21+
tags_to_add_to_project = org_tags[:3]
22+
tags_to_add_to_project_label = [tag["label"] for tag in tags_to_add_to_project]
23+
24+
# When
25+
kili.tag_project(project_id, tags=tags_to_add_to_project_label)
26+
27+
# Then
28+
project_tags = kili.tags(project_id=project_id, fields=("label",))
29+
assert sorted([tag["label"] for tag in project_tags]) == sorted(tags_to_add_to_project_label)
30+
31+
32+
@pytest.fixture()
33+
def project_with_tags_id(project_id: str, kili: Kili):
34+
org_tags = kili.tags(fields=("label",))
35+
assert len(org_tags) > 0, "Organization has no tags"
36+
tag_to_add_to_project = org_tags[0]["label"]
37+
kili.tag_project(project_id, tags=(tag_to_add_to_project,))
38+
39+
return project_id
40+
41+
# kili.delete_project(project_id) # project is deleted in project_id fixture
42+
43+
44+
def test_given_project_with_tags_when_i_call_untag_project_then_it_removes_one_tag(
45+
kili: Kili, project_with_tags_id: str
46+
):
47+
# Given
48+
tags_of_project = kili.tags(project_id=project_with_tags_id, fields=("label",))
49+
assert len(tags_of_project) > 0, "Project has no tags"
50+
nb_tags_in_project_before = len(tags_of_project)
51+
tag_to_delete = tags_of_project[0]["label"]
52+
53+
# When
54+
kili.untag_project(project_with_tags_id, tags=(tag_to_delete,))
55+
56+
# Then
57+
project_tags = kili.tags(project_id=project_with_tags_id, fields=("label",))
58+
nb_tags_in_project_after = len(project_tags)
59+
assert nb_tags_in_project_after == nb_tags_in_project_before - 1
60+
assert not any(tag["label"] == tag_to_delete for tag in project_tags)

0 commit comments

Comments
 (0)