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
103 lines
3.6 KiB
Python
103 lines
3.6 KiB
Python
"""Unit tests for PagerDuty integration config, catalog, and env-var loader."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from integrations.config_models import PagerDutyIntegrationConfig
|
|
|
|
|
|
class TestPagerDutyIntegrationConfig:
|
|
"""Tests for PagerDutyIntegrationConfig model validation."""
|
|
|
|
def test_valid_config(self) -> None:
|
|
config = PagerDutyIntegrationConfig(api_key="test-key")
|
|
assert config.api_key == "test-key"
|
|
assert config.base_url == "https://api.pagerduty.com"
|
|
assert config.integration_id == ""
|
|
|
|
def test_custom_base_url(self) -> None:
|
|
config = PagerDutyIntegrationConfig(api_key="key", base_url="https://custom.pagerduty.com")
|
|
assert config.base_url == "https://custom.pagerduty.com"
|
|
|
|
def test_api_key_required(self) -> None:
|
|
with pytest.raises(ValidationError):
|
|
PagerDutyIntegrationConfig() # type: ignore[call-arg]
|
|
|
|
def test_headers_format(self) -> None:
|
|
config = PagerDutyIntegrationConfig(api_key="my-token")
|
|
assert config.headers == {
|
|
"Authorization": "Token token=my-token",
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
def test_integration_id_stored(self) -> None:
|
|
config = PagerDutyIntegrationConfig(api_key="k", integration_id="int-123")
|
|
assert config.integration_id == "int-123"
|
|
|
|
|
|
class TestCatalogClassify:
|
|
"""Tests for _classify_service_instance handling of 'pagerduty' key."""
|
|
|
|
def test_classify_valid_pagerduty(self) -> None:
|
|
from integrations._catalog_impl import _classify_service_instance
|
|
|
|
config, source = _classify_service_instance(
|
|
"pagerduty",
|
|
{"api_key": "pd-key", "base_url": "https://api.pagerduty.com"},
|
|
record_id="rec-1",
|
|
)
|
|
assert source == "pagerduty"
|
|
assert config is not None
|
|
assert config.api_key == "pd-key"
|
|
|
|
def test_classify_missing_api_key_returns_none(self) -> None:
|
|
from integrations._catalog_impl import _classify_service_instance
|
|
|
|
config, source = _classify_service_instance(
|
|
"pagerduty",
|
|
{"api_key": "", "base_url": ""},
|
|
record_id="rec-2",
|
|
)
|
|
assert config is None
|
|
assert source is None
|
|
|
|
def test_classify_uses_default_base_url(self) -> None:
|
|
from integrations._catalog_impl import _classify_service_instance
|
|
|
|
config, source = _classify_service_instance(
|
|
"pagerduty",
|
|
{"api_key": "key-1"},
|
|
record_id="rec-3",
|
|
)
|
|
assert source == "pagerduty"
|
|
assert config is not None
|
|
assert config.base_url == "https://api.pagerduty.com"
|
|
|
|
|
|
class TestEnvLoader:
|
|
"""Tests for PAGERDUTY_API_KEY env-var loading."""
|
|
|
|
@patch.dict("os.environ", {"PAGERDUTY_API_KEY": "env-key"}, clear=False)
|
|
def test_env_loader_picks_up_api_key(self) -> None:
|
|
from integrations._catalog_impl import load_env_integrations
|
|
|
|
integrations = load_env_integrations()
|
|
pd_records = [r for r in integrations if r.get("service") == "pagerduty"]
|
|
assert len(pd_records) == 1
|
|
assert pd_records[0]["credentials"]["api_key"] == "env-key"
|
|
|
|
@patch.dict("os.environ", {}, clear=False)
|
|
def test_env_loader_skips_when_no_key(self) -> None:
|
|
import os
|
|
|
|
os.environ.pop("PAGERDUTY_API_KEY", None)
|
|
from integrations._catalog_impl import load_env_integrations
|
|
|
|
integrations = load_env_integrations()
|
|
pd_records = [r for r in integrations if r.get("service") == "pagerduty"]
|
|
assert len(pd_records) == 0
|