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
103 lines
2.8 KiB
Python
103 lines
2.8 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from arcade_confluence.client import ConfluenceClientV2
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"space_identifier, is_id",
|
|
[
|
|
(
|
|
"12345",
|
|
True,
|
|
),
|
|
(
|
|
"test-space",
|
|
False,
|
|
),
|
|
],
|
|
)
|
|
async def test_get_space_id(space_identifier, is_id) -> None:
|
|
with patch("arcade_confluence.client.ConfluenceClient._get_cloud_id", return_value=None):
|
|
client_v2 = ConfluenceClientV2("fake-token")
|
|
with patch(
|
|
"arcade_confluence.client.ConfluenceClientV2.get_space_by_key",
|
|
return_value={"space": {"id": "12345"}},
|
|
):
|
|
space_id = await client_v2.get_space_id(space_identifier)
|
|
if is_id:
|
|
assert space_id == space_identifier
|
|
else:
|
|
assert space_id == "12345"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"page_identifier, is_id",
|
|
[
|
|
(
|
|
"67890",
|
|
True,
|
|
),
|
|
(
|
|
"test-page",
|
|
False,
|
|
),
|
|
],
|
|
)
|
|
async def test_get_page_id(page_identifier, is_id) -> None:
|
|
with patch("arcade_confluence.client.ConfluenceClient._get_cloud_id", return_value=None):
|
|
client_v2 = ConfluenceClientV2("fake-token")
|
|
with patch(
|
|
"arcade_confluence.client.ConfluenceClientV2.get_page_by_title",
|
|
return_value={"page": {"id": "67890"}},
|
|
):
|
|
page_id = await client_v2.get_page_id(page_identifier)
|
|
if is_id:
|
|
assert page_id == page_identifier
|
|
else:
|
|
assert page_id == "67890"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"space_identifier, is_id",
|
|
[
|
|
(
|
|
"12345",
|
|
True,
|
|
),
|
|
(
|
|
"test-space",
|
|
False,
|
|
),
|
|
],
|
|
)
|
|
async def test_get_space(space_identifier, is_id) -> None:
|
|
with patch("arcade_confluence.client.ConfluenceClient._get_cloud_id", return_value=None):
|
|
client_v2 = ConfluenceClientV2("fake-token")
|
|
|
|
mock_space = {"space": {"id": "12345", "key": "TEST"}}
|
|
|
|
with (
|
|
patch(
|
|
"arcade_confluence.client.ConfluenceClientV2.get_space_by_id",
|
|
return_value=mock_space,
|
|
) as mock_by_id,
|
|
patch(
|
|
"arcade_confluence.client.ConfluenceClientV2.get_space_by_key",
|
|
return_value=mock_space,
|
|
) as mock_by_key,
|
|
):
|
|
result = await client_v2.get_space(space_identifier)
|
|
|
|
if is_id:
|
|
mock_by_id.assert_called_once_with(space_identifier)
|
|
mock_by_key.assert_not_called()
|
|
else:
|
|
mock_by_id.assert_not_called()
|
|
mock_by_key.assert_called_once_with(space_identifier)
|
|
|
|
assert result == mock_space
|