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
135 lines
3.8 KiB
Python
135 lines
3.8 KiB
Python
"""Tests for the Jira integration client."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from integrations.config_models import JiraIntegrationConfig as JiraConfig
|
|
from integrations.jira.client import JiraClient
|
|
|
|
|
|
@pytest.fixture
|
|
def config() -> JiraConfig:
|
|
return JiraConfig(
|
|
base_url="https://myteam.atlassian.net",
|
|
email="user@example.com",
|
|
api_token="test-token-123",
|
|
project_key="OPS",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def client(config: JiraConfig) -> JiraClient:
|
|
return JiraClient(config)
|
|
|
|
|
|
def test_is_configured(client: JiraClient) -> None:
|
|
assert client.is_configured is True
|
|
|
|
|
|
def test_is_not_configured_missing_token() -> None:
|
|
config = JiraConfig(
|
|
base_url="https://myteam.atlassian.net",
|
|
email="user@example.com",
|
|
api_token="",
|
|
project_key="OPS",
|
|
)
|
|
assert JiraClient(config).is_configured is False
|
|
|
|
|
|
def test_create_issue_success(client: JiraClient) -> None:
|
|
mock_resp = MagicMock()
|
|
mock_resp.json.return_value = {"key": "OPS-42", "id": "10042"}
|
|
mock_resp.raise_for_status = MagicMock()
|
|
|
|
with patch("httpx.Client.post", return_value=mock_resp):
|
|
result = client.create_issue(
|
|
summary="DB connection spike",
|
|
description="Connection pool exhausted during peak traffic.",
|
|
priority="High",
|
|
labels=["incident", "rca"],
|
|
)
|
|
|
|
assert result["success"] is True
|
|
assert result["issue_key"] == "OPS-42"
|
|
assert "browse/OPS-42" in result["url"]
|
|
|
|
|
|
def test_create_issue_http_error(client: JiraClient) -> None:
|
|
import httpx
|
|
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 403
|
|
mock_resp.text = "Forbidden"
|
|
|
|
with patch(
|
|
"httpx.Client.post",
|
|
side_effect=httpx.HTTPStatusError("err", request=MagicMock(), response=mock_resp),
|
|
):
|
|
result = client.create_issue(summary="test", description="test")
|
|
|
|
assert result["success"] is False
|
|
assert "403" in result["error"]
|
|
|
|
|
|
def test_add_comment_success(client: JiraClient) -> None:
|
|
mock_resp = MagicMock()
|
|
mock_resp.json.return_value = {"id": "comment-99"}
|
|
mock_resp.raise_for_status = MagicMock()
|
|
|
|
with patch("httpx.Client.post", return_value=mock_resp):
|
|
result = client.add_comment("OPS-42", "RCA complete. Root cause: pool exhaustion.")
|
|
|
|
assert result["success"] is True
|
|
assert result["comment_id"] == "comment-99"
|
|
|
|
|
|
def test_get_issue_success(client: JiraClient) -> None:
|
|
mock_resp = MagicMock()
|
|
mock_resp.json.return_value = {
|
|
"key": "OPS-42",
|
|
"fields": {
|
|
"summary": "DB spike",
|
|
"status": {"name": "Open"},
|
|
"priority": {"name": "High"},
|
|
"description": "some desc",
|
|
"labels": ["incident"],
|
|
},
|
|
}
|
|
mock_resp.raise_for_status = MagicMock()
|
|
|
|
with patch("httpx.Client.get", return_value=mock_resp):
|
|
result = client.get_issue("OPS-42")
|
|
|
|
assert result["success"] is True
|
|
assert result["issue_key"] == "OPS-42"
|
|
assert result["status"] == "Open"
|
|
|
|
|
|
def test_update_issue_success(client: JiraClient) -> None:
|
|
mock_resp = MagicMock()
|
|
mock_resp.raise_for_status = MagicMock()
|
|
|
|
with patch("httpx.Client.put", return_value=mock_resp):
|
|
result = client.update_issue("OPS-42", {"priority": {"name": "Low"}})
|
|
|
|
assert result["success"] is True
|
|
assert result["issue_key"] == "OPS-42"
|
|
|
|
|
|
def test_update_issue_http_error(client: JiraClient) -> None:
|
|
import httpx
|
|
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 400
|
|
mock_resp.text = "Bad Request"
|
|
|
|
with patch(
|
|
"httpx.Client.put",
|
|
side_effect=httpx.HTTPStatusError("err", request=MagicMock(), response=mock_resp),
|
|
):
|
|
result = client.update_issue("OPS-42", {"priority": {"name": "Low"}})
|
|
|
|
assert result["success"] is False
|
|
assert "400" in result["error"]
|