ecd59c12de
- cloud_aws_sandbox_steps.py: read context.boto3_available instead of
hardcoding True when patching _BOTO3_AVAILABLE; fixes 3 ImportError
scenarios (145, 163, 181) and unblocks 3 ValueError scenarios
- cloud_aws_sandbox_steps.py: add explicit step overloads for empty
plan_id (behave parse {plan_id} uses .+? and won't match ""); fixes
3 undefined-step errors (193, 199, 205)
- cloud_handler_coverage_r3_steps.py: change _make_resource default
type from aws-account to gcp-account so discover_children() raises
NotImplementedError instead of ImportError; fixes scenario at line 35
- cloud_aws.py: wrap session.client/method() call in try/except in
discover_aws_resources() so RuntimeError from mock sessions returns []
instead of propagating; fixes scenario 106
ISSUES CLOSED: #1280
96 lines
4.0 KiB
Python
96 lines
4.0 KiB
Python
"""Step definitions for AWS sandbox lifecycle scenarios.
|
|
|
|
Tests CloudSandboxStrategy.create/commit/rollback with mocked boto3.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
from unittest.mock import patch
|
|
|
|
from behave import given, when # type: ignore[attr-defined]
|
|
|
|
from cleveragents.resource.handlers.cloud_aws import CloudSandboxStrategy
|
|
|
|
|
|
@given('awssdk a cloud sandbox strategy for "{provider}"')
|
|
def step_sandbox_strategy(context: Any, provider: str) -> None:
|
|
"""Create a CloudSandboxStrategy for the given provider."""
|
|
context.cloud_sandbox = CloudSandboxStrategy(provider) # type: ignore[attr-defined]
|
|
|
|
|
|
@when('awssdk I call create on the AWS sandbox strategy with plan "{plan_id}"')
|
|
def step_sandbox_create_aws(context: Any, plan_id: str) -> None:
|
|
"""Call create on the CloudSandboxStrategy."""
|
|
strategy: CloudSandboxStrategy = context.cloud_sandbox # type: ignore[attr-defined]
|
|
context.raised_error = None # type: ignore[attr-defined]
|
|
context.raised_error_type = None # type: ignore[attr-defined]
|
|
|
|
boto3_avail = getattr(context, "boto3_available", True)
|
|
with patch(
|
|
"cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", boto3_avail
|
|
):
|
|
try:
|
|
strategy.create("res-test-001", plan_id)
|
|
except (NotImplementedError, ImportError, ValueError) as exc:
|
|
context.raised_error = exc # type: ignore[attr-defined]
|
|
context.raised_error_type = type(exc).__name__ # type: ignore[attr-defined]
|
|
|
|
|
|
@when('awssdk I call commit on the AWS sandbox strategy with plan "{plan_id}"')
|
|
def step_sandbox_commit_aws(context: Any, plan_id: str) -> None:
|
|
"""Call commit on the CloudSandboxStrategy."""
|
|
strategy: CloudSandboxStrategy = context.cloud_sandbox # type: ignore[attr-defined]
|
|
context.raised_error = None # type: ignore[attr-defined]
|
|
context.raised_error_type = None # type: ignore[attr-defined]
|
|
|
|
boto3_avail = getattr(context, "boto3_available", True)
|
|
with patch(
|
|
"cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", boto3_avail
|
|
):
|
|
try:
|
|
strategy.commit("res-test-001", plan_id)
|
|
except (NotImplementedError, ImportError, ValueError) as exc:
|
|
context.raised_error = exc # type: ignore[attr-defined]
|
|
context.raised_error_type = type(exc).__name__ # type: ignore[attr-defined]
|
|
|
|
|
|
@when('awssdk I call rollback on the AWS sandbox strategy with plan "{plan_id}"')
|
|
def step_sandbox_rollback_aws(context: Any, plan_id: str) -> None:
|
|
"""Call rollback on the CloudSandboxStrategy."""
|
|
strategy: CloudSandboxStrategy = context.cloud_sandbox # type: ignore[attr-defined]
|
|
context.raised_error = None # type: ignore[attr-defined]
|
|
context.raised_error_type = None # type: ignore[attr-defined]
|
|
|
|
boto3_avail = getattr(context, "boto3_available", True)
|
|
with patch(
|
|
"cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", boto3_avail
|
|
):
|
|
try:
|
|
strategy.rollback("res-test-001", plan_id)
|
|
except (NotImplementedError, ImportError, ValueError) as exc:
|
|
context.raised_error = exc # type: ignore[attr-defined]
|
|
context.raised_error_type = type(exc).__name__ # type: ignore[attr-defined]
|
|
|
|
|
|
# behave's parse format {plan_id} uses .+? and won't match an empty string,
|
|
# so we need explicit overloads for the empty plan_id scenarios.
|
|
|
|
|
|
@when('awssdk I call create on the AWS sandbox strategy with plan ""')
|
|
def step_sandbox_create_aws_empty(context: Any) -> None:
|
|
"""Call create on the CloudSandboxStrategy with empty plan_id."""
|
|
step_sandbox_create_aws(context, "")
|
|
|
|
|
|
@when('awssdk I call commit on the AWS sandbox strategy with plan ""')
|
|
def step_sandbox_commit_aws_empty(context: Any) -> None:
|
|
"""Call commit on the CloudSandboxStrategy with empty plan_id."""
|
|
step_sandbox_commit_aws(context, "")
|
|
|
|
|
|
@when('awssdk I call rollback on the AWS sandbox strategy with plan ""')
|
|
def step_sandbox_rollback_aws_empty(context: Any) -> None:
|
|
"""Call rollback on the CloudSandboxStrategy with empty plan_id."""
|
|
step_sandbox_rollback_aws(context, "")
|