-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into clwan/sample_1_10
- Loading branch information
Showing
57 changed files
with
2,263 additions
and
1,663 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
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
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
77 changes: 77 additions & 0 deletions
77
src/promptflow-azure/tests/sdk_cli_azure_test/e2etests/test_pfs_azure.py
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,77 @@ | ||
import json | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import mock | ||
import pytest | ||
from flask.app import Flask | ||
|
||
|
||
@pytest.fixture | ||
def app() -> Flask: | ||
from promptflow._sdk._service.app import create_app | ||
|
||
app, _ = create_app() | ||
app.config.update({"TESTING": True}) | ||
yield app | ||
|
||
|
||
@pytest.fixture | ||
def pfs_op(app: Flask): | ||
# Hack to import the pfs test utils from the devkit tests | ||
import sys | ||
|
||
sys.path.append("../promptflow-devkit/tests") | ||
from sdk_pfs_test.utils import PFSOperations | ||
|
||
client = app.test_client() | ||
return PFSOperations(client) | ||
|
||
|
||
@pytest.mark.e2etest | ||
class TestPFSAzure: | ||
@pytest.mark.skipif(pytest.is_replay, reason="connection provider test, skip in non-live mode.") | ||
def test_get_connection_by_provider(self, pfs_op, subscription_id, resource_group_name, workspace_name): | ||
target = "promptflow._sdk._pf_client.Configuration.get_connection_provider" | ||
provider_url_target = "promptflow.core._utils.extract_workspace" | ||
mock_provider_url = (subscription_id, resource_group_name, workspace_name) | ||
with mock.patch(target) as mocked_config, mock.patch(provider_url_target) as mocked_provider_url: | ||
mocked_config.return_value = "azureml" | ||
mocked_provider_url.return_value = mock_provider_url | ||
connections = pfs_op.list_connections(status_code=200).json | ||
assert len(connections) > 0 | ||
|
||
connection = pfs_op.get_connection(name=connections[0]["name"], status_code=200).json | ||
assert connection["name"] == connections[0]["name"] | ||
|
||
target = "promptflow._sdk._pf_client.Configuration.get_config" | ||
with tempfile.TemporaryDirectory() as temp: | ||
config_file = Path(temp) / ".azureml" / "config.json" | ||
config_file.parent.mkdir(parents=True, exist_ok=True) | ||
with open(config_file, "w") as f: | ||
config = { | ||
"subscription_id": subscription_id, | ||
"resource_group": resource_group_name, | ||
"workspace_name": workspace_name, | ||
} | ||
json.dump(config, f) | ||
with mock.patch(target) as mocked_config: | ||
mocked_config.return_value = "azureml" | ||
connections = pfs_op.list_connections_by_provider(working_dir=temp, status_code=200).json | ||
assert len(connections) > 0 | ||
|
||
connection = pfs_op.get_connections_by_provider( | ||
name=connections[0]["name"], working_dir=temp, status_code=200 | ||
).json | ||
assert connection["name"] == connections[0]["name"] | ||
|
||
# this test checked 2 cases: | ||
# 1. if the working directory is not exist, it should return 400 | ||
# 2. working directory has been encoded and decoded correctly, so that previous call may pass validation | ||
error_message = pfs_op.list_connections_by_provider( | ||
working_dir=temp + "not exist", status_code=400 | ||
).json | ||
assert error_message == { | ||
"errors": {"working_directory": "Invalid working directory."}, | ||
"message": "Input payload validation failed", | ||
} |
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
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
Empty file.
Oops, something went wrong.