Skip to content

Commit

Permalink
test: add e2e tests for primitives (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas1312 authored Oct 5, 2023
1 parent aedcd0d commit ece2d63
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/scripts/upload_test_stats_datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,24 @@
"tests/e2e/test_notebooks.py::test_all_recipes[tests/e2e/import_predictions.ipynb]": (
"import_predictions_ipynb"
),
"tests/e2e/test_notebooks.py::test_all_recipes[recipes/export_a_kili_project.ipynb]": (
"export_a_kili_project_ipynb"
),
"tests/e2e/test_notebooks.py::test_all_recipes[recipes/importing_video_assets.ipynb]": (
"importing_video_assets_ipynb"
),
"tests/e2e/test_copy_project.py::test_copy_project_e2e_video": "copy_project_e2e_video",
"tests/e2e/test_copy_project.py::test_copy_project_e2e_with_ocr_metadata": (
"copy_project_e2e_with_ocr_metadata"
),
"tests/e2e/test_projects.py::test_create_project": "create_project",
"tests/e2e/test_mutations_label.py::test_append_many_labels": "append_many_labels",
"tests/e2e/test_mutations_asset.py::test_append_many_assets": "append_many_assets",
"tests/e2e/test_mutations_asset.py::test_send_back_to_queue": "send_back_to_queue",
"tests/e2e/test_mutations_asset.py::test_delete_many_from_dataset": "delete_many_from_dataset",
"tests/e2e/test_mutations_asset.py::test_change_asset_external_ids": (
"change_asset_external_ids"
),
}

OWNER = "kili-technology"
Expand Down
46 changes: 46 additions & 0 deletions tests/e2e/test_mutations_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,49 @@ def test_update_properties_in_assets_external_id(kili, src_project):

assert [asset["externalId"] for asset in assets_new] == ["1", "2", "3"]
assert [asset["priority"] for asset in assets_new] == [1, 0, 0]


@pytest.fixture()
def src_project_no_assets(kili: Kili):
interface = {
"jobs": {
"DETECTION": {
"mlTask": "OBJECT_DETECTION",
"tools": ["rectangle"],
"instruction": "Is there a defect ? Where ? What kind ?",
"required": 0,
"isChild": False,
"content": {
"categories": {
"DEFECT_CLASS_1": {"name": "defect of class 1"},
"DEFECT_CLASS_2": {"name": "defect of class 2"},
"DEFECT_CLASS_3": {"name": "defect of class 3"},
"DEFECT_CLASS_4": {"name": "defect of class 4"},
},
"input": "radio",
},
}
}
}

project = kili.create_project(
input_type="IMAGE",
json_interface=interface,
title="e2e test_add_many_assets",
)

yield project["id"]

kili.delete_project(project["id"])


def test_append_many_assets(kili: Kili, src_project_no_assets: str):
NB_ASSETS = 500
img_url = "https://storage.googleapis.com/label-public-staging/car/car_1.jpg"

kili.append_many_to_dataset(
project_id=src_project_no_assets,
content_array=[img_url] * NB_ASSETS,
)

assert kili.count_assets(src_project_no_assets) == NB_ASSETS
48 changes: 48 additions & 0 deletions tests/e2e/test_mutations_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,51 @@ def test_e2e_append_labels_overwrite(kili: Kili, project: Dict):
]
for label_id in old_pred_ids_asset_1:
assert label_id not in new_label_ids


@pytest.fixture()
def project_and_asset_id(kili: Kili):
interface = {
"jobs": {
"CLASSIFICATION_JOB": {
"content": {"categories": {"A": {"children": [], "name": "A"}}, "input": "radio"},
"instruction": "classif",
"mlTask": "CLASSIFICATION",
"required": 1,
"isChild": False,
}
}
}

project = kili.create_project(
input_type="TEXT",
json_interface=interface,
title="test_append_many_labels",
)

kili.append_many_to_dataset(
project_id=project["id"],
content_array=["asset_content_1"],
external_id_array=["1"],
)

asset_id = kili.assets(project_id=project["id"], fields=("id",))[0]

yield project["id"], asset_id["id"]

kili.delete_project(project["id"])


def test_append_many_labels(kili: Kili, project_and_asset_id):
project_id, asset_id = project_and_asset_id

N_LABELS = 1000

kili.append_labels(
project_id=project_id,
asset_id_array=[asset_id] * N_LABELS,
json_response_array=[{"CLASSIFICATION_JOB": {"categories": [{"name": "A"}]}}] * N_LABELS,
label_type="DEFAULT",
)

assert kili.count_labels(project_id=project_id) == N_LABELS
14 changes: 14 additions & 0 deletions tests/e2e/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
from kili.client import Kili


@pytest.fixture()
def project_name(kili: Kili):
project_name = "e2e test_create_project " + str(uuid.uuid4())

yield project_name

project_id = kili.projects(search_query=f"%{project_name}%", first=1)[0]["id"]
kili.delete_project(project_id)


def test_create_project(project_name: str, kili: Kili):
_ = kili.create_project(input_type="TEXT", json_interface={}, title=project_name)


@pytest.fixture()
def projects_uuid(kili: Kili):
projects_uuid = str(uuid.uuid4())
Expand Down

0 comments on commit ece2d63

Please sign in to comment.