-
Notifications
You must be signed in to change notification settings - Fork 6
test(live): add sandboxed live test suite #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
serhii-workato
wants to merge
1
commit into
main
Choose a base branch
from
tests/92-e2e-integration-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| # Live Tests (Sandbox Only) | ||
|
|
||
| These tests hit real Workato APIs. Run only against sandbox/trial environments. | ||
|
|
||
| ## Required Environment Variables | ||
| - `WORKATO_HOST` | ||
| - `WORKATO_API_TOKEN` | ||
| - `WORKATO_LIVE_SANDBOX=1` (explicit confirmation) | ||
|
|
||
| ## Optional Environment Variables | ||
| - `WORKATO_TEST_PROJECT_ID` or `WORKATO_TEST_PROJECT_NAME` | ||
| - `WORKATO_TEST_PROFILE` (default: `live-test`) | ||
| - `WORKATO_LIVE_ALLOW_PUSH=1` (enable `workato push`) | ||
| - `WORKATO_TEST_RECIPE_ID` (enable recipe start/stop) | ||
| - `WORKATO_LIVE_ALLOW_RECIPE_CONTROL=1` (enable recipe start/stop) | ||
| - `WORKATO_TEST_CONNECTION_ID` (enable OAuth URL and pick-list tests) | ||
| - `WORKATO_TEST_PICKLIST_NAME` (enable pick-list test) | ||
|
|
||
| ## Run | ||
| ```bash | ||
| WORKATO_LIVE_SANDBOX=1 make test-live | ||
| ``` | ||
|
|
||
| ## Safety Notes | ||
| - Destructive actions are opt-in. | ||
| - Project creation test skips if the token lacks permissions. |
This file contains hidden or 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 @@ | ||
| """Live test package marker.""" |
This file contains hidden or 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,29 @@ | ||
| import contextlib | ||
|
|
||
| from collections.abc import AsyncGenerator | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| import pytest_asyncio | ||
|
|
||
| from workato_platform_cli import Workato | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture(autouse=True) | ||
| async def close_workato_clients( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> AsyncGenerator[None, None]: | ||
| clients: list[Workato] = [] | ||
| original_init = Workato.__init__ | ||
|
|
||
| def tracking_init(self: Workato, *args: Any, **kwargs: Any) -> None: | ||
| original_init(self, *args, **kwargs) | ||
| clients.append(self) | ||
|
|
||
| monkeypatch.setattr(Workato, "__init__", tracking_init) | ||
|
|
||
| yield | ||
|
|
||
| for client in clients: | ||
| with contextlib.suppress(Exception): | ||
| await client.close() |
This file contains hidden or 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,170 @@ | ||
| import json | ||
| import os | ||
|
|
||
| from pathlib import Path | ||
| from typing import cast | ||
|
|
||
| import certifi | ||
| import pytest | ||
|
|
||
| from asyncclick.testing import CliRunner | ||
|
|
||
| from workato_platform_cli import Workato | ||
| from workato_platform_cli.cli import cli | ||
| from workato_platform_cli.cli.commands.projects.project_manager import ProjectManager | ||
| from workato_platform_cli.client.workato_api.configuration import Configuration | ||
|
|
||
|
|
||
| REQUIRED_BASE = ["WORKATO_HOST", "WORKATO_API_TOKEN"] | ||
| _PROJECT_ID_CACHE: str | None = None | ||
|
|
||
|
|
||
| def ensure_sandbox() -> None: | ||
| host = os.getenv("WORKATO_HOST", "").lower() | ||
| if os.getenv("WORKATO_LIVE_SANDBOX", "").lower() in {"1", "true", "yes"}: | ||
| return | ||
| if any(token in host for token in ("trial", "preview", "sandbox")): | ||
| return | ||
| pytest.skip( | ||
| "Set WORKATO_LIVE_SANDBOX=1 to confirm tests are running against a sandbox." | ||
| ) | ||
|
|
||
|
|
||
| def require_live_env(extra: list[str] | None = None) -> None: | ||
| ensure_sandbox() | ||
| required = REQUIRED_BASE + (extra or []) | ||
| missing = [key for key in required if not os.getenv(key)] | ||
| if missing: | ||
| pytest.skip(f"Missing env vars for live tests: {', '.join(missing)}") | ||
|
|
||
|
|
||
| def allow_live_action(flag: str) -> bool: | ||
| return os.getenv(flag, "").lower() in {"1", "true", "yes"} | ||
|
|
||
|
|
||
| def force_keyring_fallback(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| import workato_platform_cli.cli.utils.config.profiles as profiles | ||
|
|
||
| def _raise_no_keyring() -> None: | ||
| raise Exception("No keyring backend") | ||
|
|
||
| monkeypatch.setattr(profiles.keyring, "get_keyring", _raise_no_keyring) | ||
|
|
||
|
|
||
| def prepare_live_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: | ||
| monkeypatch.setenv("WORKATO_DISABLE_UPDATE_CHECK", "1") | ||
| monkeypatch.setattr(Path, "home", lambda: tmp_path) | ||
| force_keyring_fallback(monkeypatch) | ||
|
|
||
|
|
||
| def _build_api_client() -> Workato: | ||
| api_host = os.environ["WORKATO_HOST"] | ||
| api_token = os.environ["WORKATO_API_TOKEN"] | ||
| api_config = Configuration( | ||
| access_token=api_token, | ||
| host=api_host, | ||
| ssl_ca_cert=certifi.where(), | ||
| ) | ||
| return Workato(configuration=api_config) | ||
|
|
||
|
|
||
| async def resolve_project_id() -> str: | ||
| global _PROJECT_ID_CACHE | ||
| if _PROJECT_ID_CACHE: | ||
| return _PROJECT_ID_CACHE | ||
|
|
||
| project_id = os.getenv("WORKATO_TEST_PROJECT_ID") | ||
| if project_id: | ||
| _PROJECT_ID_CACHE = project_id | ||
| return project_id | ||
|
|
||
| project_name = os.getenv("WORKATO_TEST_PROJECT_NAME") | ||
|
|
||
| async with _build_api_client() as workato_api_client: | ||
| project_manager = ProjectManager(workato_api_client=workato_api_client) | ||
| projects = await project_manager.get_all_projects() | ||
|
|
||
| if not projects: | ||
| pytest.skip("No projects found in workspace.") | ||
|
|
||
| if project_name: | ||
| for project in projects: | ||
| if project.name == project_name: | ||
| _PROJECT_ID_CACHE = str(project.id) | ||
| return str(project.id) | ||
| pytest.skip(f"No project found with name '{project_name}'.") | ||
|
|
||
| _PROJECT_ID_CACHE = str(projects[0].id) | ||
| return _PROJECT_ID_CACHE | ||
|
|
||
|
|
||
| async def delete_project(project_id: int) -> None: | ||
| async with _build_api_client() as workato_api_client: | ||
| await workato_api_client.projects_api.delete_project(project_id=project_id) | ||
|
|
||
|
|
||
| async def run_init(cli_runner: CliRunner, project_id: str) -> dict[str, object]: | ||
| api_host = os.environ["WORKATO_HOST"] | ||
| profile_name = os.getenv("WORKATO_TEST_PROFILE", "live-test") | ||
| result = await cli_runner.invoke( | ||
| cli, | ||
| [ | ||
| "init", | ||
| "--non-interactive", | ||
| "--profile", | ||
| profile_name, | ||
| "--project-id", | ||
| str(project_id), | ||
| "--output-mode", | ||
| "json", | ||
| "--region", | ||
| "custom", | ||
| "--api-url", | ||
| api_host, | ||
| ], | ||
| ) | ||
|
|
||
| assert result.exit_code == 0, result.output | ||
|
|
||
| lines = [line for line in result.output.splitlines() if line.strip()] | ||
| data = cast(dict[str, object], json.loads(lines[-1])) | ||
| assert data.get("status") == "success" | ||
| return data | ||
|
|
||
|
|
||
| async def run_init_create_project( | ||
| cli_runner: CliRunner, | ||
| project_name: str, | ||
| ) -> dict[str, object]: | ||
| api_host = os.environ["WORKATO_HOST"] | ||
| profile_name = os.getenv("WORKATO_TEST_PROFILE", "live-test") | ||
| result = await cli_runner.invoke( | ||
| cli, | ||
| [ | ||
| "init", | ||
| "--non-interactive", | ||
| "--profile", | ||
| profile_name, | ||
| "--project-name", | ||
| project_name, | ||
| "--output-mode", | ||
| "json", | ||
| "--region", | ||
| "custom", | ||
| "--api-url", | ||
| api_host, | ||
| ], | ||
| ) | ||
|
|
||
| if result.exit_code != 0: | ||
| if "UNAUTHORIZED" in result.output or "Authentication failed" in result.output: | ||
| pytest.skip( | ||
| "Project creation/pull not authorized for this token. " | ||
| "Check sandbox permissions or token scope." | ||
| ) | ||
| assert result.exit_code == 0, result.output | ||
|
|
||
| lines = [line for line in result.output.splitlines() if line.strip()] | ||
| data = cast(dict[str, object], json.loads(lines[-1])) | ||
| assert data.get("status") == "success" | ||
| return data | ||
This file contains hidden or 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,58 @@ | ||
| import os | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from asyncclick.testing import CliRunner | ||
|
|
||
| from tests.live.helpers import prepare_live_env, require_live_env | ||
| from workato_platform_cli.cli import cli | ||
|
|
||
|
|
||
| @pytest.mark.live | ||
| @pytest.mark.asyncio | ||
| async def test_connections_oauth_flow_live( | ||
| cli_runner: CliRunner, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| require_live_env(["WORKATO_TEST_CONNECTION_ID"]) | ||
| prepare_live_env(monkeypatch, tmp_path) | ||
|
|
||
| connection_id = os.environ["WORKATO_TEST_CONNECTION_ID"] | ||
|
|
||
| list_result = await cli_runner.invoke(cli, ["connections", "list"]) | ||
| assert list_result.exit_code == 0, list_result.output | ||
|
|
||
| oauth_result = await cli_runner.invoke( | ||
| cli, ["connections", "get-oauth-url", "--id", str(connection_id)] | ||
| ) | ||
| assert oauth_result.exit_code == 0, oauth_result.output | ||
|
|
||
|
|
||
| @pytest.mark.live | ||
| @pytest.mark.asyncio | ||
| async def test_connection_picklist_live( | ||
| cli_runner: CliRunner, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| require_live_env(["WORKATO_TEST_CONNECTION_ID", "WORKATO_TEST_PICKLIST_NAME"]) | ||
| prepare_live_env(monkeypatch, tmp_path) | ||
|
|
||
| connection_id = os.environ["WORKATO_TEST_CONNECTION_ID"] | ||
| picklist_name = os.environ["WORKATO_TEST_PICKLIST_NAME"] | ||
|
|
||
| result = await cli_runner.invoke( | ||
| cli, | ||
| [ | ||
| "connections", | ||
| "pick-list", | ||
| "--id", | ||
| str(connection_id), | ||
| "--pick-list-name", | ||
| picklist_name, | ||
| ], | ||
| ) | ||
| assert result.exit_code == 0, result.output |
This file contains hidden or 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,25 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from asyncclick.testing import CliRunner | ||
|
|
||
| from tests.live.helpers import prepare_live_env, require_live_env | ||
| from workato_platform_cli.cli import cli | ||
|
|
||
|
|
||
| @pytest.mark.live | ||
| @pytest.mark.asyncio | ||
| async def test_connectors_discovery_live( | ||
| cli_runner: CliRunner, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| require_live_env() | ||
| prepare_live_env(monkeypatch, tmp_path) | ||
|
|
||
| list_result = await cli_runner.invoke(cli, ["connectors", "list"]) | ||
| assert list_result.exit_code == 0, list_result.output | ||
|
|
||
| params_result = await cli_runner.invoke(cli, ["connectors", "parameters"]) | ||
| assert params_result.exit_code == 0, params_result.output |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hovu96 What do you think - should we parse
WORKATO_HOSTmore explicitly to classify the environment? Right now I decide to add as an example checking substrings (trial, preview, sandbox). We also have URLs like https://app-.devenv.awstf.workato.com which won’t match. Should we allow a regex/whitelist for those, or requireWORKATO_LIVE_SANDBOX=1for any non‑standard host/define type of test running?Context: How should we define/standardize environment identification for live test runs?