From d9d7f4f87e3874b6ed62c652747d16090bfb08fd Mon Sep 17 00:00:00 2001 From: Jonas Maison Date: Thu, 5 Oct 2023 09:17:57 +0200 Subject: [PATCH] refac: --- tests/unit/services/export/test_export.py | 9 ++++----- tests/unit/services/export/test_geojson.py | 6 ++---- tests/unit/services/export/test_kili.py | 3 +++ tests/unit/services/export/test_voc.py | 6 ++---- tests/unit/services/export/test_yolo.py | 3 +++ 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/unit/services/export/test_export.py b/tests/unit/services/export/test_export.py index d991fcb56..78c58c00b 100644 --- a/tests/unit/services/export/test_export.py +++ b/tests/unit/services/export/test_export.py @@ -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, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore kili.api_key = "" # type: ignore @@ -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, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore kili.api_key = "" # type: ignore @@ -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() @@ -938,6 +936,7 @@ def test_when_exporting_with_assets_given_a_project_with_data_connection_then_it kili.api_key = "" # type: ignore kili.graphql_client = mocker.MagicMock() kili.http_client = mocker.MagicMock() + mocker.patch.object(AbstractExporter, "_has_data_connection", return_value=True) with pytest.raises( NotCompatibleOptions, diff --git a/tests/unit/services/export/test_geojson.py b/tests/unit/services/export/test_geojson.py index 51ab7036b..1a8c5c548 100644 --- a/tests/unit/services/export/test_geojson.py +++ b/tests/unit/services/export/test_geojson.py @@ -7,6 +7,7 @@ from kili.entrypoints.queries.label import QueriesLabel from kili.orm import Asset +from kili.services.export import AbstractExporter def test_kili_export_labels_geojson(mocker: pytest_mock.MockerFixture): @@ -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(AbstractExporter, "_check_and_ensure_asset_access", return_value=None) mocker.patch( "kili.services.export.format.base.fetch_assets", return_value=[ diff --git a/tests/unit/services/export/test_kili.py b/tests/unit/services/export/test_kili.py index c3c7f0f76..e8155ee0f 100644 --- a/tests/unit/services/export/test_kili.py +++ b/tests/unit/services/export/test_kili.py @@ -238,6 +238,7 @@ def test_kili_export_labels_non_normalized_pdf(mocker: pytest_mock.MockerFixture ) ], ) + mocker.patch.object(AbstractExporter, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore @@ -385,6 +386,7 @@ def test_kili_export_labels_non_normalized_image(mocker: pytest_mock.MockerFixtu ) ], ) + mocker.patch.object(AbstractExporter, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore @@ -460,6 +462,7 @@ def test_kili_export_labels_non_normalized_video(mocker: pytest_mock.MockerFixtu ) ], ) + mocker.patch.object(AbstractExporter, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore diff --git a/tests/unit/services/export/test_voc.py b/tests/unit/services/export/test_voc.py index 99a7cbdad..1f18a771f 100644 --- a/tests/unit/services/export/test_voc.py +++ b/tests/unit/services/export/test_voc.py @@ -3,6 +3,7 @@ import pytest from kili.entrypoints.queries.label import QueriesLabel +from kili.services.export import VocExporter from kili.services.export.exceptions import NotCompatibleOptions from kili.services.export.format.voc import _convert_from_kili_to_voc_format from tests.fakes.fake_data import asset_image_1, asset_image_1_without_annotation @@ -49,10 +50,7 @@ def test_when_exporting_to_voc_given_a_project_with_data_connection_then_it_shou 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 diff --git a/tests/unit/services/export/test_yolo.py b/tests/unit/services/export/test_yolo.py index 1ea561784..dd8826843 100644 --- a/tests/unit/services/export/test_yolo.py +++ b/tests/unit/services/export/test_yolo.py @@ -9,6 +9,7 @@ from kili.adapters.http_client import HttpClient from kili.entrypoints.queries.label import QueriesLabel from kili.orm import Asset +from kili.services.export import YoloExporter from kili.services.export.format.yolo import ( _convert_from_kili_to_yolo_format, _process_asset, @@ -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, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore @@ -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, "_check_and_ensure_asset_access", return_value=None) kili = QueriesLabel() kili.api_endpoint = "https://" # type: ignore