arcade-mcp/toolkits/confluence/tests/test_client_v1.py
Eric Gustin 6bc6f0c574
Add Confluence toolkit (#406)
12 tools for the new Confluence toolkit.

| Name | Description |

|----------------------------------|------------------------------------------------------------------------------------|
| Confluence.CreatePage | Create a new page at the root of the given
space. |
| Confluence.UpdatePageContent | Update a page's content. |
| Confluence.RenamePage | Rename a page by changing its title. |
| Confluence.GetPage | Retrieve a SINGLE page's content by its ID or
title. |
| Confluence.GetPagesById | Get the content of MULTIPLE pages by their
ID in a single efficient request. |
| Confluence.ListPages | Get the content of multiple pages by their ID.
|
| Confluence.ListAttachments | List attachments in a workspace. |
| Confluence.GetAttachmentsForPage | Get attachments for a page by its
ID or title. |
| Confluence.SearchContent | Search for content in Confluence. |
| Confluence.GetSpace | Get the details of a space by its ID or key. |
| Confluence.ListSpaces | List all spaces sorted by name in ascending
order. |
| Confluence.GetSpaceHierarchy | Retrieve the full hierarchical
structure of a Confluence space as a tree structure.|

### Confluence Clients
Confluence has deprecated most of their V1 endpoints, so most of the
tools use V2. However, we still need a V1 client to support search. The
V1 search API has not been deprecated yet, because there is no V2
equivalent. But we need to be aware in the future for when this
deprecation happens.


### Future work
* Content of pages are returned in the Confluence `storage` format. This
is the format that Confluence uses to store pages internally. We should
understand the storage format more deeply, and write utility function to
transform this format into plain text.
* Better protections against extremely large pages. I've tested up to
6,000 word pages.
* Tools for blog posts
* Tool for getting the children of a page. (`get_space_hierarchy` will
suffice for now)
* Allow for numerical titles
2025-05-22 13:18:19 -07:00

120 lines
4.8 KiB
Python

from unittest.mock import patch
import pytest
from arcade.sdk.errors import ToolExecutionError
from arcade_confluence.client import ConfluenceClientV1
@pytest.fixture
def client_v1() -> ConfluenceClientV1:
"""Fixture that provides a ConfluenceClientV1 instance with mocked cloud_id."""
with patch("arcade_confluence.client.ConfluenceClient._get_cloud_id", return_value=None):
return ConfluenceClientV1("fake-token")
@pytest.mark.parametrize(
"query, enable_fuzzy, expected_cql",
[
("foo", False, '(text ~ "foo" OR title ~ "foo" OR space.title ~ "foo")'),
("foo bar", False, '(text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar")'),
("foo", True, '(text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~")'),
("foo bar", True, '(text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar")'),
],
)
def test_build_query_cql(client_v1: ConfluenceClientV1, query, enable_fuzzy, expected_cql) -> None:
cql = client_v1._build_query_cql(query, enable_fuzzy)
assert cql == expected_cql
@pytest.mark.parametrize(
"queries, enable_fuzzy, expected_cql",
[
(
["foo", "foo bar"],
False,
'((text ~ "foo" OR title ~ "foo" OR space.title ~ "foo") AND (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
(
["foo", "foo bar"],
True,
'((text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~") AND (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
],
)
def test_build_and_cql(client_v1: ConfluenceClientV1, queries, enable_fuzzy, expected_cql) -> None:
cql = client_v1._build_and_cql(queries, enable_fuzzy)
assert cql == expected_cql
@pytest.mark.parametrize(
"queries, enable_fuzzy, expected_cql",
[
(
["foo", "foo bar"],
False,
'((text ~ "foo" OR title ~ "foo" OR space.title ~ "foo") OR (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
(
["foo", "foo bar"],
True,
'((text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~") OR (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
],
)
def test_build_or_cql(client_v1: ConfluenceClientV1, queries, enable_fuzzy, expected_cql) -> None:
cql = client_v1._build_or_cql(queries, enable_fuzzy)
assert cql == expected_cql
@pytest.mark.parametrize(
"must_contain_all, can_contain_any, enable_fuzzy, expected_cql",
[
(None, None, False, ""),
(
["foo", "foo bar"],
None,
False,
'((text ~ "foo" OR title ~ "foo" OR space.title ~ "foo") AND (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
(
["foo", "foo bar"],
None,
True,
'((text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~") AND (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
(
None,
["foo", "foo bar"],
False,
'((text ~ "foo" OR title ~ "foo" OR space.title ~ "foo") OR (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
(
None,
["foo", "foo bar"],
True,
'((text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~") OR (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar"))', # noqa: E501
),
(
["foo", "foo bar"],
["foo", "foo bar"],
False,
'(((text ~ "foo" OR title ~ "foo" OR space.title ~ "foo") AND (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar")) AND ((text ~ "foo" OR title ~ "foo" OR space.title ~ "foo") OR (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar")))', # noqa: E501
),
(
["foo", "foo bar"],
["foo", "foo bar"],
True,
'(((text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~") AND (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar")) AND ((text ~ "foo~" OR title ~ "foo~" OR space.title ~ "foo~") OR (text ~ "foo bar" OR title ~ "foo bar" OR space.title ~ "foo bar")))', # noqa: E501
),
],
)
def test_construct_cql(
client_v1: ConfluenceClientV1, must_contain_all, can_contain_any, enable_fuzzy, expected_cql
) -> None:
if not expected_cql:
with pytest.raises(ToolExecutionError):
client_v1.construct_cql(must_contain_all, can_contain_any, enable_fuzzy)
else:
cql = client_v1.construct_cql(must_contain_all, can_contain_any, enable_fuzzy)
assert cql == expected_cql