Files
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

111 lines
3.8 KiB
Python

"""Unit tests for the Bitbucket integration module."""
from integrations.bitbucket import (
BitbucketConfig,
BitbucketValidationResult,
bitbucket_config_from_env,
build_bitbucket_config,
)
class TestBitbucketConfig:
"""Tests for BitbucketConfig model."""
def test_defaults(self) -> None:
config = BitbucketConfig(workspace="myteam", username="user", app_password="pass")
assert config.workspace == "myteam"
assert config.username == "user"
assert config.app_password == "pass"
assert config.base_url == "https://api.bitbucket.org/2.0"
assert config.timeout_seconds == 10.0
assert config.max_results == 25
def test_is_configured_with_all_fields(self) -> None:
config = BitbucketConfig(workspace="myteam", username="user", app_password="pass")
assert config.is_configured is True
def test_is_configured_missing_workspace(self) -> None:
config = BitbucketConfig(username="user", app_password="pass")
assert config.is_configured is False
def test_is_configured_missing_password(self) -> None:
config = BitbucketConfig(workspace="myteam", username="user")
assert config.is_configured is False
def test_normalize_workspace_strips_whitespace(self) -> None:
config = BitbucketConfig(workspace=" myteam ", username="user", app_password="pass")
assert config.workspace == "myteam"
def test_normalize_base_url_strips_trailing_slash(self) -> None:
config = BitbucketConfig(
workspace="myteam",
username="user",
app_password="pass",
base_url="https://api.bitbucket.org/2.0/",
)
assert config.base_url == "https://api.bitbucket.org/2.0"
class TestBuildBitbucketConfig:
"""Tests for build_bitbucket_config helper."""
def test_from_dict(self) -> None:
config = build_bitbucket_config(
{"workspace": "myteam", "username": "user", "app_password": "pass"}
)
assert config.workspace == "myteam"
assert config.is_configured is True
def test_from_none(self) -> None:
config = build_bitbucket_config(None)
assert config.workspace == ""
assert config.is_configured is False
class TestBitbucketConfigFromEnv:
"""Tests for bitbucket_config_from_env helper."""
def test_returns_none_without_workspace(self) -> None:
import os
old = os.environ.get("BITBUCKET_WORKSPACE")
os.environ.pop("BITBUCKET_WORKSPACE", None)
try:
result = bitbucket_config_from_env()
assert result is None
finally:
if old is not None:
os.environ["BITBUCKET_WORKSPACE"] = old
def test_returns_config_with_workspace(self) -> None:
import os
os.environ["BITBUCKET_WORKSPACE"] = "testteam"
os.environ["BITBUCKET_USERNAME"] = "testuser"
os.environ["BITBUCKET_APP_PASSWORD"] = "testpass"
try:
config = bitbucket_config_from_env()
assert config is not None
assert config.workspace == "testteam"
assert config.username == "testuser"
assert config.app_password == "testpass"
finally:
for key in [
"BITBUCKET_WORKSPACE",
"BITBUCKET_USERNAME",
"BITBUCKET_APP_PASSWORD",
]:
os.environ.pop(key, None)
class TestBitbucketValidationResult:
"""Tests for BitbucketValidationResult dataclass."""
def test_ok_result(self) -> None:
result = BitbucketValidationResult(ok=True, detail="Connected.")
assert result.ok is True
def test_error_result(self) -> None:
result = BitbucketValidationResult(ok=False, detail="Auth failed.")
assert result.ok is False