Skip to content

Commit

Permalink
fix: use projects resolver to check for data connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas1312 committed Oct 5, 2023
1 parent 0b434df commit e3cea8e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/integration/use_cases/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_given_query_parameters_I_can_query_assets_and_download_their_media(
kili_api_gateway: KiliAPIGateway, mocker
):
# mocking
kili_api_gateway.get_project.return_value = {"inputType": "IMAGE"}
kili_api_gateway.get_project.return_value = {"inputType": "IMAGE", "dataConnections": None}
media_downlaoder_mock = mocker.patch.object(MediaDownloader, "__init__", return_value=None)

# given parameters to query assets
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/services/export/test_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
_get_coco_categories_with_mapping,
_get_coco_geometry_from_kili_bpoly,
)
from kili.services.export.format.kili import KiliExporter
from kili.services.types import Job, JobName
from kili.utils.tempfile import TemporaryDirectory

Expand Down Expand Up @@ -579,12 +578,9 @@ def test_when_exporting_to_coco_given_a_project_with_data_connection_then_it_sho
mocker.patch(
"kili.services.export.format.base.get_project", return_value=get_project_return_val
)
mocker.patch.object(KiliExporter, "_check_arguments_compatibility", return_value=None)
mocker.patch.object(KiliExporter, "_check_project_compatibility", return_value=None)
mocker.patch(
"kili.services.export.format.base.DataConnectionsQuery.__call__",
return_value=(i for i in [{"id": "fake_data_connection_id"}]),
)
mocker.patch.object(CocoExporter, "_check_arguments_compatibility", return_value=None)
mocker.patch.object(CocoExporter, "_check_project_compatibility", return_value=None)
mocker.patch.object(CocoExporter, "_has_data_connection", return_value=True)

kili = QueriesLabel()
kili.api_key = "" # type: ignore
Expand Down
10 changes: 4 additions & 6 deletions tests/unit/services/export/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from kili.domain.asset import AssetFilters
from kili.entrypoints.queries.label import QueriesLabel
from kili.orm import Asset
from kili.services.export import export_labels
from kili.services.export import AbstractExporter, export_labels
from kili.services.export.exceptions import (
NoCompatibleJobError,
NotCompatibleInputType,
Expand Down Expand Up @@ -795,6 +795,7 @@ def test_export_with_asset_filter_kwargs(mocker):
"kili.services.export.format.base.get_project", return_value=get_project_return_val
)
mocker.patch.object(KiliExporter, "process_and_save", return_value=None)
mocker.patch.object(KiliExporter, "_has_data_connection", return_value=False)
kili = QueriesLabel()
kili.api_endpoint = "https://" # type: ignore
kili.api_key = "" # type: ignore
Expand Down Expand Up @@ -876,6 +877,7 @@ def test_export_with_asset_filter_kwargs_unknown_arg(mocker):
)
mocker.patch.object(KiliExporter, "_check_arguments_compatibility", return_value=None)
mocker.patch.object(KiliExporter, "_check_project_compatibility", return_value=None)
mocker.patch.object(KiliExporter, "_has_data_connection", return_value=False)
kili = QueriesLabel()
kili.api_endpoint = "https://" # type: ignore
kili.api_key = "" # type: ignore
Expand Down Expand Up @@ -918,11 +920,7 @@ def mock_kili(mocker, with_data_connection):
mocker.patch(
"kili.services.export.format.base.get_project", return_value=get_project_return_val
)
if with_data_connection:
mocker.patch(
"kili.services.export.format.base.DataConnectionsQuery.__call__",
return_value=(i for i in [{"id": "fake_data_connection_id"}]),
)
mocker.patch.object(AbstractExporter, "_has_data_connection", return_value=with_data_connection)

kili = QueriesLabel()
kili.kili_api_gateway = mocker.MagicMock()
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/services/export/test_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from kili.entrypoints.queries.label import QueriesLabel
from kili.orm import Asset
from kili.services.export.format.geojson import GeoJsonExporter


def test_kili_export_labels_geojson(mocker: pytest_mock.MockerFixture):
Expand All @@ -22,10 +23,7 @@ def test_kili_export_labels_geojson(mocker: pytest_mock.MockerFixture):
mocker.patch(
"kili.services.export.format.base.get_project", return_value=get_project_return_val
)
mocker.patch(
"kili.services.export.format.base.DataConnectionsQuery.__call__",
return_value=(i for i in [{"id": "fake_data_connection_id"}]),
)
mocker.patch.object(GeoJsonExporter, "_has_data_connection", return_value=False)
mocker.patch(
"kili.services.export.format.base.fetch_assets",
return_value=[
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/services/export/test_kili.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def test_kili_exporter_convert_to_pixel_coords_pdf(mocker: pytest_mock.MockerFix
def test_kili_export_labels_non_normalized_pdf(mocker: pytest_mock.MockerFixture):
get_project_return_val = {
"inputType": "PDF",
"dataConnections": None,
"id": "fake_proj_id",
"title": "fake_proj_title",
"description": "fake_proj_description",
Expand Down Expand Up @@ -273,6 +274,7 @@ def test_kili_export_labels_non_normalized_image(mocker: pytest_mock.MockerFixtu
get_project_return_val = {
"id": "fake_proj_id",
"title": "hgfhfg",
"dataConnections": None,
"inputType": "IMAGE",
"jsonInterface": {
"jobs": {
Expand Down Expand Up @@ -444,6 +446,7 @@ def test_kili_export_labels_non_normalized_video(mocker: pytest_mock.MockerFixtu
"title": "Object tracking on video",
"description": "Use bounding-box to track objects across video frames.",
"id": "fake_proj_id",
"dataConnections": None,
}

mocker.patch("kili.services.export.get_project", return_value=get_project_return_val)
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/services/export/test_voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from kili.entrypoints.queries.label import QueriesLabel
from kili.services.export.exceptions import NotCompatibleOptions
from kili.services.export.format.voc import _convert_from_kili_to_voc_format
from kili.services.export.format.voc import (
VocExporter,
_convert_from_kili_to_voc_format,
)
from tests.fakes.fake_data import asset_image_1, asset_image_1_without_annotation


Expand Down Expand Up @@ -44,15 +47,13 @@ def test_when_exporting_to_voc_given_a_project_with_data_connection_then_it_shou
"inputType": "IMAGE",
"title": "",
"id": "fake_proj_id",
"dataConnections": None,
}
mocker.patch("kili.services.export.get_project", return_value=get_project_return_val)
mocker.patch(
"kili.services.export.format.base.get_project", return_value=get_project_return_val
)
mocker.patch(
"kili.services.export.format.base.DataConnectionsQuery.__call__",
return_value=(i for i in [{"id": "fake_data_connection_id"}]),
)
mocker.patch.object(VocExporter, "_has_data_connection", return_value=True)

kili = QueriesLabel()
kili.api_endpoint = "https://" # type: ignore
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/services/export/test_yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from kili.entrypoints.queries.label import QueriesLabel
from kili.orm import Asset
from kili.services.export.format.yolo import (
YoloExporter,
_convert_from_kili_to_yolo_format,
_process_asset,
_write_class_file,
Expand Down Expand Up @@ -283,6 +284,7 @@ def test_yolo_v8_merged(mocker: pytest_mock.MockerFixture):
"kili.services.export.format.base.fetch_assets",
return_value=[Asset(asset) for asset in assets],
)
mocker.patch.object(YoloExporter, "_has_data_connection", return_value=False)

kili = QueriesLabel()
kili.api_endpoint = "https://" # type: ignore
Expand Down Expand Up @@ -334,6 +336,7 @@ def test_yolo_v8_split_jobs(mocker: pytest_mock.MockerFixture):
"kili.services.export.format.base.fetch_assets",
return_value=[Asset(asset) for asset in assets],
)
mocker.patch.object(YoloExporter, "_has_data_connection", return_value=False)

kili = QueriesLabel()
kili.api_endpoint = "https://" # type: ignore
Expand Down

0 comments on commit e3cea8e

Please sign in to comment.