Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions atlassian/confluence/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ def blog_post_exists(self, space_key, title, **kwargs):
result = self.get_blog_post_by_title(space_key, title, **kwargs)
return len(result.get("results", [])) > 0

def page_exists(self, space_key, title, **kwargs):
def page_exists(self, space_key, title, type=None, **kwargs):
"""Check whether a page exists using the Cloud V2 page endpoint.

The retired V1 content lookup accepted a space key directly. V2 page
queries require a space ID, so resolve the key first and request only
one matching page.
one matching page. Pass type="blogpost" to check the V2 blog post
endpoint instead.
"""
try:
spaces = self.get("api/v2/spaces", params={"keys": [space_key], "limit": 1})
Expand All @@ -263,7 +264,7 @@ def page_exists(self, space_key, title, **kwargs):

try:
result = self.get(
"api/v2/pages",
"api/v2/blogposts" if type == "blogpost" else "api/v2/pages",
params={
"space-id": space_results[0]["id"],
"title": title,
Expand Down
24 changes: 24 additions & 0 deletions tests/confluence/test_confluence_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,30 @@ def test_page_exists_uses_v2_space_and_page_endpoints(self, mock_get, confluence
}
}

@patch.object(ConfluenceCloud, "get")
def test_page_exists_uses_v2_blogpost_endpoint_for_blogpost_type(self, mock_get, confluence_cloud):
mock_get.side_effect = [{"results": [{"id": "42", "key": "TEST"}]}, {"results": [{"id": "456"}]}]

assert confluence_cloud.page_exists("TEST", "Release notes", type="blogpost") is True
assert mock_get.call_args_list[1].args == ("api/v2/blogposts",)
assert mock_get.call_args_list[1].kwargs == {
"params": {
"space-id": "42",
"title": "Release notes",
"status": "current",
"body-format": "none",
"limit": 1,
}
}

@patch.object(ConfluenceCloud, "get")
def test_page_exists_does_not_send_page_type_to_v2(self, mock_get, confluence_cloud):
mock_get.side_effect = [{"results": [{"id": "42", "key": "TEST"}]}, {"results": []}]

assert confluence_cloud.page_exists("TEST", "Test Page", type="page") is False
assert mock_get.call_args_list[1].args == ("api/v2/pages",)
assert "type" not in mock_get.call_args_list[1].kwargs["params"]

@patch.object(ConfluenceCloud, "get")
def test_page_exists_returns_false_for_unknown_space(self, mock_get, confluence_cloud):
mock_get.return_value = {"results": []}
Expand Down
Loading