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
80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
"""Tests for the Notion integration client."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from integrations.notion.client import NotionClient, NotionConfig
|
|
|
|
|
|
@pytest.fixture
|
|
def config() -> NotionConfig:
|
|
return NotionConfig(api_key="secret_test123", database_id="db-abc-123")
|
|
|
|
|
|
@pytest.fixture
|
|
def client(config: NotionConfig) -> NotionClient:
|
|
return NotionClient(config)
|
|
|
|
|
|
def test_is_configured(client: NotionClient) -> None:
|
|
assert client.is_configured is True
|
|
|
|
|
|
def test_is_not_configured_missing_key() -> None:
|
|
config = NotionConfig(api_key="", database_id="db-abc")
|
|
client = NotionClient(config)
|
|
assert client.is_configured is False
|
|
|
|
|
|
def test_create_investigation_page_success(client: NotionClient) -> None:
|
|
mock_resp = MagicMock()
|
|
mock_resp.json.return_value = {"id": "page-123", "url": "https://notion.so/page-123"}
|
|
mock_resp.raise_for_status = MagicMock()
|
|
|
|
with patch("httpx.Client.post", return_value=mock_resp):
|
|
result = client.create_investigation_page(
|
|
title="DB connection spike",
|
|
root_cause="Connection pool exhausted",
|
|
evidence="p99 latency > 5s",
|
|
timeline="14:00 alert fired, 14:05 RCA started",
|
|
suggested_actions="Increase pool size, add circuit breaker",
|
|
severity="high",
|
|
)
|
|
|
|
assert result["success"] is True
|
|
assert result["page_id"] == "page-123"
|
|
|
|
|
|
def test_create_investigation_page_http_error(client: NotionClient) -> None:
|
|
import httpx
|
|
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 401
|
|
mock_resp.text = "Unauthorized"
|
|
|
|
with patch(
|
|
"httpx.Client.post",
|
|
side_effect=httpx.HTTPStatusError("err", request=MagicMock(), response=mock_resp),
|
|
):
|
|
result = client.create_investigation_page(
|
|
title="test",
|
|
root_cause="x",
|
|
evidence="x",
|
|
timeline="x",
|
|
suggested_actions="x",
|
|
)
|
|
|
|
assert result["success"] is False
|
|
assert "401" in result["error"]
|
|
|
|
|
|
def test_notion_service_package_exports() -> None:
|
|
"""Verify the service package re-exports Notion client types."""
|
|
from integrations.notion import NotionClient as ExportedClient
|
|
from integrations.notion import NotionConfig as ExportedConfig
|
|
from integrations.notion.client import NotionClient, NotionConfig
|
|
|
|
assert ExportedClient is NotionClient
|
|
assert ExportedConfig is NotionConfig
|