Skip to content

Commit 2df0553

Browse files
[Confluence] ConfluenceCloud.page_exists: check blog posts when type="blogpost" (#1703)
The docs say page_exists() takes type="page" or "blogpost", but the Cloud client passed type through **kwargs as an extra query parameter on api/v2/pages, so page_exists(space, title, type="blogpost") only ever looked at pages and returned False for an existing blog post. Take type as an explicit argument and query api/v2/blogposts with the same space-id/title/status filters when it is "blogpost". type is no longer sent to the V2 pages endpoint.
1 parent e75f438 commit 2df0553

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎atlassian/confluence/cloud/__init__.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,13 @@ def blog_post_exists(self, space_key, title, **kwargs):
244244
result = self.get_blog_post_by_title(space_key, title, **kwargs)
245245
return len(result.get("results", [])) > 0
246246

247-
def page_exists(self, space_key, title, **kwargs):
247+
def page_exists(self, space_key, title, type=None, **kwargs):
248248
"""Check whether a page exists using the Cloud V2 page endpoint.
249249
250250
The retired V1 content lookup accepted a space key directly. V2 page
251251
queries require a space ID, so resolve the key first and request only
252-
one matching page.
252+
one matching page. Pass type="blogpost" to check the V2 blog post
253+
endpoint instead.
253254
"""
254255
try:
255256
spaces = self.get("api/v2/spaces", params={"keys": [space_key], "limit": 1})
@@ -263,7 +264,7 @@ def page_exists(self, space_key, title, **kwargs):
263264

264265
try:
265266
result = self.get(
266-
"api/v2/pages",
267+
"api/v2/blogposts" if type == "blogpost" else "api/v2/pages",
267268
params={
268269
"space-id": space_results[0]["id"],
269270
"title": title,

‎tests/confluence/test_confluence_cloud.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ def test_page_exists_uses_v2_space_and_page_endpoints(self, mock_get, confluence
216216
}
217217
}
218218

219+
@patch.object(ConfluenceCloud, "get")
220+
def test_page_exists_uses_v2_blogpost_endpoint_for_blogpost_type(self, mock_get, confluence_cloud):
221+
mock_get.side_effect = [{"results": [{"id": "42", "key": "TEST"}]}, {"results": [{"id": "456"}]}]
222+
223+
assert confluence_cloud.page_exists("TEST", "Release notes", type="blogpost") is True
224+
assert mock_get.call_args_list[1].args == ("api/v2/blogposts",)
225+
assert mock_get.call_args_list[1].kwargs == {
226+
"params": {
227+
"space-id": "42",
228+
"title": "Release notes",
229+
"status": "current",
230+
"body-format": "none",
231+
"limit": 1,
232+
}
233+
}
234+
235+
@patch.object(ConfluenceCloud, "get")
236+
def test_page_exists_does_not_send_page_type_to_v2(self, mock_get, confluence_cloud):
237+
mock_get.side_effect = [{"results": [{"id": "42", "key": "TEST"}]}, {"results": []}]
238+
239+
assert confluence_cloud.page_exists("TEST", "Test Page", type="page") is False
240+
assert mock_get.call_args_list[1].args == ("api/v2/pages",)
241+
assert "type" not in mock_get.call_args_list[1].kwargs["params"]
242+
219243
@patch.object(ConfluenceCloud, "get")
220244
def test_page_exists_returns_false_for_unknown_space(self, mock_get, confluence_cloud):
221245
mock_get.return_value = {"results": []}

0 commit comments

Comments
 (0)