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
10 changes: 2 additions & 8 deletions atlassian/confluence/cloud/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,9 @@ def create_page(
"spaceId": space_id,
"status": status,
"title": title,
"body": {body_format: {"value": body, "representation": representation}},
"body": {body_format: {"value": body, "representation": representation or body_format}},
}

# Remove representation field if None
if representation is None:
del data["body"][body_format]["representation"]

# Add parent ID if provided
if parent_id:
data["parentId"] = parent_id
Expand Down Expand Up @@ -552,9 +548,7 @@ def update_page(
data["status"] = status

if body:
data["body"] = {body_format: {"value": body}}
if representation:
data["body"][body_format]["representation"] = representation
data["body"] = {body_format: {"value": body, "representation": representation or body_format}}

if parent_id:
data["parentId"] = parent_id
Expand Down
21 changes: 17 additions & 4 deletions tests/test_confluence_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_create_page(self, mock_post):
"spaceId": "SPACE123",
"status": "current",
"title": "New Page",
"body": {"storage": {"value": "<p>This is the content</p>"}},
"body": {"storage": {"value": "<p>This is the content</p>", "representation": "storage"}},
}
mock_post.assert_called_once_with("api/v2/pages", data=expected_data)
self.assertEqual(response, mock_response)
Expand All @@ -247,7 +247,7 @@ def test_create_page_with_parent(self, mock_post):
"spaceId": "SPACE123",
"status": "current",
"title": "New Child Page",
"body": {"storage": {"value": "<p>This is a child page</p>"}},
"body": {"storage": {"value": "<p>This is a child page</p>", "representation": "storage"}},
"parentId": "PARENT123",
}
mock_post.assert_called_once_with("api/v2/pages", data=expected_data)
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_update_page(self, mock_put, mock_get_page):
"id": "123",
"title": "Updated Page",
"version": {"number": 2, "message": "Updated via Python API"},
"body": {"storage": {"value": "<p>Updated content</p>"}},
"body": {"storage": {"value": "<p>Updated content</p>", "representation": "storage"}},
}
mock_put.assert_called_once_with("api/v2/pages/123", data=expected_data)
self.assertEqual(response, mock_response)
Expand Down Expand Up @@ -448,12 +448,25 @@ def test_update_page_with_parent_id(self, mock_put):
"id": "123",
"title": "Moved Page",
"version": {"number": 4, "message": "Updated via Python API"},
"body": {"storage": {"value": "<p>Content</p>"}},
"body": {"storage": {"value": "<p>Content</p>", "representation": "storage"}},
"parentId": "456",
}
mock_put.assert_called_once_with("api/v2/pages/123", data=expected_data)
self.assertEqual(response, mock_response)

@patch("atlassian.confluence.cloud.ConfluenceCloud.put")
def test_update_page_body_representation_follows_body_format(self, mock_put):
mock_put.return_value = {"id": "123"}

self.confluence_v2.update_page(page_id="123", body='{"type": "doc"}', body_format="atlas_doc_format", version=1)

expected_data = {
"id": "123",
"version": {"number": 2, "message": "Updated via Python API"},
"body": {"atlas_doc_format": {"value": '{"type": "doc"}', "representation": "atlas_doc_format"}},
}
mock_put.assert_called_once_with("api/v2/pages/123", data=expected_data)

def test_update_page_invalid_body_format(self):
# Test invalid body_format
with self.assertRaises(ValueError):
Expand Down
Loading