Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tstadel committed Dec 9, 2024
1 parent 2a9606d commit 5146424
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions tests/integration/api/test_integration_upload_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/service/test_integration_files_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/workflows/sync_client/test_sync_workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -147,6 +167,7 @@ def test_download_files() -> None:
batch_size=100,
show_progress=True,
timeout_s=100,
safe_mode=False,
)


Expand Down

0 comments on commit 5146424

Please sign in to comment.