-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adapt deepset cloud sdk endpoint format for saving pipelines (#…
…5969) * chore: adapt to new endpoints formats * docs: add release notes
- Loading branch information
Showing
4 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/update-deepset-cloud-sdk-save-pipeline-config-ff820838846f5f38.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
enhancements: | ||
- | | ||
Update the deepset Cloud SDK to the new endpoint format for new saving pipeline configs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"version": "ignore", | ||
"name": "document_retrieval_1", | ||
"components": [ | ||
{ | ||
"name": "DocumentStore", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
import yaml | ||
|
||
from haystack.utils.deepsetcloud import DeepsetCloudClient, PipelineClient | ||
|
||
|
||
@pytest.fixture | ||
def pipeline_config(samples_path: Path) -> Dict[str, Any]: | ||
with (samples_path / "dc" / "pipeline_config.json").open() as f: | ||
return json.load(f) | ||
|
||
|
||
@pytest.fixture() | ||
def mocked_client() -> Mock: | ||
api_client = Mock(spec=DeepsetCloudClient) | ||
|
||
api_client.build_workspace_url.return_value = "https://dc" | ||
|
||
return api_client | ||
|
||
|
||
@pytest.fixture() | ||
def mock_success_response() -> Mock: | ||
mock_response = Mock() | ||
mock_response.json.return_value = {"name": "test_pipeline"} | ||
|
||
return mock_response | ||
|
||
|
||
class TestSaveConfig: | ||
def test_save_config( | ||
self, pipeline_config: Dict[str, Any], mocked_client: Mock, mock_success_response: Mock | ||
) -> None: | ||
mocked_client.post.return_value = mock_success_response | ||
|
||
pipeline_name = "test_pipeline" | ||
workspace_name = "test_workspace" | ||
|
||
pipeline_client = PipelineClient(client=mocked_client) | ||
|
||
pipeline_client.save_pipeline_config( | ||
config=pipeline_config, pipeline_config_name=pipeline_name, workspace=workspace_name | ||
) | ||
|
||
expected_payload = {"name": pipeline_name, "config": yaml.dump(pipeline_config)} | ||
mocked_client.post.assert_called_once_with(url="https://dc/pipelines", json=expected_payload, headers=None) | ||
|
||
|
||
class TestUpdateConfig: | ||
def test_update_config( | ||
self, pipeline_config: Dict[str, Any], mocked_client: Mock, mock_success_response: Mock | ||
) -> None: | ||
mocked_client.put.return_value = mock_success_response | ||
pipeline_name = "test_pipeline" | ||
workspace_name = "test_workspace" | ||
|
||
pipeline_client = PipelineClient(client=mocked_client) | ||
|
||
pipeline_client.update_pipeline_config( | ||
config=pipeline_config, pipeline_config_name=pipeline_name, workspace=workspace_name | ||
) | ||
|
||
mocked_client.put.assert_called_once_with( | ||
url=f"https://dc/pipelines/{pipeline_name}/yaml", data=yaml.dump(pipeline_config), headers=None | ||
) |