From 5146424c44627f5b20935e2c43396e1c25aa7afd Mon Sep 17 00:00:00 2001 From: tstadel Date: Mon, 9 Dec 2024 15:28:46 +0100 Subject: [PATCH] fix tests --- tests/conftest.py | 12 +++++ .../api/test_integration_upload_sessions.py | 1 + .../service/test_integration_files_service.py | 2 + tests/unit/test_cli.py | 49 +++++++++++++++++++ .../sync_client/test_sync_workflow_files.py | 21 ++++++++ 5 files changed, 85 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index f41c840b..922d3049 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,6 +52,18 @@ def integration_config() -> CommonConfig: return config +@pytest.fixture(scope="session") +def integration_config_safe_mode() -> CommonConfig: + config = CommonConfig( + api_key=os.getenv("API_KEY", ""), + api_url=os.getenv("API_URL", ""), + safe_mode=True, + ) + assert config.api_key != "", "API_KEY environment variable must be set" + assert config.api_url != "", "API_URL environment variable must be set" + return config + + @pytest.fixture def unit_config() -> CommonConfig: return CommonConfig(api_key="test_api_key", api_url="https://fake.dc.api/api/v1") diff --git a/tests/integration/api/test_integration_upload_sessions.py b/tests/integration/api/test_integration_upload_sessions.py index 311bc732..4e69a679 100644 --- a/tests/integration/api/test_integration_upload_sessions.py +++ b/tests/integration/api/test_integration_upload_sessions.py @@ -11,6 +11,7 @@ @pytest.mark.asyncio +@pytest.mark.parametrize("integration_config", ["integration_config", "integration_config_safe_mode"], indirect=True) class TestCreateUploadSessions: async def test_create_and_close_upload_session(self, integration_config: CommonConfig, workspace_name: str) -> None: async with DeepsetCloudAPI.factory(integration_config) as deepset_cloud_api: diff --git a/tests/integration/service/test_integration_files_service.py b/tests/integration/service/test_integration_files_service.py index 42a9b25c..7102abe0 100644 --- a/tests/integration/service/test_integration_files_service.py +++ b/tests/integration/service/test_integration_files_service.py @@ -18,6 +18,7 @@ @pytest.mark.asyncio +@pytest.mark.parametrize("integration_config", ["integration_config", "integration_config_safe_mode"], indirect=True) class TestUploadsFileService: async def test_direct_upload_path(self, integration_config: CommonConfig, workspace_name: str) -> None: async with FilesService.factory(integration_config) as file_service: @@ -276,6 +277,7 @@ async def test_list_all_files(self, integration_config: CommonConfig, workspace_ @pytest.mark.asyncio +@pytest.mark.parametrize("integration_config", ["integration_config", "integration_config_safe_mode"], indirect=True) class TestDownloadFilesService: async def test_download_files(self, integration_config: CommonConfig, workspace_name: str) -> None: with tempfile.TemporaryDirectory() as tmp_dir: diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 734179f1..9ca7e12b 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -71,6 +71,7 @@ def test_upload_only_desired_file_types_defaults_to_text(self, async_upload_mock recursive=False, desired_file_types=[".txt", ".pdf"], enable_parallel_processing=True, + safe_mode=False, ) assert result.exit_code == 0 @@ -105,6 +106,35 @@ def test_upload_only_desired_file_types_with_desired_file_types(self, async_uplo recursive=False, desired_file_types=[".csv", ".pdf", ".json", ".xml"], enable_parallel_processing=False, + safe_mode=False, + ) + assert result.exit_code == 0 + + @patch("deepset_cloud_sdk.workflows.sync_client.files.async_upload") + def test_upload_safe_mode(self, async_upload_mock: AsyncMock) -> None: + result = runner.invoke( + cli_app, + [ + "upload", + "./test/data/upload_folder/example.txt", + "--workspace-name", + "default", + "--safe-mode", + ], + ) + async_upload_mock.assert_called_once_with( + paths=[Path("test/data/upload_folder/example.txt")], + api_key=None, + api_url=None, + workspace_name="default", + write_mode=WriteMode.KEEP, + blocking=True, + timeout_s=None, + show_progress=True, + recursive=False, + desired_file_types=[".txt", ".pdf"], + enable_parallel_processing=False, + safe_mode=True, ) assert result.exit_code == 0 @@ -124,6 +154,25 @@ def test_download_files(self, sync_download_mock: AsyncMock) -> None: api_key=None, api_url=None, show_progress=True, + safe_mode=False, + ) + + @patch("deepset_cloud_sdk.cli.sync_download") + def test_download_files_safe_mode(self, sync_download_mock: AsyncMock) -> None: + sync_download_mock.side_effect = Mock(spec=sync_download) + result = runner.invoke(cli_app, ["download", "--workspace-name", "default", "--safe-mode"]) + assert result.exit_code == 0 + sync_download_mock.assert_called_once_with( + workspace_name="default", + file_dir=None, + name=None, + odata_filter=None, + include_meta=True, + batch_size=50, + api_key=None, + api_url=None, + show_progress=True, + safe_mode=True, ) class TestListFiles: diff --git a/tests/unit/workflows/sync_client/test_sync_workflow_files.py b/tests/unit/workflows/sync_client/test_sync_workflow_files.py index eacbeb20..86d874c5 100644 --- a/tests/unit/workflows/sync_client/test_sync_workflow_files.py +++ b/tests/unit/workflows/sync_client/test_sync_workflow_files.py @@ -41,6 +41,26 @@ def test_upload_folder(async_upload_mock: AsyncMock) -> None: recursive=False, desired_file_types=SUPPORTED_TYPE_SUFFIXES, enable_parallel_processing=True, + safe_mode=False, + ) + + +@patch("deepset_cloud_sdk.workflows.sync_client.files.async_upload") +def test_upload_folder_safe_mode(async_upload_mock: AsyncMock) -> None: + upload(paths=[Path("./tests/data/upload_folder")], enable_parallel_processing=True, safe_mode=True) + async_upload_mock.assert_called_once_with( + paths=[Path("./tests/data/upload_folder")], + api_key=None, + api_url=None, + workspace_name=DEFAULT_WORKSPACE_NAME, + write_mode=WriteMode.KEEP, + blocking=True, + timeout_s=None, + show_progress=True, + recursive=False, + desired_file_types=SUPPORTED_TYPE_SUFFIXES, + enable_parallel_processing=True, + safe_mode=True, ) @@ -147,6 +167,7 @@ def test_download_files() -> None: batch_size=100, show_progress=True, timeout_s=100, + safe_mode=False, )